Remember us getting you to test the exit code? This is what a plugin returns back to bash when it runs.spyder13337 wrote:i ran this
/usr/local/nagios/libexec/check_snmp -H xx.xx.xx.xx -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 -w one -c two
and got this
SNMP OK - 67 | iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=67;one;two
then i ran echo $?
and got this
0
Every time a command is run, it outputs an exit code, for example:
Code: Select all
/usr/local/nagios/libexec/check_dummy 2 'my exit message, yo'
CRITICAL: my exit message, yo
echo $?
2
echo $?
0
Then we echo $? and it shows us 2
Then we echo $? again but this time it shows us 0 .... what the ???
To go back to what I said earlier, every time a command is run, it outputs an exit code.
"echo $?" is a command, and that command completed successfully so it outputted an exit code of 0.
How does this relate to your problem?
The check_snmp program runs and then pipes it's output to the awk program. So you are getting the exit code from the awk program.spyder13337 wrote:Code: Select all
/usr/local/nagios/libexec/check_snmp -H xx.xx.xx.xx -C xxxxx -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 -w $1 -c $2 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/1$
So you're going to need to record the exit code from check_snmp and use it when you exit.
Code: Select all
#!/bin/bash
snmp_output=$(/usr/local/nagios/libexec/check_snmp -H xx.xx.xx.xx -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 -w $1 -c $2)
snmp_exit_code=$?
echo "$snmp_output" | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/1$
exit $snmp_exit_code