Script doesn't run when Nagios is Daemonized
Posted: Wed Jul 18, 2012 3:03 pm
Currently running: Nagios 3.4.1 on Centos 6.2
I have a special script that I wrote to send me email notifications in the event that our primary Internet connection fails. This script is a simple BASH script as follows:
I know this is ugly. I'm just trying to get it to work for now. This flips over to a secondary cheap Internet connection we have, connects to a remote server (It uses a keyfile to authenticate), and uses that to send an email.
In the command.cfg, I added the following command:
I'm using sudo because the command changes routes (Which requires root). I've added the proper entries to the /etc/sudoers file. I can run this command as the user "nagios" and it works successfully.
Next I've got a special user and I've assigned their host_notification_commands and service_notification_commands to the "notify-internet-down" command.
Now when I'm testing and I take the "Internet" host down, I don't get a notification. However, if I start nagios as the nagios user without the -d (To daemonize it), the notification script works when I bring the "Internet" host down. I've tried to turn on debugging, but I'm not seeing any information on what is wrong. Any help is appreciated. Thanks!
I have a special script that I wrote to send me email notifications in the event that our primary Internet connection fails. This script is a simple BASH script as follows:
Code: Select all
#!/bin/bash
/sbin/route add -host `/usr/bin/nslookup site2.mydomain.com | /bin/awk 'NF > 1' | /bin/awk '{ field = $NF}; END{print field }'` gw 192.168.1.2
/usr/bin/ssh [email protected] "sendmail -t < /root/email_wic_nagios"
/sbin/route del -host `/usr/bin/nslookup site2.mydomain.com | /bin/awk 'NF > 1' | /bin/awk '{ field = $NF}; END{print field }'` gw 192.168.1.2]In the command.cfg, I added the following command:
Code: Select all
define command{
command_name notify-internet-down
command_line /usr/bin/sudo /usr/local/nagios/libexec/internet_down.sh
}
Next I've got a special user and I've assigned their host_notification_commands and service_notification_commands to the "notify-internet-down" command.
Now when I'm testing and I take the "Internet" host down, I don't get a notification. However, if I start nagios as the nagios user without the -d (To daemonize it), the notification script works when I bring the "Internet" host down. I've tried to turn on debugging, but I'm not seeing any information on what is wrong. Any help is appreciated. Thanks!