Nagios Core - Problem with E-Mail Notifications

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Bone8Head
Posts: 106
Joined: Tue Nov 10, 2015 2:39 am

Nagios Core - Problem with E-Mail Notifications

Post 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                          	xxx@xxx.com	; <<***** 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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)
Former Nagios Employee
Bone8Head
Posts: 106
Joined: Tue Nov 10, 2015 2:39 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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=<20160421064953.7DEA120BD0@nagioscorefe.xxx.com>
Apr 21 08:49:53 nagioscorefe postfix/qmgr[1831]: 7DEA120BD0: from=<nagios@nagioscorefe.xxx.com>, size=760, nrcpt=1 (queue active)
Apr 21 08:49:53 nagioscorefe postfix/local[24695]: 7DEA120BD0: to=<nagios@localhost.xxx.com>, 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".
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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?
Former Nagios Employee
Bone8Head
Posts: 106
Joined: Tue Nov 10, 2015 2:39 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Nagios Core - Problem with E-Mail Notifications

Post by hsmith »

Do you have access to your mail logs to make sure this isn't getting filtered?
Former Nagios Employee.
me.
Bone8Head
Posts: 106
Joined: Tue Nov 10, 2015 2:39 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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.
Former Nagios Employee
Bone8Head
Posts: 106
Joined: Tue Nov 10, 2015 2:39 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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..
Bone8Head
Posts: 106
Joined: Tue Nov 10, 2015 2:39 am

Re: Nagios Core - Problem with E-Mail Notifications

Post 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=<nagios@nagioscorefe.xxx.com>, size=811, nrcpt=1 (queue active)
Apr 26 14:25:17 nagioscorefe postfix/local[18885]: 74AA520BE6: to=<nagios@localhost.xxx.com>, 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=<nagios@localhost.xxx.com" 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 nagios@localhost.xxx.com and not to the mine?
This is can be the problem?
Actually I find this Address "nagios@localhost.xxx.com" 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.

admin_email=nagios@localhost.xxx.com
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.
Locked