Page 1 of 2

How to configure email notification from nagios.

Posted: Tue Sep 06, 2016 6:50 am
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.

Re: How to configure email notification from nagios.

Posted: Tue Sep 06, 2016 11:37 am
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.

Re: How to configure email notification from nagios.

Posted: Wed Sep 07, 2016 2:02 am
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?

Re: How to configure email notification from nagios.

Posted: Wed Sep 07, 2016 10:37 am
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$
}

Re: How to configure email notification from nagios.

Posted: Mon Oct 03, 2016 5:33 am
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?

Re: How to configure email notification from nagios.

Posted: Mon Oct 03, 2016 2:25 pm
by avandemore
You can change a contact's email by editing /usr/local/nagios/etc/objects/contacts.cfg. Does this resolve your problem?

Re: How to configure email notification from nagios.

Posted: Mon Oct 03, 2016 4:48 pm
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?

Re: How to configure email notification from nagios.

Posted: Tue Oct 04, 2016 8:56 am
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.

Re: How to configure email notification from nagios.

Posted: Tue Oct 04, 2016 3:58 pm
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.

Re: How to configure email notification from nagios.

Posted: Wed Oct 05, 2016 8:55 am
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 [email protected]. If want change the email address such as [email protected] intsead of [email protected] where should I change?

Regards,
Giles.