Page 1 of 5

Nagios Bash Script Help

Posted: Tue May 10, 2016 10:41 am
by spyder13337
so here is the issue i received a bash script form a member named box293 on this forum

which works fine

Thank you

"#!/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 | 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;}'"


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! -w 5 -c 7
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
contacts nagiosadmin

command.cfg


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



that is my current config but i am not able to generate any alert this should work right ? i tried the alerts on the script it self but nothing happens

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 10:56 am
by rkennedy
You'll need to modify the script, and keep in mind your warning / critical need to be in the original format, not the divided out amount.

To the end of this part -

Code: Select all

-C xxxxx -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 
Change it to -

Code: Select all

-C xxxxx -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 -w $1 -c $2
This will then let you pass variables to your script as the warning / crit values as $1 and $2 variables. In bash, these are the first two variables after the call to the script. So by running yourscript.sh one two would make -w one and -c two.

Once that's done, change your command definition to -

Code: Select all

command_line $USER1$/241_total_load $ARG1$
and, your check_command to -

Code: Select all

check_command 241_total_load!one two
(where one is the warning value, and two is the critical value)

Let us know if you run into any issues!

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 4:16 pm
by spyder13337
i did what the script said but still get no alerts

this would be the waring of 1 and critical of 2

"-C xxxxx -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 -w $1 -c $2"

should this have a Warn and critical valuable or just one

"command_line $USER1$/241_total_load $ARG1$"

my check command

check_command 241_total_load!one two

but is still get no alerts

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 4:50 pm
by ssax
Please post your command definition, your service definition, and your modified bash script so that we can troubleshoot further.

Thank you

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 4:53 pm
by spyder13337
thank you for your responds but if you look at the first post that was my initial info i then mod it to what rkennedy told me to use

Mod Note: In the future please don't modify previous posts this way, it creates confusion when reading through the issue. If you have an update, please put it in a new post.

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 5:04 pm
by ssax
That's fine, the reason why I ask is because a lot of the times we see things changed based on the initial configuration that was posted so we make assumptions based on that (which can be wrong), it helps us to have it in it's latest configuration.

Code: Select all

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

Code: Select all

define command{
command_name 241_total_load
command_line $USER1$/241_total_load $ARG1$
}
but still get no alerts
Are you saying that your are not getting emails or the check is not working at all?


Thank you

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 5:42 pm
by spyder13337
i received email from other services and host but not these

here is my bash 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]/1$


here is my service file

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

here is my command

# '241_total_load' command definition
define command{
command_name 241_total_load
command_line $USER1$/241_total_load $ARG1$

sorry for the confusion

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 5:44 pm
by spyder13337
i am not getting any alert email but the check is working fine i can see the info Ampes on my APC vary so i know that it is working but i need to get the alert to work incase it goes to high

Re: Nagios Bash Script Help

Posted: Tue May 10, 2016 6:35 pm
by Box293
Can you run the plugin at the command line, without all the awk stuff, then do echo $?

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 $?
What is the output?

Re: Nagios Bash Script Help

Posted: Wed May 11, 2016 8:29 am
by spyder13337
this is my output w/o awk command

SNMP OK - 68 | iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=68;one;two

not sure how to use the echo command