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
New Lines in notify-by-email
Re: New Lines in notify-by-email
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?
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?
Re: New Lines in notify-by-email
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.
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.
Re: New Lines in notify-by-email
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.
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.
Re: New Lines in notify-by-email
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
http://nagios.sourceforge.net/docs/3_0/macrolist.html
- Bryant
Re: New Lines in notify-by-email
hmmm well there you go, I've learned something for the day. Thanks for the follow up!