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.
kimjaggi
Posts: 44
Joined: Thu Apr 17, 2014 3:56 am

Email notification from Nagios

Post 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!
        }
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Email notification from Nagios

Post by slansing »

Are you seeing any mail being passed through your maillog?:

Code: Select all

tail -50 /var/log/maillog
kimjaggi
Posts: 44
Joined: Thu Apr 17, 2014 3:56 am

Re: Email notification from Nagios

Post 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.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Email notification from Nagios

Post 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]
Be sure to check out our Knowledgebase for helpful articles and solutions!
kimjaggi
Posts: 44
Joined: Thu Apr 17, 2014 3:56 am

Re: Email notification from Nagios

Post 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)
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Email notification from Nagios

Post 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?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
kimjaggi
Posts: 44
Joined: Thu Apr 17, 2014 3:56 am

Re: Email notification from Nagios

Post 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)
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Email notification from Nagios

Post 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.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Email notification from Nagios

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Email notification from Nagios

Post by tmcdonald »

Thanks Eric.

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