Setting up Email Alerts

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.
CSSI
Posts: 20
Joined: Fri Jun 07, 2013 3:15 pm

Setting up Email Alerts

Post by CSSI »

Excuse my ignorance but I can't seem to be able to figure out how to setup email alerts.

I have postfix working and have tested it in terminal using the mail command.
I have my target email address in contacts.cfg and I have services that are reporting critical yet no email alert ever gets sent out.

Does anyone have any ideas?

Thanks!
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Setting up Email Alerts

Post by lmiltchev »

Do you see anything useful in the log files?

Code: Select all

tail /usr/local/nagios/var/nagios.log
tail /var/log/maillog
Be sure to check out our Knowledgebase for helpful articles and solutions!
CSSI
Posts: 20
Joined: Fri Jun 07, 2013 3:15 pm

Re: Setting up Email Alerts

Post by CSSI »

I do see errors related to the email, but I'm not sure what to do with it. I am able to send mail from terminal.

tail /usr/local/nagios/var/nagios.log reports

Code: Select all

SERVICE NOTIFICATION: nagiosadmin;BPMDC001;Uptime;CRITICAL;notify-service-by-email;CRITICAL - Socket timeout after 10 seconds
[1371222427] Warning: Attempting to execute the command "/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: Uptime\nHost: BPM Domain Controller\nAddress: 66.148.161.2\nState: CRITICAL\n\nDate/Time: Fri Jun 14 11:07:07 EDT 2013\n\nAdditional Info:\n\nCRITICAL - Socket timeout after 10 seconds\n" | /bin/mail -s "** PROBLEM Service Alert: BPM Domain Controller/Uptime is CRITICAL **" m.hudgins@gmail.com" resulted in a return code of 127.  Make sure the script or binary you are trying to execute actually exists...
[1371222437] SERVICE NOTIFICATION: nagiosadmin;edison1.cssi.us;Webpage Response;CRITICAL;notify-service-by-email;RESPONSE: CRITICAL - URL edison1.cssi.us cant resolve or port 80 not open
[1371222437] Warning: Attempting to execute the command "/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: Webpage Response\nHost: edison1.cssi.us\nAddress: edison1.cssi.us\nState: CRITICAL\n\nDate/Time: Fri Jun 14 11:07:17 EDT 2013\n\nAdditional Info:\n\nRESPONSE: CRITICAL - URL edison1.cssi.us cant resolve or port 80 not open\n" | /bin/mail -s "** PROBLEM Service Alert: edison1.cssi.us/Webpage Response is CRITICAL **" m.hudgins@gmail.com" resulted in a return code of 127.  Make sure the script or binary you are trying to execute actually exists...
[1371222557] Warning: Return code of 127 for check of service 'System-Event-Log' on host 'BPMDC001' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1371222557] SERVICE NOTIFICATION: nagiosadmin;BPMDC001;System-Event-Log;CRITICAL;notify-service-by-email;(Return code of 127 is out of bounds - plugin may be missing)
[1371222557] Warning: Attempting to execute the command "/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: System-Event-Log\nHost: BPM Domain Controller\nAddress: 66.148.161.2\nState: CRITICAL\n\nDate/Time: Fri Jun 14 11:09:17 EDT 2013\n\nAdditional Info:\n\n(Return code of 127 is out of bounds - plugin may be missing)\n" | /bin/mail -s "** PROBLEM Service Alert: BPM Domain Controller/System-Event-Log is CRITICAL **" m.hudgins@gmail.com" resulted in a return code of 127.  Make sure the script or binary you are trying to execute actually exists...
[1371222657] Warning: Return code of 127 for check of service 'System-Event-Log' on host '2presserver' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1371222657] SERVICE NOTIFICATION: nagiosadmin;2presserver;System-Event-Log;CRITICAL;notify-service-by-email;(Return code of 127 is out of bounds - plugin may be missing)
[1371222657] Warning: Attempting to execute the command "/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: System-Event-Log\nHost: 2Pres Server\nAddress: 74.143.178.34\nState: CRITICAL\n\nDate/Time: Fri Jun 14 11:10:57 EDT 2013\n\nAdditional Info:\n\n(Return code of 127 is out of bounds - plugin may be missing)\n" | /bin/mail -s "** PROBLEM Service Alert: 2Pres Server/System-Event-Log is CRITICAL **" m.hudgins@gmail.com" resulted in a return code of 127.  Make sure the script or binary you are trying to execute actually exists...
tail /var/log/mail.log reports

