track spanning tree topology changes
[dell-switch] / snmp-port-status.sh
1 #!/bin/bash
2
3 # modified from https://gist.github.com/krokodilerian/a88b4ae992706c22e0b0
4 # see /var/lib/snmp/mibs/ietf/IF-MIB
5
6 if [ -z "$1" ]; then
7         echo Usage: "$0" hostname
8         exit 4
9 fi
10
11 log=/dev/shm/port-status/
12 test -d $log || mkdir $log
13
14 sw="$1"
15 . ./snmp.conf
16 snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw"
17
18 numports=`$snmp IF-MIB::ifNumber.0`
19 :> $log/$sw
20
21 for i in `seq 1 $numports`; do
22         name=`$snmp IF-MIB::ifName.$i`
23         alias=`$snmp IF-MIB::ifAlias.$i`
24         if [ "$name" = "No Such Instance currently exists at this OID" ]; then
25                 continue
26         fi
27
28         iftype=`$snmp IF-MIB::ifType.$i`
29
30 #       if [ "$iftype" = "other" ] || [ "$iftype" = propVirtual ] || [ "$iftype" = softwareLoopback ]; then
31 #               continue
32 #       fi 
33         
34         status=`$snmp IF-MIB::ifOperStatus.$i`
35         if [ "$status" = "notPresent" ] ; then
36                 continue;
37         fi
38
39         #descr=`$snmp IF-MIB::ifDescr.$i`
40         speed=`$snmp IF-MIB::ifSpeed.$i | sed 's/000000//'`
41
42 #       echo "## $sw [$name] $iftype $status $descr $speed"
43         echo "$sw $i $name $speed $status [$alias]" | tee -a $log/$sw
44 done
45