Nagios email notification not working on CentOS

centos6emailnagiospostfix

I have configured Nagios 3.4.4 on CentOS 6.3 Final. I have also configured Postfix with SMTP email server. I have verified from console that I am able to send email notifications and recieved them on designated address.

Nagios is configured to send notify-host-by-email and notify-service-by-email. I can see from Nagios logs that service notification alerts and customer notification being sent from Nagios. But nothing is seen on /vag/log/maillog. There are no errors either.

I even fired 'command_line' from below commands from console and they are able to send emails to address mentioned.

Commands.cfg

# 'notify-host-by-email' command definition

define command{

command_name    notify-host-by-email

command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | sudo /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

# 'notify-service-by-email' command definition
define command{

command_name    notify-service-by-email

command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | sudo /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

Contact.cfg

define contact{
    contact_name manish
    service_notification_period 24x7
    host_notification_period 24x7
    service_notification_options w,u,c,r,f
    host_notification_options d,u,r,f
    service_notification_commands notify-service-by-email
    host_notification_commands notify-host-by-email
    email manish@xxx.com
    }

define contactgroup {
    contactgroup_name   email
    alias Email Group
    members manish
    }

Nagios Groups

cat /etc/group |grep nagios
nagios:x:502:nagios,apache
nagcmd:x:503:nagios,apache

Best Answer

You need to configure contacts or contact_groups in the host/service definition. I normally create a template host and service and then override using inheritance.

http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#host http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#service http://nagios.sourceforge.net/docs/3_0/objectinheritance.html