ecce
Jul 13, 2019Cirrostratus
Is this a good way to health monitor SNMP?
I needed a way to check if SNMPd was running on log servers (in my case - Splunk). I understand you need an external monitor for this, so I wrote one and would like input on the script and the complete solution. I didn't want to post this in the code section since I'm not sure if this is a good solution.
The script is checking if SNMP returns a value on SNMPGET for an OID you specify in the script file. I used an uptime OID. If anything is returned, the server is considered up. In it times out, it is considered down.
Any suggestions you might have is appreciated!
#!/bin/sh
# User-defined variables
oid=".iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.0"
community="really-secret-community"
# kill of the last instance of this monitor if hung and log current pid
PIDFILE="/var/run/`basename ${0}`.${IP}_${PORT}.pid"
if [ -f $PIDFILE ]
then
kill -9 `cat $PIDFILE` > /dev/null 2>&1
fi
echo "$$" > $PIDFILE
# Strip IPv6 prefix off node IP
node_ip=$(echo $1 | sed 's/::ffff://');
# Get SNMP Value
snmpget -O qv -t 1 -r 1 -v 2c -c $community $node_ip:161 $oid &>/dev/null
# Evaluate
status=$?
if [ $status -eq 0 ]
then
echo "up"
fi
rm -f $PIDFILE
exit