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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Bash Script Help

Post by rkennedy »

Please run the two commands that @Box293 mentioned above, and post the output. You just want to run 'echo $?' which will show us the exit code that check_snmp runs on -

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 one -c two
echo $?
Former Nagios Employee
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post by spyder13337 »

so when i run this command i get 0 when this be correct

/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 | echo $?
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 »

Don't run it all as one command.
Please run them as two separate commands and post the output of both commands.
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 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
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 the 0 means it is exiting as OK.

What do you want with the warning threshold of one and critical of two?

The response you are getting back is a number, so your warning and critical thresholds should be numbers.
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 »

this is my script

i assume that -w $1 -c $2 $1 and $2 are variable if i change them to a -w 70 and -c 100 i get ouptput of

SNMP OK - 6.9| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=6.9

/usr/local/nagios/libexec/check_snmp -H xx.xx.xx.xx -C xxxx -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$

i run this script and get a output of SNMP WARNING - 0| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=6.9

command
# '241_total_load' command definition
define command{
command_name 241_total_load
command_line $USER1$/241_total_load -w $ARG1$ -c $ARG2$


service

define service{
use generic-service,srv-pnp
host_name Metered Rack PDU 241
service_description APC Metered Total
check_command 241_total_load!-w 50 -c 100
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
contacts nagiosadmin
}

with these setting a get a snmp warning 0 but stay green

can you verify that these are the correct info thank you
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Bash Script Help

Post by rkennedy »

What command are you running to produce this? -

Code: Select all

SNMP WARNING - 0| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=6.9
Are you specifying a $1 and $2 variable? I don't think your check command needs to specify a -w and -c since you're already specifying that in the wrapper script. It just expects to be ran like this -

Code: Select all

script.sh 70 100
Which then passes $1 as 70, and $2 as 100, to the wrapper script, which then fills in $1 and $2 as 70 / 100.
Former Nagios Employee
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post by spyder13337 »

i run this script

bash /usr/local/nagios/libexec/241_total_load

which contains

#!/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 50 -c 100 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[$
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Bash Script Help

Post by rkennedy »

Could you clarify what the issue is at this point, since you hard coded the -w and -c?

You should be able to change this from your command_line now for the command definition -

Code: Select all

$USER1$/241_total_load -w $ARG1$ -c $ARG2$
to -

Code: Select all

$USER1$/241_total_load
Former Nagios Employee
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post by spyder13337 »

the issue is that i dont received any email alert it done not show warning or critical it just show "SNMP WARNING - 0| iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=6.7"

what i would like for it to show is warring or critical and what the current level is so her is my lastest info

i run my script directly {as before i am specifying the Variable }

/usr/local/nagios/libexec/241_total_load

/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$

here is my service.cfg

define service{
use generic-service,srv-pnp
host_name Metered Rack PDU 241
service_description APC Metered Total
check_command 241_total_load! 70 100 {do i specific the variable here or in the command } {and is this the right format}
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
contacts nagiosadmin
}

here is the command.cfg

# '241_total_load' command definition
define command{
command_name 241_total_load
command_line $USER1$/241_total_load {do i specific the variable here or in the command } {-w $ARG1$ -c $ARG2$} {is this the right format}
}

as stated in the previous comments i am not receiving email alert i did add AWK command function to it so that it display in 9.6 Amps instead of 96 which is more realistic i ams sorry for the mix up but i hope my point get across but if i remove the variable in the wrapper script the command function just fine and display it in the right format of 9.6 i am not 100 sure so i was changing thing around to see what result i would get
Locked