Page 4 of 5
Re: Nagios Bash Script Help
Posted: Wed May 18, 2016 10:16 am
by spyder13337
it seem i still need to give the warning and critical values in original format w/o AWK command
Re: Nagios Bash Script Help
Posted: Wed May 18, 2016 4:10 pm
by Box293
spyder13337 wrote:it seem i still need to give the warning and critical values in original format w/o AWK command
Oh yeah you're right I also missed that. Your warning and critical values need to be undivided numbers, as all we are doing is altering the returned result.
Re: Nagios Bash Script Help
Posted: Wed May 18, 2016 5:40 pm
by spyder13337
so that fixed the issue but it is not changing from OK to CRITICAL or WARNING just start green
Re: Nagios Bash Script Help
Posted: Wed May 18, 2016 6:02 pm
by Box293
So you need to go back to this command:
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 xxx -c yyy
Replace xxx and yyy with real values.
Run the command
Then run
echo $? after the command
Do you get 1 when warning and 2 when critical?
Re: Nagios Bash Script Help
Posted: Thu May 19, 2016 9:33 am
by spyder13337
ok i ran this command line /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 60 -c 80
the result where
SNMP WARNING - *65* | iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=65;60;80;60;80;
echo $?
(1) which is a warning that is working fine
and i also get a critical (2) when i adjust variables
Re: Nagios Bash Script Help
Posted: Thu May 19, 2016 3:28 pm
by tgriep
What are you adjusting and to what value are you using to generate the critical message?
Re: Nagios Bash Script Help
Posted: Thu May 19, 2016 4:50 pm
by Box293
Can you post your current script please. I've tested and the snmp_exit_code is working correctly, so I suspect there is something wrong in your script.
FYI, going all the way back to your previous forum thread where you wanted to simply divide the number ... this was somewhat simple, and didn't have any warning and critical requirements. The answer provided was to show it could be done and give you the commands on how to do it.
Now that you are doing a warning and critical, it is going to complicate things, because the performance data is going to have the undivided warning and critical numbers and won't make sense in performance graphs. You'll need to work on this yourself, as it's getting out of scope of "helping you get the monitoring working" and is moving into "custom development".
Re: Nagios Bash Script Help
Posted: Thu May 19, 2016 5:54 pm
by spyder13337
here is my script
#!/bin/bash
/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]/10;}'
i believe this is getting more complicated than careto go i am not a developer but somewhat understand Nagios runs in the background i think the issue occurs with the AWK command which throws Nagios for a Loop
i would think that the script pass the Variable to the command and the command pass the variable to service config file and there it would take Warn and Crit
Re: Nagios Bash Script Help
Posted: Thu May 19, 2016 5:57 pm
by Box293
The script should be like this:
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=$?
final_output=$(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]/10;}')
echo "$final_output"
exit $snmp_exit_code
Re: Nagios Bash Script Help
Posted: Fri May 20, 2016 9:49 am
by spyder13337
i ran the script and i got this i believe it should still show the value rather than 0
SNMP WARNING - 0| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=7.2
and echo $?
gave me 1