How to divide value returned from check_snmp?

Hi there!

I’m trying to get the input voltage from a MGE UPS, but the returned value is 10 times greater than the actual voltage.

# /usr/local/nagios/libexec/check_snmp -H 10.10.12.9 -C ***** -o .1.3.6.1.4.1.705.1.6.2.1.2.1 SNMP OK - 2308 | iso.3.6.1.4.1.705.1.6.2.1.2.1=2308

Is there any way I can divide this by 10?

kind regards
T.G.

Hi!

you could write a small script that would call check_snmp, get the value returned, divide by 10 and print the output to nagios :slight_smile:

Good idea. :wink:

I am relatively unexperienced in scripting, but would something like this do the trick?

[code]snmp=$(/usr/local/nagios/libexec/check_snmp -H $1 -C ****** -o .1.3.6.1.4.1.705.1.6.2.1.2.1|cut -b 11-14)
volt=$(expr $snmp / 10)

if $volt -ge 200 ] ; then
echo “Input Voltage OK - $volt | iso.3.6.1.4.1.534.1.3.4.1.2.1=$volt”

elif $volt -lt 200 ] ; then
echo “Input Voltage CRITICAL - $volt | iso.3.6.1.4.1.534.1.3.4.1.2.1=$volt”

else
echo “Input Voltage problem - No data received from host”

fi[/code]

The script now returns the same as check_snmp (but with correct voltage), but when I give a invalid input it should return only “Input Voltage problem - No data received from host”, but instead it returns this:

$ ./mgeups 10.10.13.8 expr: non-numeric argument ./mgeups: line 4: : -ge: unary operator expected ./mgeups: line 7: : -lt: unary operator expected Input Voltage problem - No data received from host
How do I avoid all this extra crap? :slight_smile:

Can I just add a check command with “this_script $HOSTADDRESS$” in checkcommands.cfg, and that would work?

“Can I just add a check command with “this_script $HOSTADDRESS$” in checkcommands.cfg, and that would work?”
=> yes; it should work fine.

"How do I avoid all this extra crap?"
Well; the good thing is that all that crap is on the ERROR output; which nagios will not read it … so you will only have your “Input Voltage problem - No data received from host” line as output in nagios.
But yes, that’s not a really good way to do it.

To avoid this, you could test your exit code from the snmp command:
after the first line, add:
RET=$?
if $RET -ne 0 ]]
then
echo "Input Voltage problem - No data received from host"
exit 3
fi

let me know if this doesn’t work (I’m at work and shouldn’t take time to answer, so i didn’t check if this is correct)

I added those lines to the script, and it actually seems like it works. :slight_smile:
Thanks! :slight_smile: