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

Nagios Bash Script Help

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

Re: Nagios Bash Script Help

Post 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!
Former Nagios Employee
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post 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
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios Bash Script Help

Post by ssax »

Please post your command definition, your service definition, and your modified bash script so that we can troubleshoot further.

Thank you
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post 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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios Bash Script Help

Post 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
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

Post 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
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: Nagios Bash Script Help

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