Not Alerting via Email


#1

Hello,

I recently installed Nagios 2.0.4b. I know it’s a beta and I shouldn’t be running it, but I’m just playing for now.

Anyway, for some reason it doesn’t send me emails on alerts. I’m not sure why and I’ve looked in the docs to find out more about how it works, but it doesn’t have much info on how it actually mails the alert. I’m fairly certain I have my contact defined right:

‘nagios’ contact definition

define contact{
contact_name tom-jones
alias Tom Jones
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email,notify-by-epager
host_notification_commands host-notify-by-email,host-notify-by-epag
er
email tjones@myemail.com

pager pagenagios-admin@localhost.localdomain

    }

Anyway, what doesn’t seem clear to me is "how does it know where to send the email. I don’t see where you define an SMTP server, and I didn’t set one up on my Linux box.

What’s odd here is also that I had two of us in a group. Strangely, it was emailing to my coworker, but not me. I’ve since removed him, cause it was annoying him during my testing. Anyway, it’s still not emailing me.

I checked the log files, but I don’t see anything about this.

I did notice one post that said to check the rights on the /var/mail and see that there isn’t even a “nagios” directory:

[root@localhost etc]# ls -la /var/mail
lrwxrwxrwx 1 root root 10 Oct 13 10:18 /var/mail -> spool/mail

Should there be one?

Any thoughts or directions you could point me to.

Thanks,

Dave


#2

emails are sent directly be the server… you often don’t need to set that up. a DNS server is enough.

Check if the notifications are actually been sent by nagios in the notifications page. If they ARE being sent check in the server logs if you find your email address in some server logs. possibly with an error. if they are not being sent… well then it’s a configuration issue, better check the docs step by step :slight_smile:

Luca


#3

su - nagios and run the exact same command that nagios does to send mail out. What is that you ask? Look in your misccommands.cfg for

‘notify-by-email’ command definition

define command{
command_name notify-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: $DATETIME$\n\nAdditional Info:\n\n$OUTPUT$" | /bin/mail -s " $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

just copy paste the whole thing and change only $CONTACTEMAIL$ to your valid email addy, the rest you can leave it as is, and you should get an email.
If you aren’t getting one, look at
ls -la /var/spool/mail
and the nagios file should be 0 bytes.
if it isn’t 0 bytes then read the nagios mail by :
su - nagios
then type:
mail
and read the mail. Hit ? while in mail if you don’t know who to use the mail command.


#4

Hey guys,

Thanks for the posts.

I do think that the problem is somewhere at my email hosting provider. I think this cause if I send it to another one of my email addresses, it works fine.

This tells me that they’re somehow refusing to forward the email. Not sure if this has something to do with sendmail or not. I can see in the maillog file:

stat=Sent (Message queued)

Contrast that with one that was successful:

stat=Sent (j9VDhmCX006604 Message accepted for delivery)

I really don’t know jack about sendmail, but from what I can find on Google, it tells me that the far end is queuing it for some reason. I plan to contact my email provider and see if they can shed some light on the topic.

Thanks,

Dave


#5

OK, I think I finally got this resolved, and I figured I’d post my findings in case someone else finds it useful:

Basically, I eventually discovered that my email hosting provider had the “reverse-DNS” feature turned on. Because my box did not have a reverse DNS entry in the name server (and I couldn’t put one in), the service provider’s email server was rejecting it. The troublesome thing about this was that there was really no way for me to tell.

Anyway, since I didn’t have access to modify DNS server settings, I discovered another workaround. Here’s what I did:

  1. I modified my sendmail.mc file to use my service provider’s SMTP host. In there, it’s called a SMART_HOST or something like that. This basically tells sendmail to deliver all mail using an SMTP server instead of regular DNS, I guess. Since the service provider’s SMTP server DOES have a reverse-DNS set up, the email server at the other end accepted the email.

  2. Note that after modifying the sendmail.mc file, I had to issue the following command:

m4 /etc/mail/sendmal.mc > /etc/mail/sendmal.cf

  1. Then restart sendmail:

service restart sendmail

And all worked fine!!

So, this turned out to be a problem not so much with NAGIOS, but with sendmail. Anyway, I hope you learn from my mistakes.

Regards,

Dave


#6

a nice example of good troubleshooting work :slight_smile:

Luca