Page 1 of 1

Email notifications not being sent

Posted: Fri Jan 25, 2019 5:46 am
by MarcWithercy
Hi, I am brand new to Nagios and I have installed Nagios Core on an Ubuntu 18.04 VM and enabled notifications to send via email. However, I do not receive email notifications. I installed Sendmail and can successfully send a test email to my own email. Any help/advice given would be truly appreciative.

Contents from my contacts.cfg

Code: Select all

define contactgroup {

    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin
}

define contact {

contact_name nagios
alias nagios
host_notifications_enabled 1
service_notifications_enabled 1
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r,f,s
service_notification_options w,u,c,r,f,s
host_notification_commands notify-host-by-email
service_notification_commands notify-service-by-email
email [email protected]
}
Contents from my commands.cfg

Code: Select all

define command {

    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/sbin/sendmail -v [email protected]
}

define command {

    command_name    notify-service-by-email
    command_line    /usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$\n\n***** 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/sbin/sendmail -v [email protected]
}

Re: Email notifications not being sent

Posted: Fri Jan 25, 2019 2:16 pm
by benjaminsmith
Hello @MarcWithercy,

The typical Nagios Core command for notifications looks like this:

Code: Select all

define command {
    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\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 Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Notice the use of the macro $CONTACTEMAIL$ as this will allow notifications to be sent to the email address in the contact definition.

Also, make sure you have the correct settings for notifications in your host and service definitions. For example, are notifications enabled, and if so what states are they configured to notify. Please refer to the Nagios Object definitions for more detail:
https://assets.nagios.com/downloads/nag ... tions.html

Lastly, take a look at the email log for errors:

Code: Select all

/var/log/maillog