New Lines in notify-by-email

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
bvinisky
Posts: 34
Joined: Wed Jul 06, 2011 11:28 am

New Lines in notify-by-email

Post by bvinisky »

Hi,

I'm trying to get some extra data at the bottom of a few different email alerts. The data is coming through the $SERVICEOUTPUT$ variable. However, the notify-by-email commands chop off the output when there's a newline returned. Is there any way around this problem?

Thanks,

Bryant
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: New Lines in notify-by-email

Post by jsmurphy »

Is the new line in the $SERVICEOUTPUT$ causing the problem? Or are you manually adding new lines?

Either way as long as you use double quotes around the string then the mail client should understand \n just fine... are you able to post an example of the command from your config?
bvinisky
Posts: 34
Joined: Wed Jul 06, 2011 11:28 am

Re: New Lines in notify-by-email

Post by bvinisky »

It's the newlines returned inside the data held in the $SERVICEOUTPUT$ variable that seem to be causing the problem.

Here's the command:

/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$" | /bin/mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$


$SERVICEOUTPUT$ is captured by the double quotes. The output I get when I run the command directly looks something like this when there's a problem:


App versions running are out of sync. Versions found are testtaker-2.1.0-50007 & testtaker-2.1.0-50097
-------------
App running on app003.prdmir = testtaker-2.1.0-50007
App running on app004.prdmir = testtaker-2.1.0-50007
App running on app005.prdmir = testtaker-2.1.0-50097


When this data is substituted into an email via $SERVICEOUTPUT$. It comes out like this at the bottom of the email:


Additional Info:
App versions running are out of sync. Versions found are testtaker-2.1.0-50007 & testtaker-2.1.0-50097


It's terminating the rest of data when a newline is returned.
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: New Lines in notify-by-email

Post by jsmurphy »

Hmmmm that is weird... I can't see anything explicitly wrong with it and I don't think I've ever seen behaviour like that before :(

All I can suggest is maybe set up a dummy notify-command that writes to a file instead of sending an email and looking for unusual white space or line break characters that don't appear with one of your checks that does work. I would be interested to hear if you find out what's causing it.
bvinisky
Posts: 34
Joined: Wed Jul 06, 2011 11:28 am

Re: New Lines in notify-by-email

Post by bvinisky »

I finally had some time to dig into this a little bit further. Passing the output to a text file produced the same result. $SERVICEOUTPUT$ ended up being the problem. This macro is designed to only allow one line of output and terminates any output after a new line is issued. $LONGSERVICEOUTPUT$ needed to be included in the notify-by-email-command to pass through the additional lines.

http://nagios.sourceforge.net/docs/3_0/macrolist.html

- Bryant
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: New Lines in notify-by-email

Post by jsmurphy »

hmmm well there you go, I've learned something for the day. Thanks for the follow up!
Locked