Nagios Bash Script Help

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post by spyder13337 »

it seem i still need to give the warning and critical values in original format w/o AWK command
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Bash Script Help

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post by spyder13337 »

so that fixed the issue but it is not changing from OK to CRITICAL or WARNING just start green
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Bash Script Help

Post 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?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post 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
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Nagios Bash Script Help

Post by tgriep »

What are you adjusting and to what value are you using to generate the critical message?
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Bash Script Help

Post 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".
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post 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
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Bash Script Help

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post 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
Locked