3 # modified from https://gist.github.com/krokodilerian/a88b4ae992706c22e0b0
4 # see /var/lib/snmp/mibs/ietf/IF-MIB
7 echo Usage: "$0" hostname ifAdminStatus BRIDGE-MIB::dot1dStpPortState ifInErrors ifOutErrors ifInDiscards
11 dir=/dev/shm/port-status/
12 if [ ! -d $dir ] ; then
14 ln -sv `pwd`/port-status/.git $dir/
18 shift # rest of arguments are IfEntry SEQUENCE
22 snmpwalk="snmpwalk -Oqs -v2c -Cc -c $COMMUNITY $sw"
24 fping $sw 2>>/dev/shm/dead
28 for oid in ifName ifHighSpeed ifAdminStatus ifOperStatus $extra ifType ifAlias
30 echo -n "# snmpwalk $sw [$oid] = " >/dev/stderr
32 $snmpwalk $oid | cut -d. -f2- | tee $dir/$sw-$oid | wc -l >/dev/stderr
34 # put [] around alias and remove empty ones
35 if [ "$oid" = 'ifAlias' ] ; then
36 cat $dir/$sw-$oid | sed -e 's/ / [/' -e 's/$/]/' -e 's/ \[\]$//' > $dir/$sw-$oid.new && mv $dir/$sw-$oid.new $dir/$sw-$oid
39 if [ ! -s $dir/$sw ] ; then
40 mv $dir/$sw-$oid $dir/$sw
42 join -a 1 $dir/$sw $dir/$sw-$oid > $dir/$sw.new && mv $dir/$sw.new $dir/$sw
47 # add switch name prefix
48 cat $dir/$sw | sed "s/^/$sw /" > $dir/$sw.new && mv $dir/$sw.new $dir/$sw
52 test ! -z "$extra" && exit 0 # don't commit if we have custom oids
54 ports_changed=`cd $dir && git diff $sw | grep '^-' | awk '{ print $3 }' | tr '\n' ' '`
55 if [ ! -z "$ports_changed" ] ; then
56 cd $dir && git commit -m "$sw : $ports_changed" $dir/$sw