Page 1 of 2

Configuring e-Mail Notifications in Nagios Core

Posted: Mon Oct 30, 2017 9:55 am
by michaelpn
Hi,

at the moment I use Nagios version 4.3.2 by SMS notification but I would also like to use Nagios by mail notification if a server ot host is down. I have search alot but it seems to be old stuff. Do you have any idea how I should configure that. I have looked at this example:

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

but it is from February 2012. If I should use this example I'm afraid opening up “Anonymous Users” on my Exchange server2010. Do you have any idea how I could solve this issue ?

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Mon Oct 30, 2017 2:41 pm
by dwasswa
Hi @ michaelpn

Do you already have your exchange server configured to accept emails from the Nagios Server?

Also, what Linux distribution and version are you running?

Please go to /usr/local/nagios/etc/objects and send me contacts.cfg and commands.cfg files.

Example of contents in contacts.cfg:

Code: Select all

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic­contact         ; Inherit default values
        alias                           Nagios Admin            ; Full name of user
        email                           your_email  ; <<***** CHANGE THIS TO YOUR EMAIL
        }
Example of contents in commands.cfg:

Code: Select all

# 'notify-host-by-email' command definition
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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }


I am asking for those files because I want to see how you have your contacts and commands are to send SMS notifications

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Tue Oct 31, 2017 8:26 am
by michaelpn
Hi dwasswa,

I have already configured my Exchange Server to accept emails from Nagios Server.

My Linux Version is Ubuntu 14.04,05 LTS

Attached contacts.cfg and commands.cfg

I have tried your example today but not succeeded ;(

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Tue Oct 31, 2017 1:16 pm
by dwasswa
Hi @ michaelpn,

Looking at your contacts.cfg file, you need to make some modifications to get email notifications.

In your contacts.cfg file, add the following lines to your contact definitions:

Next to your host_notification_commands directive, add host-notify-by-email, these are delimited by a comma.

You must also add a directive called email to your contact definitions with your email address.

See example below:

Code: Select all

define contact{
    contact_name  mnl ;Short name of user
    use           generic-contact ;Inherit default values from generic-contact template (defined above)
    alias         Martin Noergaard ;Full name of user
    pager         0045xxxxxxxx
    email         <your email goes here>
    host_notification_period    24x7
    host_notification_options   d,u,r
    host_notification_commands notify-host-by-sms,host-notify-by-email
}



After making changes to contacts.cfg file, save and close it then restart Nagios with the following command...sudo service nagios restart

For more information about Nagios and object definitions, take a look at this guide...https://assets.nagios.com/downloads/nag ... ml#contact

Please make the changes above and let me know if you have any questions.

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Wed Nov 01, 2017 9:23 am
by michaelpn
Hi dwasswa,

Now I have done what you have asked for. I do not get any failure. I'm being notified from my sms gateway but I do not get any message like email from Nagios. I took a view at log:

Notification[11-01-2017 13:25:24] HOST NOTIFICATION: mpn;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.31.1.82)
Host Notification[11-01-2017 13:25:24] HOST NOTIFICATION: mpn;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.31.1.82)

By restarting services from Nagios is okay done, done :) so why do I not get an email ? I have my own private email too - nothing :( Do I have to install anything extra as I wrote to you some are installing Postfix but that seems like overkill ?

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Wed Nov 01, 2017 3:15 pm
by dwasswa
Hi @michaelpn

Yes, there has to be a mailer daemon installed on the server for Nagios to use to send email from to their Exchange server.

Postfix can be used orSendmail can be used. Therefore, you need to install one of them and set it up to relay to their exchange server.

Here is an article on how to set up postfix for relaying emails to another email server...https://www.howtoforge.com/postfix_rela ... mailserver


Please implement the steps above and let me know if that resolves your issue.

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Mon Nov 06, 2017 4:56 am
by michaelpn
Hi dwasswa,
by Configuring Postfix For Relaying the link you sent me : https://www.howtoforge.com/postfix_rela ... mailserver - do I have to configure for every person who I would like to sent a mail ? In my contact.cfg list I have as you know 6 persons who are notified by Host from SMS Gateway if I want them to be notified by mail (My Postfix is Configured) do I have them all using this command: echo "smtp.example.com someuser:howtoforge" > /etc/postfix/sasl_passwd which be like this;

echo "mail.fg.dk mpn:12345678" /etc/postfix/sasl_passwd - and for my colleges? Do I have to run the hole setup from beginnig to end by every user ?

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Mon Nov 06, 2017 5:28 pm
by dwhitfield
You're probably just going to be sending email as one user, correct? That would be the only user that needs to auth.

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Tue Nov 07, 2017 4:05 pm
by michaelpn
Hi dwhitfield ,

As I wrote you to mdays ago I have installed postfix and Configure Postfix For Relaying :)
I did configure the rest and i'm able to send an Test mail with this command:

guser@Nagios:~$ echo "Subject: sendmail test" | sendmail -v [email protected]
Mail Delivery Status Report will be mailed to <nguser>.


and I get this from maillog:

Reporting-MTA: dns; Nagios
X-Postfix-Queue-ID: 2D1B7560744
X-Postfix-Sender: rfc822; [email protected]
Arrival-Date: Tue, 7 Nov 2017 15:07:50 +0100 (CET)

Final-Recipient: rfc822; [email protected]
Action: relayed
Status: 2.6.0
Remote-MTA: dns; fgmail3.fg.dk
Diagnostic-Code: smtp; 250 2.6.0 <20171107140750.2D1B7560744@Nagios>
[InternalId=128207] Queued mail for delivery

--2D1B7560744.1510063671/Nagios
Content-Description: Message Headers
Content-Type: text/rfc822-headers

Return-Path: <[email protected]>
Received: by Nagios (Postfix, from userid 1000)
id 2D1B7560744; Tue, 7 Nov 2017 15:07:50 +0100 (CET)
Subject: sendmail test
Message-Id: <20171107140750.2D1B7560744@Nagios>
Date: Tue, 7 Nov 2017 15:07:50 +0100 (CET)
From: [email protected] (Nagios14045LTS)


But if I try to use the host_notification_commands notify-host-by-sms,notify-host-by-email - I get this message:

[1510139816] HOST NOTIFICATION: mpn;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.xx.x.xx)
[1510139816] HOST NOTIFICATION: mpn;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.xx.x.xx)
[1510139816] wproc: NOTIFY job 219 from worker Core Worker 19936 is a non-check helper but exited with return code 127
[1510139816] wproc: host=W2012_Tmp; service=(none); contact=mpn
[1510139816] wproc: early_timeout=0; exited_ok=1; wait_status=32512; error_code=0

[1510081046] wproc: stderr line 01: /bin/sh: 1: usr/bin/mail: not found
[1510081046] wproc: stderr line 02: /usr/bin/printf: skrivefejl: write error: Broken pipe

What do I have to do ? I'm almost there now :)

I have tried allot to solve the issue but I did not find the problem :( Should I also install mailx ?

You still have the files I guess ?

Re: Configuring e-Mail Notifications in Nagios Core

Posted: Wed Nov 08, 2017 10:42 am
by kyang
Do you still receive SMS notifications?

Run this commands and tell us the output.

Code: Select all

which mail

Code: Select all

/usr/bin/mail
quit