Page 1 of 1

Notify By Email Not Working

Posted: Fri Mar 11, 2016 12:24 pm
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

Re: Notify By Email Not Working

Posted: Fri Mar 11, 2016 1:17 pm
by lmiltchev
Do you see any errors in the mail log?

Code: Select all

tail -100 /var/log/maillog

Re: Notify By Email Not Working

Posted: Fri Mar 11, 2016 1:26 pm
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.

Re: Notify By Email Not Working

Posted: Fri Mar 11, 2016 1:29 pm
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.