I am relatively unexperienced in scripting, but would something like this do the trick?
snmp=$(/usr/local/nagios/libexec/check_snmp -H $1 -C ****** -o .188.8.131.52.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.184.108.40.206.1.5220.127.116.11.1.2.1=$volt"
elif $volt -lt 200 ] ; then
echo "Input Voltage CRITICAL - *$volt* | iso.18.104.22.168.1.522.214.171.124.1.2.1=$volt"
echo "Input Voltage problem - No data received from host"
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?
Can I just add a check command with "this_script $HOSTADDRESS$" in checkcommands.cfg, and that would work?