I am using nagios 3.06 to monitor the servers. When a service is critical, it sends a mail, but when a server is down no mail is sent. Even if all the services go to critical state, no mail is sent.
I have the following configuration:
define command {
command_name notify-host-by-email
command_line python /etc/nagios3/send_mail.py "[Nagios] $HOSTNAME$" "******** Nagios ****\n\n Host: $HOSTNAME$\n Description: the server is down"
}
define command{
command_name notify-service-by-email
command_line python /etc/nagios3/send_mail.py "[Nagios] $HOSTNAME$: $SERVICEDESC$ ($NOTIFICATIONTYPE$)" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info:$SERVICEOUTPUT$"
}
The python script is a script to sent a mail. It works if I execute it from the command line, but it doesn't sents an email from nagios.
What I am doing wrong?
UPDATE: The contact data is:
define contact{
contact_name root
alias Root
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email myemail@gmail.com
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members root
}
Best Answer
First check and see that nagios is actually kicking off your script by looking at nagios.log. If it is taking the appropriate action you can try logging the output of your email script by adding 2>&1 >> /tmp/mynagiosemail.log to see if it's throwing an error, either python related or os related.
I noticed that your script is in /etc/nagios3, this is an abnormal place for putting something that nagios will be executing, you may want to move it to /usr/lib/nagios/plugins/ or /usr/lib/nagios3 just to be consistant and then make sure that the nagios user can read and execute it. It doesn't look like there are any apparmor limitations on that but it can't hurt.