Page 1 of 1
How to read check_snmp response
Posted: Fri Jan 15, 2016 12:17 pm
by jriker1
When I do an SNMP walk of a particular OID I get:
Code: Select all
snmpwalk -v2c -c public 192.168.0.8 .1.3.6.1.4.1.674.10909.1.400.20.1.4
SNMPv2-SMI::enterprises.674.10909.1.400.20.1.4.1 = INTEGER: 3
3 is the right answer. The matrix is: other(1),unknown(2),ok(3),nonCritical(4),critical(5),nonRecoverable(6)
If I do:
Code: Select all
# ./check_snmp -H 192.168.0.8 -o .1.3.6.1.4.1.674.10909.1.400.20.1.4.1 -C public
SNMP OK - 3 | iso.3.6.1.4.1.674.10909.1.400.20.1.4.1=3
Why is it returning OK? I know it's OK, however how does check_snmp know it's OK and what would it return if a 2 was returned? Or a 1 or 6?
Thanks.
JR
Re: How to read check_snmp response
Posted: Fri Jan 15, 2016 1:35 pm
by hsmith
I'm going to explain this the best way I can, and to the best of my understanding.
SNMP doesn't really return any kind of exit code. If you get one of those other codes, Nagios is going to think it is fine still, it doesn't care what the server returns, as long as the plugin runs successfully.
You'll notice there are loads of SNMP scripts out there for different products. If check_snmp had logic to know whether something was good or bad, you wouldn't need to have that many other scripts. The proper way to approach this would be to write a wrapper script that check SNMP runs inside of, and use that for your check. The script would have to have some kind of logic, to know whether or not the output was what we desired.
I'll give you a (messy) example:
Code: Select all
#!/bin/bash
RESULT=$(/usr/local/nagios/libexec/check_snmp -H $1 -o .1.3.6.1.4.1.674.10909.1.400.20.1.4.1 -c $2)
CODE=$(echo $RESULT | awk '{print $4}')
if [ $CODE = 3 ]
then
echo "Yay"
# 0 is OK
exit 0
elif [ $CODE = 2 ]
then
echo "Darn!"
# 1 is warning
exit 1
elif [ $CODE = 6 ]
then
echo "Critical Mission Failure - Abort!"
# 2 is critical
exit 2
fi
Then from the command line, run something like this:
./check_coffee_pot.sh 172.16.0.5 public
If someone else has more information, please correct me, I'm relatively new to the world of SNMP.
Re: How to read check_snmp response
Posted: Fri Jan 15, 2016 1:56 pm
by jriker1
Thanks for the reply. Kind of what I was thinking but know a lot of the out of the box plugins can be rather robust in options so wanted to check.
For your sample script, the echo statements. for say when it's OK, is the expectation for plugins supposed to be status pipe description?
So instead of "Yeah" would be OK|whatever is reporting 50 degrees
Thanks.
JR
Re: How to read check_snmp response
Posted: Fri Jan 15, 2016 2:07 pm
by hsmith
That should be just fine. It may be different for your environment, I just wanted to give you a rough idea. It's basically running the check, assigning the result to a variable, echoing the variable, awking the number out of the variable, and doing stuff based on that. There might be a better way to do it, don't take my little five minute script for something official
