Newlines are broken in Email notification


#1

We’re running Nagios on Fedora Core, and the notification emails are not composing newlines correctly. The emails look like this:

***** Nagios 2.6 *****nnNotification Type: PROBLEMnnService: : 1nAddress: nState: CRITICALnnDate/Time: Tue Dec 11 10:08:03 CST 2007nnAdditional Info:nn.

It looks like something isn’t parsing the “\n” characters correctly. I’d be looking at Sendmail, but other notifications from the box work fine.


#2

You should check your printf command syntax (man printf) and change the notify-by-email command syntax in Nagios for your version of printf. Nagios prints e-mail thorugh printf and pipes it to mail command. You can see that in commands.cfg file in your /etc/nagios/ folder. Be sure you have %b argument in that command. It should be in “double quotes”. Like this:

‘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$\nState: $SERVICESTATE$ for $SERVICEDURATION$\nAddress: $HOSTADDRESS$\n\nInfo:\n\n$SERVICEOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\nACK by: $SERVICEACKAUTHOR$\nComment: $SERVICEACKCOMMENT$\n" | /usr/bin/mail -s " $NOTIFICATIONTYPE$ alert $NOTIFICATIONNUMBER$ - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

You could also check the nagios.log for some errors maybe.


#3

Albin,

Thanks for the reply. The commands are formatted correctly, and I don’t see anything in this version of printf that would cause the trouble. Sending the commands to stdout formats correctly.

I guess the problem must be something either sendmail or the exchange relay is doing?


#4

Hm, hm… I think it’s in the printf format, because /usr/bin/mail just sends already formatted message to e-mail address specified. Sendmail and exchange don’t format mails. Is the mail subject formatted correctly when you get email?

If I put the command (in shell) like this (with qoutes ending before any \n and starting after \n):
/usr/bin/printf “%b” “***** Nagios ***"\n\n"Notification Type: $NOTIFICATIONTYPE$"\n\n"Service: $SERVICEDESC$"\n"Host: $HOSTALIAS$"\n"State: $SERVICESTATE$ for $SERVICEDURATION$"\n"Address: $HOSTADDRESS$"\n\n"Info:"\n\n"$SERVICEOUTPUT$"\n\n"Date/Time: $LONGDATETIME$"\n\n"ACK by: $SERVICEACKAUTHOR$"\n"Comment: $SERVICEACKCOMMENT$"\n | /usr/bin/mail -s " $NOTIFICATIONTYPE$ alert $NOTIFICATIONNUMBER$ - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$

I get mail in this format:
***** Nagios *****nnNotification Type: $nnService: $nHost: $nState: $ for $nAddress: $nnInfo:nn$nnDate/Time: $nnACK by: $nComment: $n
which is very similar to yours. Those $ and $nHost: etc. are such because I’ve just c/p-ed the command from commands.cfg to the shell, modifying just mail address at the end.

Be sure you have correctly written the command like the one I c/p-ed in the earlier post (with doubleqoutes just in front of the message and at the end).

Can you post your notify-by-email command definition from commands.cfg?


#5

Sure, I didn’t figure Sendmail would affect things, but I don’t know anythign about Exchange. Everything in nagios looks ok to me, but I’m probably missing something.

Thanks for taking a look.

‘notify-by-email’ command definition

define command{
command_name notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios 2.6 ***\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s " $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$


#6

Dude, this is weird. :slight_smile: Especially, if you say when you copy these commands to the shell and they send a normal mail (try every combination of this to make yourself sure commands are fine).
To me, it sends a normal mail when I copy this commands which you’ve posted to the sheel changing only mail recipient at the end. Same situation with the Nagios running these commands.

Some of my colleagues get emails through Exchange and everything works fine.

Probably something is defined wrong on your Nagios machine.