Page 1 of 3

Email notification from Nagios

Posted: Mon May 19, 2014 8:49 am
by kimjaggi
hi,

I am trying to enable email notification for Nagios. I am running Nagios core 4.0.6 on CentOS6.5.

Below are the configurations of the files I have changed to setup notification but I still didn't get any email. Do I have to do something Special on CentOS as well? for example postfix?

Code: Select all

[nagios@xyz objects]$ which mail
/bin/mail
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$
        }

# 'notify-service-by-email' command definition
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$\n" |/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
IN Contacts.cfg

Code: Select all

define contact{
        contact_name                    nagiosadmin
        use                             generic-contact
        alias                           Nagios Admin
        email                           [email protected]
}

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }
In Template.cfg

Code: Select all

define contact{
        name                            generic-contact         ; The name of this contact template
        service_notification_period     24x7                    ; service notifications can be sent anytime
        host_notification_period        24x7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-email ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }

Re: Email notification from Nagios

Posted: Mon May 19, 2014 10:39 am
by slansing
Are you seeing any mail being passed through your maillog?:

Code: Select all

tail -50 /var/log/maillog

Re: Email notification from Nagios

Posted: Tue May 20, 2014 6:13 am
by kimjaggi
No, I get error related to postfix

Somthing like {error/postfix} - email deferred connection timed out.


Sorry couldnt send you the entire message, I dont have system with me.

Re: Email notification from Nagios

Posted: Tue May 20, 2014 10:56 am
by lmiltchev
Well, we need to see the error message. Can you send a test email from the CLI and see if you are going to receive it?

Code: Select all

 echo "test" | mail -s "test mail" [email protected]

Re: Email notification from Nagios

Posted: Wed May 21, 2014 4:06 am
by kimjaggi
5.178]:25: Connection timed out)
May 21 11:01:46 postfix/error[5015]: 6D3F2100335: to=<[email protected]>, relay=none, delay=147550, delays=147520/30/0/0.03, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com[37.202.5.178]:25: Connection timed out)
May 21 11:01:46 EIS02 postfix/error[5018]: 869081002C1: to=<[email protected]>, relay=none, delay=235723, delays=235693/30/0/0.06, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com[37.202.5.178]:25: Connection timed out)
May 21 11:01:46 EIS02 postfix/error[5019]: 7CA75100195: to=<[email protected]>, relay=none, delay=416315, delays=416285/30/0/0.06, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com.com[37.202.5.178]:25: Connection timed out)
May 21 11:03:13 EIS02 postfix/pickup[23215]: CFCE810028C: uid=0 from=<root>
May 21 11:03:13 EIS02 postfix/cleanup[5865]: CFCE810028C: message-id=<[email protected]>
May 21 11:03:13 EIS02 postfix/qmgr[29151]: CFCE810028C: from=<root@EIS02localdomain>, size=473, nrcpt=1 (queue active)
May 21 11:03:13 EIS02 postfix/error[5011]: CFCE810028C: to=<[email protected]>, relay=none, delay=0.12, delays=0.09/0/0/0.03, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com[37.202.5.178]:25: Connection timed out)

Re: Email notification from Nagios

Posted: Wed May 21, 2014 3:49 pm
by sreinhardt
I think lmiltchev really wanted you to replace the [email protected] with an actual email address that you are trying to send to. However, considering this message, is it pretty much the same as errors for when nagios attempts to send a notification?

Re: Email notification from Nagios

Posted: Thu May 22, 2014 4:33 am
by kimjaggi
Sure,I used real email address. I just didnt want to use it on Nagios

when nagios attempts to send a notification, The results are as below: (again, I have changed the email addresses)

Code: Select all

May 21 11:01:46 postfix/error[5015]: 6D3F2100335: to=<[email protected]>, relay=none, delay=147550, delays=147520/30/0/0.03, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com[37.202.5.178]:25: Connection timed out)
May 21 11:01:46 EIS02 postfix/error[5018]: 869081002C1: to=<[email protected]>, relay=none, delay=235723, delays=235693/30/0/0.06, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com[37.202.5.178]:25: Connection timed out)
May 21 11:01:46 EIS02 postfix/error[5019]: 7CA75100195: to=<[email protected]>, relay=none, delay=416315, delays=416285/30/0/0.06, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to xyz.com.com[37.202.5.178]:25: Connection timed out)

Re: Email notification from Nagios

Posted: Thu May 22, 2014 8:28 am
by scottwilkerson
This portion of the message tells it all

Code: Select all

connect to xyz.com[37.202.5.178]:25: Connection timed out
It means that your Nagios server cannot connect to the mail server (xyz.com[37.202.5.178]:25) to deliver the message. Either the mail server is down, or something is blocking network traffic such as an outage.

Re: Email notification from Nagios

Posted: Thu May 22, 2014 8:36 am
by eloyd
something is blocking network traffic such as an outage
It's really hard to tell, but you can at least try this from the command line on your Nagios box:

$ telnet 37.202.5.178 25

If you get a "Trying 37.202.5.178..." message, then you can't connect. (You may not have the telnet command installed.) As a test, from our server, I did it and I get a "Trying 37.202.5.178..." message. This says that that mail server is definitely not reachable, but it could be due to any of the reasons listed below.

Is this mail server that you're sending the mail to at your site or at a someone else's site? Meaning, are you running the mail server or is it something like gmail or hotmail? If it's your mail server, look at firewalls or iptables. Make sure you're not blocking (or "are allowing", whichever is apropos) your Nagios server to communicate. If it's NOT your mail server, you may be bumping up against their firewall, you may not have a network route to get there, they may not be allowing connections from the outside, or the server may be down.

Re: Email notification from Nagios

Posted: Thu May 22, 2014 4:46 pm
by tmcdonald
Thanks Eric.

@kimjaggi, let us know if you are in fact blocking anywhere as per scottwilkerson and eloyd's posts.