Piping Notification Command to Sed?

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
mmartin
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Piping Notification Command to Sed?

Post by mmartin »

Hello All,

I created a script that builds a String to echo to the "send_nsca" command to send a Passive Check to Nagios using NSCA Plugin.
In the Message String I send to Nagios I added a couple HTML Tags like <b> and <i> for certain circumstances to make it standout from the rest of the
Services listed on the "Services Page" in a browser.

This works just fine, but when I get the email notification for this Service I can see that the <b> and <i> tags are getting the "<" & ">" angled
brackets removed and it is printing a lonely "i" and/or "b"... I'm assuming the angled-brackets are being removed because they are in the "illegal characters" in
the "nagios.cfg" Config File.

But anyway, this can get confusing for someone who doesn't know why they are there. So I was trying to pipe a "sed" command to the Notification Command "notify-by-email-test".
Which is a test command I setup to try and pipe it to sed. The test Notification Command is the exact same thing as the "notify-by-email Command except that I added the sed command
to the end of the "command_line" Line.

For Example: *Here is my test Notification Command. I simply added "i" to be removed and replaced Globally with nothing.

Code: Select all

define command{
	command_name	notify-by-email
	command_line	/usr/bin/printf "%b" "***** Nagios 3.2.3 *****\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$ | sed 's/i//g'
}

So I guess it would be helpful to know, WHEN does Nagios replace the "Macros" (i.e. the Variables) with their actual values...?
If anyone has ANY suggestions please feel free to reply.


Thoughts:
Just thought of something right before submitting this post... I should probably pipe the printf to sed then pipe that to mail...?
So it would basically look something like this:
/usr/bin/printf "message_string" | sed '/search/replace/' | /bin/mail -s "subject" contactAddress
I will try it this way and post back with my results...



Thanks in Advance,
Matt
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Piping Notification Command to Sed?

Post by sreinhardt »

I believe your logic of "printf | sed | mail" should work. Having sed after probably would not do much if anything as once mail has the input I doubt its being returned to std out for sed. Please let us know how that works!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
mmartin
Posts: 45
Joined: Fri Jul 15, 2011 12:45 pm

Re: Piping Notification Command to Sed?

Post by mmartin »

Hey sreinhardt, thanks for your reply!

Yup... I think that will do the trick.
I ran the command manually from the command line and it did remove whatever was in the sed command.
i.e. --> "echo 'This is the email body' | sed 's/h/H/g' | mail "This is the Subject" emailAddress@email.com"

Email Body --> "THis is tHe email body"

And just now as I am posting, I got the Notification from Nagios with the 'sed' command doing what it should...!!

Thanks Again for Your Reply!

Thanks,
Matt
Locked