Page 1 of 2

Contacts/email configuration

Posted: Tue Mar 26, 2019 2:16 pm
by LibrarianJoe
Hello,

I'm trying to configure Nagios Core to send me emails when the services and hosts go down. I've set up sendEmail, and I think all the values in the contacts and commands config files are correct, but it's not working so presumably I'm missing something.

Here is my contact definition:

Code: Select all

define contact {
   contact_name nagiosadmin
   use          generic-contact
   alias        librarysysadmin
   email        [email protected]
Here is the host email notification command:

Code: Select all

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/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
}
And the service email notification command:

Code: Select all

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$" | /usr/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"
}

What am I missing?

Thanks much,
Joe

Re: Contacts/email configuration

Posted: Tue Mar 26, 2019 2:34 pm
by tgriep
Did you add the contact to a Host or Service configuration and enable Notifications for those Host and Services?

Here are a few examples you can look at.

Code: Select all

define host {
    host_name         localhost
    use               linux-server
    alias             localhost
    address           localhost
    contacts          nagiosadmin
    register          1
}

Code: Select all

define service {
    host_name                       localhost
    service_description             Current Users
    use                             local-service
    check_command                   check_local_users!20!50
    contacts                        nagiosadmin
    register                        1
}
Did you check to see if Notifications are enabled in the Nagios Web interface under the System > Process Info menu?

For more details, take a look at this link.
https://assets.nagios.com/downloads/nag ... tions.html

Re: Contacts/email configuration

Posted: Tue Mar 26, 2019 2:39 pm
by npolovenko
@LibrarianJoe, Can you also upload the /usr/local/nagios/var/nagios.log in this thread?

Re: Contacts/email configuration

Posted: Wed Mar 27, 2019 1:11 pm
by LibrarianJoe
Sure thing, attached.

Re: Contacts/email configuration

Posted: Wed Mar 27, 2019 1:16 pm
by scottwilkerson
Your log file shows this

Code: Select all

[1553709866] wproc:   stderr line 01: /bin/sh: 1: /usr/local/bin/sendEmail: not found
are you sure this file exists?

Code: Select all

ls -l /usr/local/bin/sendEmail

Re: Contacts/email configuration

Posted: Wed Mar 27, 2019 2:35 pm
by LibrarianJoe
Ok, fixed the /usr/local/bin/sendEmail, the one that really exists is /usr/bin/sendEmail.

Also fixed the email to reflect the Gmail STMP configuration, which I forgot to fix.

Have added in the contact stuff in the host definition on a test machine, still no notification. What else should I try?

Re: Contacts/email configuration

Posted: Wed Mar 27, 2019 3:54 pm
by scottwilkerson
LibrarianJoe wrote:Ok, fixed the /usr/local/bin/sendEmail, the one that really exists is /usr/bin/sendEmail.

Also fixed the email to reflect the Gmail STMP configuration, which I forgot to fix.

Have added in the contact stuff in the host definition on a test machine, still no notification. What else should I try?
The first thing I would suggest is trying the command from the command line (replacing the variables with the real values) to verify it works

Re: Contacts/email configuration

Posted: Fri Mar 29, 2019 12:19 pm
by LibrarianJoe
Thanks, tried that and am having issues connecting to the gmail stmp, which I'm assuming is not a Nagios issue? Will report back if there are further difficulties once I get it to connect.

Re: Contacts/email configuration

Posted: Fri Mar 29, 2019 1:09 pm
by scottwilkerson
LibrarianJoe wrote:Thanks, tried that and am having issues connecting to the gmail stmp, which I'm assuming is not a Nagios issue? Will report back if there are further difficulties once I get it to connect.
Sounds good!

Re: Contacts/email configuration

Posted: Thu Apr 04, 2019 10:40 am
by LibrarianJoe
Ok, got sendemail to work with gmail, but still no luck running the notification command. Here's what it currently looks like, post-tinkering to make it match my working example gmail test email:

Code: Select all

/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/sendEmail -s stmp.gmail.com:587 -xu [email protected] -xp PASSWORD -o tls=yes -t [email protected] -f [email protected] -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
What am I missing?