Page 1 of 1
add a warning check to a decemel place change
Posted: Fri Jan 20, 2017 12:10 pm
by chrisbooth
https://support.nagios.com/forum/viewto ... 2&start=10
following on from this locked soloution, i'd like to know how to add a warning and critical check to this.
#!/bin/bash
hostaddress=$1
./check_snmp -H $hostaddress -C public -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
this script works but i'm not sure or how to add a warning and critical check to it
Re: add a warning check to a decemel place change
Posted: Fri Jan 20, 2017 12:35 pm
by mcapra
Can you shed a little more light on what you're trying to accomplish with this script? Sharing it's current output and describing the warning/critical criteria would be helpful.
Generally speaking, you should be able to do something like this in most languages:
Code: Select all
if (warning criteria)
exit 1
else if (critical criteria)
exit 2
Re: add a warning check to a decemel place change
Posted: Mon Jan 23, 2017 5:10 am
by chrisbooth
but i'm wrapping a check within a check.
so i'm not sure where i should be putting the -w -c
Re: add a warning check to a decemel place change
Posted: Mon Jan 23, 2017 4:47 pm
by mcapra
The "correct" way to navigate this would be to revise your script to include proper analysis of the output of this command:
Code: Select all
./check_snmp -H $hostaddress -C public -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
Intuitively, it might make sense to pass the warning/critical threshold to the check_snmp command. But the issue is that the
awk you are piping the plugin's output into will strip out the exit code at a minimum, which is important for Nagios in determining the state of the check.
Can you share this script's output? We might be able to offer some advice on how to best tackle this if we had additional information regarding all the variables in play. It's hard to tell what the OID is spitting out and what the
awk is doing to the result of check_snmp.
Re: add a warning check to a decemel place change
Posted: Tue Jan 24, 2017 4:43 am
by chrisbooth
Code: Select all
bash +x ./check_apc_pdu 10.101.24.95
SNMP OK - 9.1| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=9.1
i've tried like this:
Code: Select all
bash +x ./check_apc_pdu 10.101.24.95 -w 6 -c 8
SNMP OK - 9.1| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=9.1
Re: add a warning check to a decemel place change
Posted: Tue Jan 24, 2017 4:44 am
by chrisbooth
mcapra wrote:The "correct" way to navigate this would be to revise your script to include proper analysis of the output of this command:
Code: Select all
./check_snmp -H $hostaddress -C public -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
Intuitively, it might make sense to pass the warning/critical threshold to the check_snmp command. But the issue is that the
awk you are piping the plugin's output into will strip out the exit code at a minimum, which is important for Nagios in determining the state of the check.
Can you share this script's output? We might be able to offer some advice on how to best tackle this if we had additional information regarding all the variables in play. It's hard to tell what the OID is spitting out and what the
awk is doing to the result of check_snmp.
here's the output of your above suggestion
Code: Select all
./check_snmp -H 10.101.24.95 -C public -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
SNMP OK - 9| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=9
here's the exit code
Code: Select all
./check_snmp -H 10.101.24.95 -C public -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
SNMP OK - 9| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=9
root@prodsysnagios(/usr/local/nagios/libexec):echo $?
0
Re: add a warning check to a decemel place change
Posted: Tue Jan 24, 2017 2:25 pm
by mcapra
Is your intention to see if the output is 9 VS 9.1? Or is it more a question of "does a decimal point exist" ie, is the output 9 or 9.0?
Re: add a warning check to a decemel place change
Posted: Mon Jan 30, 2017 8:50 am
by chrisbooth
the above fixes the decemel place from being incorrect 90 to correct 9.
the issue now is i want a warning and critical thresholds to work
at the moment i dont know where i should put them in the above code to work.
it always replys with ok no matter where i put it at the moment
all i want to do is convert the apc output from 90 to 9 and then have threasholds to work.
if there's a better solution to this than the above i'd love to know
Re: add a warning check to a decemel place change
Posted: Mon Jan 30, 2017 5:31 pm
by mcapra
We don't typically offer advice specific to plugin development.
This is probably a typing issue within how
check_snmp was written though if i'm understanding the problem correctly. It's not as simple as just parsing the plugin's output and then comparing the warning/critical thresholds after the fact; The warning/critical thresholds will come into play before any
awk gets executed in this case:
Code: Select all
./check_snmp -H 10.101.24.95 -C public -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
SNMP OK - 9| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=9
So the gist of it is that you'd probably need to fork/alter check_snmp and bake the "change 90 to 9 or 91 to 9.1" part into the Perl.