Skip to content

Instantly share code, notes, and snippets.

@krokodilerian
Created June 17, 2015 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krokodilerian/a88b4ae992706c22e0b0 to your computer and use it in GitHub Desktop.
Save krokodilerian/a88b4ae992706c22e0b0 to your computer and use it in GitHub Desktop.
check snmp ports status
#!/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