Code: Select all

Jun  9 07:46:40 matt-GM5424 postfix/pickup[25659]: 0B317B401BE: uid=0 from=<root>
Jun  9 07:46:40 matt-GM5424 postfix/cleanup[28727]: 0B317B401BE: message-id=<20130609114640.0B317B401BE@matt-GM5424>
Jun  9 07:46:40 matt-GM5424 postfix/qmgr[1735]: 0B317B401BE: from=<root@cssi.us>, size=446, nrcpt=1 (queue active)
Jun  9 07:46:42 matt-GM5424 postfix/smtp[28729]: 0B317B401BE: to=<root@cssi.us>, orig_to=<root>, relay=smtp.gmail.com[173.194.64.109]:587, delay=2.8, delays=0.14/0.01/1.1/1.5, dsn=2.0.0, status=sent (250 2.0.0 OK 1370778405 rs4sm6073136obc.10 - gsmtp)
Jun  9 07:46:42 matt-GM5424 postfix/qmgr[1735]: 0B317B401BE: removed
Jun 14 10:57:27 matt-GM5424 postfix/master[1168]: daemon started -- version 2.9.6, configuration /etc/postfix
Jun 14 10:57:39 matt-GM5424 postfix/master[1168]: reload -- version 2.9.6, configuration /etc/postfix

sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Setting up Email Alerts

Post by sreinhardt »

Well it looks like the from and to fields are the same on the notifications, is this expected? Otherwise it does appear that it is being correctly sent through the gmail smtp gateway that you have setup. Have you tried looking in the spam folder by chance?
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.
CSSI
Posts: 20
Joined: Fri Jun 07, 2013 3:15 pm

Re: Setting up Email Alerts

Post by CSSI »

Yes the 'to' and 'from' fields being the same is expected. I'm just trying to get it to work at all and test it. I've looked through the spam and junk folders, and performed searches in every box but have not seen anything.

Is there something else I can do to further test it?
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Setting up Email Alerts

Post by sreinhardt »

Based on that postfix is saying that the mail is sent, I would presume this is a gmail issue. Do you have the domain you are sending to hosted on gmail, or have some form of agreement with them to use their relay? Also just to be sure I would try differing the to and from addresses, and possibly not use root on either setting.
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.
CSSI
Posts: 20
Joined: Fri Jun 07, 2013 3:15 pm

Re: Setting up Email Alerts

Post by CSSI »

Oh. I did not mean to use root@cssi.us as my email. I meant to use my personal gmail account as the user. root@cssi.us does not exist
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Setting up Email Alerts

Post by sreinhardt »

HA that would do it! We all make mistakes, let us know how it works.
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.
CSSI
Posts: 20
Joined: Fri Jun 07, 2013 3:15 pm

Re: Setting up Email Alerts

Post by CSSI »

Sorry again, excuse my ignorance, but I'm having trouble replacing the root@cssi.us. I looked in the contacts.cfg file for nagios and the contact is setup as my personal email rather than root@cssi.us. I also looked in the main.cf file for postfix. Is there somewhere I'm not looking?
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Setting up Email Alerts

Post by sreinhardt »

what is /bin/mail linked to? Our standard notification handlers use that, its possible although not likely based on the postfix logs, that it is set to sendmail or something. Otherwise changing the mail information in the contact and restarting nagios should change it.
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.
Locked