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
Post
by LibrarianJoe » Tue Mar 26, 2019 2:16 pm
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:
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
tgriep
Madmin
Posts: 9190 Joined: Thu Oct 30, 2014 9:02 am
Post
by tgriep » Tue Mar 26, 2019 2:34 pm
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
Post
by npolovenko » Tue Mar 26, 2019 2:39 pm
@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 .
scottwilkerson
DevOps Engineer
Posts: 19396 Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:
Post
by scottwilkerson » Wed Mar 27, 2019 1:16 pm
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?
LibrarianJoe
Posts: 16 Joined: Fri Feb 08, 2019 1:26 pm
Post
by LibrarianJoe » Wed Mar 27, 2019 2:35 pm
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:
Post
by scottwilkerson » Wed Mar 27, 2019 3:54 pm
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
LibrarianJoe
Posts: 16 Joined: Fri Feb 08, 2019 1:26 pm
Post
by LibrarianJoe » Fri Mar 29, 2019 12:19 pm
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:
Post
by scottwilkerson » Fri Mar 29, 2019 1:09 pm
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!
LibrarianJoe
Posts: 16 Joined: Fri Feb 08, 2019 1:26 pm
Post
by LibrarianJoe » Thu Apr 04, 2019 10:40 am
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?