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.