How to configure email notification from nagios.

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.
giles
Posts: 24
Joined: Thu Aug 18, 2016 3:56 am

How to configure email notification from nagios.

Post by giles »

Hi,

I was trying to configure email notification form nagios.

I was following the folllowing doc:

https://www.unixmen.com/send-alerts-nag ... ail-yahoo/

But when I run following command the result is as below

Code: Select all

root@opm:~# apt-get install 'perl(Net::SSLeay)' 'perl(IO::Socket::SSL)'
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package perl(Net:
E: Unable to locate package perl(IO::Socket:
Do you have any official doc to configure email notification for nagios core? I am using Ubuntu 14.04. I had installed nagios by following this doc. https://support.nagios.com/kb/article.php?id=97

Regards,
Giles.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: How to configure email notification from nagios.

Post by rkennedy »

For Core, we do not. The RHEL documentation does a pretty good job at explaining this -
https://access.redhat.com/documentation ... tions.html

Pretty much, make sure notifications are enabled on a host / service, assign a contact, and then whatever command is assigned to that contact will be triggered upon a notification. The default contact 'nagiosadmin' is a good example, which will use the notify-host-by-email and notify-service-by-email commands by default. This however, would utilize sendmail and not an external SMTP server such as gmail or yahoo.
Former Nagios Employee
giles
Posts: 24
Joined: Thu Aug 18, 2016 3:56 am

Re: How to configure email notification from nagios.

Post by giles »

Hi, I have configured email. But there are some error in nagios log as following:

Code: Select all

[09-07-2016 12:11:00] wproc: stderr line 02: /usr/bin/printf: write error: Broken pipe
Informational Message[09-07-2016 12:11:00] wproc: stderr line 01: /bin/sh: 1: /usr/bin/sendmail: not found
How can I sure that nagios is sending mail?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: How to configure email notification from nagios.

Post by rkennedy »

Take a look at the output of which mail, which will tell you the path for the mail on your system.

Code: Select all

[root@localhost var]#  which mail
/bin/mail
Now, look at how your notify-host-by-email, and notify-service-by-email, and adjust the path as needed, for example on my machine you can see /bin/mail is specified. -

Code: Select all

[root@localhost var]# cat /usr/local/nagios/etc/commands.cfg | grep 'notify-' -A 3
       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$
}

--
       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$
}
Former Nagios Employee
giles
Posts: 24
Joined: Thu Aug 18, 2016 3:56 am

Re: How to configure email notification from nagios.

Post by giles »

There is no error message on nagios log after using the appropriate path. Now, I want to forward the mails to gmail. What should be the configuration?
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: How to configure email notification from nagios.

Post by avandemore »

You can change a contact's email by editing /usr/local/nagios/etc/objects/contacts.cfg. Does this resolve your problem?
Previous Nagios employee
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: How to configure email notification from nagios.

Post by tgriep »

If you are using the /bin/mail command, you will have to either install the postfix or sendmail daemon on your server and then use that to forward emails from the nagios server to gmail.
Can you post back if the server has sendmail or postfix installed on it?
Be sure to check out our Knowledgebase for helpful articles and solutions!
giles
Posts: 24
Joined: Thu Aug 18, 2016 3:56 am

Re: How to configure email notification from nagios.

Post by giles »

I have installed postfix and configured nagios by following the following link.

http://www.telnetport25.com/2012/02/con ... gios-core/

But it is not working.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: How to configure email notification from nagios.

Post by tgriep »

Try using this procedure to configure Postfix to relay emails to an outside SMTP server.
https://www.freelock.com/kb/postfix-relayhost

If you do this, the Nagios server will use the default Notification commands so you will have to edit the commands file and put back the

Code: Select all

notify-host-by-email
notify-service-by-email
commands to the default settings and that should work for you.
Be sure to check out our Knowledgebase for helpful articles and solutions!
giles
Posts: 24
Joined: Thu Aug 18, 2016 3:56 am

Re: How to configure email notification from nagios.

Post by giles »

Hi,

Email notification is working!!!

Actually it started working yesterday just after installing and configuring the postfix, but as the email was going to spam I didn't notice it. So, configuring sasl_passwd and main.cf is not required.

Now, my domain name is rtailephant.com. So, all the notification is coming from nagios@rtailephant.com. If want change the email address such as mailuser@rtailephant.com intsead of nagios@rtailephant.com where should I change?

Regards,
Giles.
Locked