Problem with mail notifications

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.
Locked
m.siib
Posts: 6
Joined: Mon Dec 01, 2014 9:32 am

Problem with mail notifications

Post by m.siib »

Running Nagios 4.0.8 on Debian 7. Mail notifications are not being sent. I can send test email from the command line. Checked commands.cfg to check the path to mail and it is correct. Where can I look to troubleshoot? I've done it many times before with no issue, but this one is puzzling. If you want to suggest a never fail mailer to install, I'm ok with that.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Problem with mail notifications

Post by tmcdonald »

What command are you using from the command line to send mail, and as what user? What command do you have defined in Nagios to send mail? Are you able to run the first command as nagios instead of as root?
Former Nagios employee
m.siib
Posts: 6
Joined: Mon Dec 01, 2014 9:32 am

Re: Problem with mail notifications

Post by m.siib »

As root or nagios:

Code: Select all

root@nagios:~# mail to [email protected]
Cc:
Subject: test

root@nagios:~#

I'm using the defaults in Nagios.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Problem with mail notifications

Post by slansing »

Can you share your nagios command which is responsible for sending notifications out? An let us know what guide (if any) you were following for this? The more info you can give us on how you set your mailer up, the better...
m.siib
Posts: 6
Joined: Mon Dec 01, 2014 9:32 am

Re: Problem with mail notifications

Post by m.siib »

Here are the notify commands - defaults. In troubleshooting I've also tried pointing to /bin/mail depending on the mailer.

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" | /usr/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" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
	}
I wrote my own guide about five years ago that I've been following (link). I've had to adapt it for Debian 7 and it seems the mail part doesn't work as I'm used to. In my troubleshooting I've tried postfix, exim4, and sendmail with bsd-mailx, heirloom-mailx. I don't care which one is used, I just need something to work. If there is a start-to finish guide I'm willing to try anything.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Problem with mail notifications

Post by sreinhardt »

Is the mail server you intend to send to, on an internal or external network to the nagios system? Just wondering if you need to bother with spam filtering or if this is going straight through.
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.
m.siib
Posts: 6
Joined: Mon Dec 01, 2014 9:32 am

Re: Problem with mail notifications

Post by m.siib »

Internal.
m.siib
Posts: 6
Joined: Mon Dec 01, 2014 9:32 am

Re: Problem with mail notifications

Post by m.siib »

I switched back to sendmail and bsd-mailx. I find that it works to send to external recipients, but not internal. I think the problem is that I'm sending to [email protected], but the nagios host is nagios.domain.com so maybe it's trying to deliver locally. What do I need to tweak?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Problem with mail notifications

Post by abrist »

Can you post a tail of the maillog after a failed send?

Code: Select all

tail -15 /var/log/maillog
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
m.siib
Posts: 6
Joined: Mon Dec 01, 2014 9:32 am

Re: Problem with mail notifications

Post by m.siib »

I got it working.

I added the following to /etc/mail/sendmail.mc

Code: Select all

define(`MAIL_HUB', `domain.com.')dnl
define(`LOCAL_RELAY', `domain.com.')dnl



EDIT: Locked, glad you have it working.
Locked