3 # modified from https://gist.github.com/krokodilerian/a88b4ae992706c22e0b0
4 # see /var/lib/snmp/mibs/ietf/IF-MIB
7 echo Usage: "$0" hostname ifInErrors ifOutErrors ifInDiscards
11 log=/dev/shm/port-status/
12 test -d $log || mkdir $log
15 shift # rest of arguments are IfEntry SEQUENCE
17 snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw"
19 numports=`$snmp IF-MIB::ifNumber.0`
22 for i in `seq 1 $numports`; do
23 name=`$snmp IF-MIB::ifName.$i`
24 alias=`$snmp IF-MIB::ifAlias.$i`
25 if [ "$name" = "No Such Instance currently exists at this OID" ]; then
29 iftype=`$snmp IF-MIB::ifType.$i`
31 # if [ "$iftype" = "other" ] || [ "$iftype" = propVirtual ] || [ "$iftype" = softwareLoopback ]; then
35 status=`$snmp IF-MIB::ifOperStatus.$i`
36 if [ "$status" = "notPresent" ] ; then
40 #descr=`$snmp IF-MIB::ifDescr.$i`
41 #speed=`$snmp IF-MIB::ifSpeed.$i | sed 's/000000//'`
42 speed=`$snmp IF-MIB::ifHighSpeed.$i`
46 extra="$extra "`$snmp IF-MIB::$add.$i`
49 # echo "## $sw [$name] $iftype $status $descr $speed"
50 echo "$sw $i $name $speed $status $iftype$extra [$alias]" | tee -a $log/$sw