Monitor for abnormal bandwidth use, ignore short spikes, store five minute values
From Internetworkpro
This bash script will send FAIL or OK to an html page (to monitor) based on the value of in_convert and out_convert which are Mbps traffic rates converted from polling bytes in and bytes out from a router.
If you were to look at the snmp graph of the traffic, you find where the peaks of the hills are, and use a number slightly over that, then set the timing on the monitor checking for OK or FAIL to ignore the short spikes.
#!/bin/bash set -e #cd /directory of scripts.. (put a variable in place if you wanna get crazy) snmpwalk -v 2c -On -c 'xxxxxxxx' 172.16.1.1 .1.3.6.1.2.1.2.2.1.10.2 | cut -d " " -f 4 >> in snmpwalk -v 2c -On -c 'xxxxxxxx' 172.16.1.2 .1.3.6.1.2.1.2.2.1.16.2 | cut -d " " -f 4 >> out outrate_back=$(tail -n2 out | head -n1) inrate_back=$(tail -n2 in | head -n1) outrate=$(tail -n1 out) inrate=$(tail -n1 in) in_trans=$((($inrate-$inrate_back)/300)) out_trans=$((($outrate-$outrate_back)/300)) #since the Mbps number is multiplied first it should always be higher than .5 # therefore we don't need floats with bc as we can round to the next Mb in_convert=$((($in_trans*8)/(1024*1024))) out_convert=$((($out_trans*8)/(1024*1024))) #change 14 to the matching Mbps value if [ $in_convert -lt 14 ] ; then echo OK > /var/www/inbandcheck.html else echo FAIL > /var/www/inbandcheck.html fi if [ $out_convert -lt 14 ] ; then echo OK > /var/www/outbandcheck.html else echo FAIL > /var/www/outbandcheck.html fi #monitor okay with proper timing parameters to not have false positives for short spikes exit 0