Created
June 17, 2015 14:48
-
-
Save krokodilerian/a88b4ae992706c22e0b0 to your computer and use it in GitHub Desktop.
check snmp ports status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$2" ]; then | |
echo Usage: "$0" hostname community | |
exit 4 | |
fi | |
srv="$1" | |
com="$2" | |
snmp="snmpget -v 2c -c $2 -Cf -Ov -OQ $srv" | |
numports=`$snmp IF-MIB::ifNumber.0` | |
for i in `seq 1 $numports`; do | |
name=`$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` | |
port=`$snmp IF-MIB::ifDescr.$i` | |
if [ -z "$name" ]; then | |
if ! [ $status = 'down' ]; then | |
badoutput="$badoutput, $port is $status and should be down" | |
fi | |
continue | |
else | |
fulloutput="$fulloutput, $port:$name is $status" | |
if ! [ $status = 'up' ]; then | |
badoutput="$badoutput, $port:$name is $status" | |
fi | |
fi | |
done | |
fo=`echo "$fulloutput"|sed 's/^, //;s/RMON Port //g'` | |
bo=`echo "$badoutput"|sed 's/^, //;s/RMON Port //g'` | |
if [ -z "$badoutput" ]; then | |
echo "OK; $fo" | |
exit 0 | |
else | |
echo "CRITICAL; $bo" | |
exit 2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment