Email Notifications

I am having a problem getting Nagios to send email notifications. I am running on Ubuntu 7.04. I am using Nagios 2.10 and sendmail.

I am able to send an email by typing /usr/bin/mail -s “test” [email protected]
After I type this line, the terminal waits for more input. I can press d and I am prompted for Cc:
I then press enter and get the mesage "Null message body; hope that’s ok"
The terminal then waits for more input. I can exit out by typing z
I then get “[4]+ Stopped /usr/bin/mail -s “test” [email protected]

The problem I am having is with nagios sending email. It is timing out after 60 seconds.
I get the following in my log files (edited of course)

[04-16-2008 18:13:56] Warning: Contact ‘bdudley’ host notification command ‘/usr/bin/printf “%b” “Host ‘Motorclub3 - 4796’ is DOWN\nInfo: PING CRITICAL - Packet loss = 100%\nTime: Wed Apr 16 18:12:55 CDT 2008” | /usr/bin/mail -s “PROBLEM alert - Host 4796 is DOWN” [email protected]’ timed out after 60 seconds
Host Notification[04-16-2008 18:12:55] HOST NOTIFICATION: bdudley;4796;DOWN;host-notify-by-epager;PING CRITICAL - Packet loss = 100%

My script for sending the notifications is as follows.
define command{
command_name host-notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios 2.10 *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /usr/bin/mail -s “Host $HOSTSTATE$ alert for $HOSTNAME$!” $CONTACTEMAIL$
}

I know that I am missing something, probably real simple, but I am not sure what. Should there be a command to enter the d and z? I am pretty sure that it is timing out on the parts where /usr/bin/mail was waiting on a terminal input, but I do not know how to fix it. Any suggestions will be appreciated as I have been going over this for 2 days now.

Thanks,

Remove the ! I’ve bolded and underlined in your command (at the end, before $CONTACTEMAIL$:
define command{
command_name host-notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios 2.10 *\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "Host $HOSTSTATE$ alert for $HOSTNAME$!” $CONTACTEMAIL$

If you want to test /usr/bin/mail try it like this:
echo blabla | /usr/bin/mail -s “test” valid_email_address

If you want to test your command just copy/paste it to a terminal but be assured you’ve replaced $CONTACTEMAIL$ with valid_email_address of yours. And of course, remove that !

Thank you fro your quick response. I tried removing the ! from where you indicated and it did not make a difference. I also looked at the other 3 notification commands and the ! was not present in any of them. It must have been accidentally inserted. Thank you for catching that.

I am still stuck with the same timeout message after 60 seconds every time that an event notification is sent from Nagios.
I tested sending email from both mail and mailx using the command:

echo blabla | /usr/bin/mail -s “test” [email protected].

I still have to press z to complete the transaction and send an email.

This got me one step closer, but I am not quite there yet. Any other suggestions that I could try.

Thank you.

You could check /etc/mail.rc
See your options in it. Check if there is a dot option in the set line. If there isn’t, try adding it and reload /etc/mail.rc

You can play with those options until you set it the way it works.
You can see some explanation here:
publib.boulder.ibm.com/infocente … 3/mail.htm
(scroll down and at the end you will see The .mailrc file format. link. Follow it to get mail.rc explanation)

Thank you. The dot just after the blabla and before the | fixed the problem. That is exactly what I was looking for.

Example:

echo blabla**.** | /usr/bin/mail -s “test” valid_email_address

It takes exactly 60 seconds to send the email before it releases the message. Is that normal?

I don’t know exactly what you mean. When you paste the command
echo blabla. | /usr/bin/mail -s “test” valid_email_address
to a terminal and hit enter, does it take 60 seconds for you to get the prompt back or you get the prompt right away and receive the message in your inbox after 60 seconds.
If you get the prompt right away and get the message after 60 seconds, it could be normal, so the email server could process the message. But if the command waits for 60 seconds and sends it after that, there could be a problem. If so, try to type
echo blabla. | /usr/bin/mail -d -s “test” valid_email_address
to see the debug process of sending the message. It won’t really send the message, just fake it to see the process of sending it. If the program hangs for some time on any command check it out on the link I’ve provided and see if there is any solution to that.

It takes 60 seconds to get the prompt back. I am not sure if it sends the message immediately, or if it waits until after it frees up to send the message.

When I run the command with a -d, it goes immediately.

I will check my sendmail for problems that could be causing the delay. I think that is the most likely source.

Thanks for all your help. I will post back with whatever I find.