X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=snmp-port-status.sh;h=4ebea7465f7990b98c6bd76334eed20a90e350fc;hb=8362f4eaf891497a9cfd036a009d2ff8d460adfa;hp=174259f71e4402caf29ded2cc6d35bbfb7c73c28;hpb=f87785b08d5b2f04f015f31e112bc9f49ee3ab36;p=dell-switch diff --git a/snmp-port-status.sh b/snmp-port-status.sh index 174259f..4ebea74 100755 --- a/snmp-port-status.sh +++ b/snmp-port-status.sh @@ -4,7 +4,7 @@ # see /var/lib/snmp/mibs/ietf/IF-MIB if [ -z "$1" ]; then - echo Usage: "$0" hostname ifInErrors ifOutErrors ifInDiscards + echo Usage: "$0" hostname ifAdminStatus BRIDGE-MIB::dot1dStpPortState ifInErrors ifOutErrors ifInDiscards exit 4 fi @@ -15,16 +15,18 @@ sw="$1" shift # rest of arguments are IfEntry SEQUENCE . ./snmp.conf +extra=$* snmpwalk="snmpwalk -Oqs -v2c -Cc -c $COMMUNITY $sw" +fping $sw 2>>/dev/shm/dead :> $log/$sw -for oid in ifName ifHighSpeed ifOperStatus ifType $* ifAlias +for oid in ifName ifHighSpeed ifOperStatus $extra ifType ifAlias do - echo -n "# snmpwalk $sw [$oid] = " + echo -n "# snmpwalk $sw [$oid] = " >/dev/stderr - $snmpwalk $oid | cut -d. -f2- | tee $log/$sw-$oid | wc -l + $snmpwalk $oid | cut -d. -f2- | tee $log/$sw-$oid | wc -l >/dev/stderr # put [] around alias and remove empty ones if [ "$oid" = 'ifAlias' ] ; then @@ -44,48 +46,7 @@ cat $log/$sw | sed "s/^/$sw /" > $log/$sw.new && mv $log/$sw.new $log/$sw cat $log/$sw -exit 1 - -snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw" - -numports=`$snmp IF-MIB::ifNumber.0` -:> $log/$sw - -for PORT in `seq 1 $numports`; do - -## name=`$snmp IF-MIB::ifName.$i` -## alias=`$snmp IF-MIB::ifAlias.$i` -## if [ "$name" = "No Such Instance currently exists at this OID" ]; then -## continue -## fi -## -## iftype=`$snmp IF-MIB::ifType.$i` -## -### if [ "$iftype" = "other" ] || [ "$iftype" = propVirtual ] || [ "$iftype" = softwareLoopback ]; then -### continue -### fi -## -## status=`$snmp IF-MIB::ifOperStatus.$i` -## if [ "$status" = "notPresent" ] ; then -## continue; -## fi -## -## #descr=`$snmp IF-MIB::ifDescr.$i` -## #speed=`$snmp IF-MIB::ifSpeed.$i | sed 's/000000//'` -## speed=`$snmp IF-MIB::ifHighSpeed.$i` -## -## extra="" -## for add in "$@"; do -## extra="$extra "`$snmp IF-MIB::$add.$i` -## done -## -### echo "## $sw [$name] $iftype $status $descr $speed" -## #echo "$sw $i $name $speed $status $iftype$extra [$alias]" | tee -a $log/$sw - - echo "$sw $PORT "`$snmp IF-MIB::ifName.$PORT $* IF-MIB::ifHighSpeed.$PORT IF-MIB::ifOperStatus.$PORT IF-MIB::ifType.$PORT IF-MIB::ifAlias.$PORT` | grep -v 'No Such Instance currently exists at this OID' | sed 's/\(ethernetCsmacd\) \(..*\)$/\1 [\2]/' | tee -a $log/$sw -done - -exit 1 +test ! -z "$extra" && exit 0 # don't commit if we have custom oids ports_changed=`cd $log && git diff $sw | grep '^-' | awk '{ print $3 }' | tr '\n' ' '` if [ ! -z "$ports_changed" ] ; then