Page 1 of 1

Nagios Email Notifications not sending emails

Posted: Tue Jul 05, 2016 10:25 am
by allta
Nagios Core 4.1.1 (Student VM)
Notification is enabled in nagios.cfg
[root@nagios ~]# cat /usr/local/nagios/etc/nagios.cfg | grep enable_notifications
enable_notifications=1

below is content of my host's cfg
define host {
host_name maplebee-001
address 10.10.10.10
check_command check-host-alive!!!!!!!!
max_check_attempts 2
check_interval 2
retry_interval 1
check_period 24x7
flap_detection_enabled 0
contacts maplebee
notification_interval 5
notification_period 24x7
notification_options d,u,r,f,s,
notifications_enabled 1
register 1
}

below is content of my contact's cfg
define contact {
contact_name maplebee
alias maplebee
host_notifications_enabled 1
service_notifications_enabled 1
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r,f,s,n,
service_notification_options w,u,c,r,f,s,n,
host_notification_commands notify-host-by-email
service_notification_commands notify-service-by-email
email maplebeexyz001@gmail.com
}
commands' cfgs:

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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

I am able to run the mail test command from cli as root and also nagios user.

/usr/bin/printf "%b" "test" | /bin/mail -s "test subject" maplebeexyz001@gmail.com

My tail -f on nagios.log shows Host Notification HARD, but there is no HOST email alerting out msg

what am I doing wrong here? I've spent almost a couple days trying to figure this out

Re: Nagios Email Notifications not sending emails

Posted: Tue Jul 05, 2016 11:02 am
by tgriep
You need to remove the "n" from the service / host notification options
If you specify n (none) as an option, the contact will not receive any type of host / service notifications.
Change that option and restart nagios and that contact should start receiving notifications.

Re: Nagios Email Notifications not sending emails

Posted: Tue Jul 05, 2016 11:26 am
by allta
Wow, that is the issue, thanks a lot.

I removed the "n" option and emails are now being received

Re: Nagios Email Notifications not sending emails

Posted: Tue Jul 05, 2016 11:28 am
by mcapra
Is it alright if we lock this thread and mark the issue as resolved?

Re: Nagios Email Notifications not sending emails

Posted: Tue Jul 05, 2016 12:00 pm
by allta
Yes, issue resolved for me.