Page 1 of 2

Nagios Core - Problem with E-Mail Notifications

Posted: Wed Apr 20, 2016 8:43 am
by Bone8Head
Good Morning,

I have a problem with the E-Mail Notifications in my Nagios Core.
Can you check my Files please, and tell me if I did something wrong?

There are an example of one of my Command (The E-Mail Commands that I have) - Contact - Service - Host.

Commands:

Code: Select all

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


# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/lib/nagios/host-perfdata.out
}


# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/lib/nagios/service-perfdata.out
}
Contacts:

Code: Select all

define contact{
        contact_name                    nagiosadmin									; Short name of user
		use								generic-contact								; Inherit default values from generic-contact template (defined above)
        alias                          	xxx								; Full name of user
		email                          	[email protected]	; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
		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
        }

define contactgroup{
        contactgroup_name       admins
        alias                             Nagios Administrators
        members                       nagiosadmin
        }
Services:

Code: Select all

	define service{
	use				        generic-service
	servicegroups			xxx
	host_name				xxx
	service_description		Ping
	check_command		check_ping!200.0,40%!400.0,80%
	check_interval			5
	retry_interval			5
	max_check_attempts		10
	check_period			24x7
	notification_interval         	300
	notification_period		24x7
	notification_options     	w,c,r
	}
Hosts:

Code: Select all

define host{	
	hostgroups						  xxx
	host_name						  xxx			; The name we're giving to this host
	alias							  xxx			; A longer name associated with the host
	address						  xxx				; IP address of the host
	check_command           		          check-host-alive
    register 						  1
	max_check_attempts 		          10
	contacts						  nagiosadmin
	check_interval					  5
	retry_interval					  1
	contacts						  nagiosadmin
	check_period					  24x7
	notification_interval		   	          300
	notification_period				  24x7
	}
Thank you very much.

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Wed Apr 20, 2016 10:10 am
by rkennedy
Can you please emulate triggering a notification, and post your /var/log/maillog file?

Additionally, when it should be sending the notification, do you see it being triggered under Reports -> Notifications? (please attach a screenshot of this page)

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Thu Apr 21, 2016 1:53 am
by Bone8Head
rkennedy wrote:Can you please emulate triggering a notification, and post your /var/log/maillog file?

Additionally, when it should be sending the notification, do you see it being triggered under Reports -> Notifications? (please attach a screenshot of this page)
Ok, like yesterday i Did "Send Custom Notification" ---> Forced - Broadcast (at 08:49).

Service Notifications:

Image

Mailog File:

Code: Select all

Apr 21 08:49:53 nagioscorefe postfix/pickup[10731]: 7DEA120BD0: uid=500 from=<nagios>
Apr 21 08:49:53 nagioscorefe postfix/cleanup[24693]: 7DEA120BD0: message-id=<[email protected]>
Apr 21 08:49:53 nagioscorefe postfix/qmgr[1831]: 7DEA120BD0: from=<[email protected]>, size=760, nrcpt=1 (queue active)
Apr 21 08:49:53 nagioscorefe postfix/local[24695]: 7DEA120BD0: to=<[email protected]>, orig_to=<nagios@localhost>, relay=local, delay=0.15, delays=0.08/0.03/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)
Apr 21 08:49:53 nagioscorefe postfix/qmgr[1831]: 7DEA120BD0: removed
Is like "Status - Sent".

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Thu Apr 21, 2016 1:05 pm
by rkennedy
Did you run service nagios restart after making changes to your contact definition?

What OS did you install Core on, and what is the output of which mail?

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Fri Apr 22, 2016 4:34 am
by Bone8Head
rkennedy wrote:Did you run service nagios restart after making changes to your contact definition?

What OS did you install Core on, and what is the output of which mail?
1) Yes, I always did service nagios restart
2) CentOS 6.7
3)

Code: Select all

[root@nagioscorefe /]# which mail
/bin/mail

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Fri Apr 22, 2016 2:02 pm
by hsmith
Do you have access to your mail logs to make sure this isn't getting filtered?

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Mon Apr 25, 2016 1:42 am
by Bone8Head
hsmith wrote:Do you have access to your mail logs to make sure this isn't getting filtered?
Yes, the E-Mail isn't getting filtered.

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Mon Apr 25, 2016 10:04 am
by rkennedy
Bone8Head wrote:
rkennedy wrote:Did you run service nagios restart after making changes to your contact definition?

What OS did you install Core on, and what is the output of which mail?
1) Yes, I always did service nagios restart
2) CentOS 6.7
3)

Code: Select all

[root@nagioscorefe /]# which mail
/bin/mail

Code: Select all

# '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" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
I believe this is the issue. Your command is referencing /usr/bin/mail, and your server is using /bin/mail. Try updating your notify-host-by-email and notify-service-by-email to use /bin/mail rather then /usr/bin/mail.

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Tue Apr 26, 2016 1:58 am
by Bone8Head
rkennedy wrote:
Bone8Head wrote:
rkennedy wrote:Did you run service nagios restart after making changes to your contact definition?

What OS did you install Core on, and what is the output of which mail?
1) Yes, I always did service nagios restart
2) CentOS 6.7
3)

Code: Select all

[root@nagioscorefe /]# which mail
/bin/mail

Code: Select all

# '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" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
I believe this is the issue. Your command is referencing /usr/bin/mail, and your server is using /bin/mail. Try updating your notify-host-by-email and notify-service-by-email to use /bin/mail rather then /usr/bin/mail.
As you said I edited in the commands.cfg all the usr/bin/mail to /bin/mail (4), but nothing changed now..

Re: Nagios Core - Problem with E-Mail Notifications

Posted: Tue Apr 26, 2016 7:34 am
by Bone8Head
Another thing: now I was looking at the maillog file in /var/log/, and I see one thing (when I try to force a notification from WEB GUI):

Code: Select all

Apr 26 14:25:17 nagioscorefe postfix/qmgr[1831]: 74AA520BE6: from=<[email protected]>, size=811, nrcpt=1 (queue active)
Apr 26 14:25:17 nagioscorefe postfix/local[18885]: 74AA520BE6: to=<[email protected]>, orig_to=<nagios@localhost>, relay=local, delay=0.1, delays=0.06/0.02/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
This E-Mail address "to=<[email protected]" is different from the one that I writed in the commands file (notify host mail etc.)...
So it seems like that nagios is sending an E-Mail to [email protected] and not to the mine?
This is can be the problem?
Actually I find this Address "[email protected]" in the nagios.cfg file.

Code: Select all

# ADMINISTRATOR EMAIL/PAGER ADDRESSES
# The email and pager address of a global administrator (likely you).
# Nagios never uses these values itself, but you can access them by
# using the $ADMINEMAIL$ and $ADMINPAGER$ macros in your notification
# commands.

[email protected]
admin_pager=pagenagios@localhost
I tried to edit this and put in my E-Mail, but still nothing.

This is what I see in the Nagios Core GUI ---> Configuration --- Web Config ---> Contacts.

Image

Last thing, Nagios Core don't need the "E-Mail Configuration" (Pop Server, Smtp Server, Authentication credentials) for sending the E-Mail?

Thanks.