Nagios Bash Script Help
-
spyder13337
- Posts: 68
- Joined: Tue Oct 06, 2015 9:50 pm
Nagios Bash Script Help
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
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
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 -
Change it to -
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 -
and, your check_command to -
(where one is the warning value, and two is the critical value)
Let us know if you run into any issues!
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
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
Once that's done, change your command definition to -
Code: Select all
command_line $USER1$/241_total_load $ARG1$
Code: Select all
check_command 241_total_load!one two
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
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
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
Please post your command definition, your service definition, and your modified bash script so that we can troubleshoot further.
Thank you
Thank you
-
spyder13337
- Posts: 68
- Joined: Tue Oct 06, 2015 9:50 pm
Re: Nagios Bash Script Help
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.
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
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.
Thank you
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 nagiosadminCode: Select all
define command{
command_name 241_total_load
command_line $USER1$/241_total_load $ARG1$
}Are you saying that your are not getting emails or the check is not working at all?but still get no alerts
Thank you
-
spyder13337
- Posts: 68
- Joined: Tue Oct 06, 2015 9:50 pm
Re: Nagios Bash Script Help
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
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
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
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Nagios Bash Script Help
Can you run the plugin at the command line, without all the awk stuff, then do echo $?
What is the output?
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 $?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
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
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