Contacts/email configuration

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.
LibrarianJoe
Posts: 16
Joined: Fri Feb 08, 2019 1:26 pm

Contacts/email configuration

Post 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
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Contacts/email configuration

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Contacts/email configuration

Post by npolovenko »

@LibrarianJoe, Can you also upload the /usr/local/nagios/var/nagios.log in this thread?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
LibrarianJoe
Posts: 16
Joined: Fri Feb 08, 2019 1:26 pm

Re: Contacts/email configuration

Post by LibrarianJoe »

Sure thing, attached.
Attachments
nagios.log
(299.48 KiB) Downloaded 461 times
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Contacts/email configuration

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
LibrarianJoe
Posts: 16
Joined: Fri Feb 08, 2019 1:26 pm

Re: Contacts/email configuration

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Contacts/email configuration

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
LibrarianJoe
Posts: 16
Joined: Fri Feb 08, 2019 1:26 pm

Re: Contacts/email configuration

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Contacts/email configuration

Post 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!
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
LibrarianJoe
Posts: 16
Joined: Fri Feb 08, 2019 1:26 pm

Re: Contacts/email configuration

Post 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?
Locked