Notify By Email Not Working

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.
Locked
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Notify By Email Not Working

Post by rlinux57 »

When i send email like "mail -s "subject" abc@domainname < /dev/null" it works perfectly but not working when send custom notification or any warning and critical state.

Code: Select all

[root@monitor ~]# which mail
/bin/mail

Code: Select all

[root@monitor ~]# which printf
/usr/bin/printf

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

Custom notifications shows that email sent but it's not received:
Your command request was successfully submitted to Nagios for processing.

Note: It may take a while before the command is actually processed.

Done
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Notify By Email Not Working

Post by lmiltchev »

Do you see any errors in the mail log?

Code: Select all

tail -100 /var/log/maillog
Be sure to check out our Knowledgebase for helpful articles and solutions!
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: Notify By Email Not Working

Post by rlinux57 »

I have fixed it at my own by set the following settings in contacts.cfg file:

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downt$
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime$
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
email Email ID ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
Thanks for the cooperation.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Notify By Email Not Working

Post by rkennedy »

You're welcome, I'll close this out now, but if you need any assistance in the future feel free to open a new thread.
Former Nagios Employee
Locked