Page 1 of 1

Sending multiple lines to passive check

Posted: Mon Oct 05, 2015 1:27 pm
by stonefury
I'm attempting to use a python script to write to nagios.cmd to process my passive check data.

It works, but I can't figure out how to send multiple lines. Adding newlines or escaping them doesn't work.

Can someone show me how to write multiple lines? We can take a step back and just use the shell example.
:geek:

Code: Select all

#!/bin/sh
 
	# Write a command to the Nagios command file to cause
	# it to process a service check result
 
	echocmd="/bin/echo"
 
	CommandFile="/usr/local/nagios/var/rw/nagios.cmd"
 
	# get the current date/time in seconds since UNIX epoch
	datetime=`date +%s`
 
	# create the command line to add to the command file
	cmdline="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$1;$2;$3;$4"
 
	# append the command to the end of the command file
	echo "$echocmd $cmdline >> $CommandFile"

Re: Sending multiple lines to passive check

Posted: Mon Oct 05, 2015 2:13 pm
by eloyd
What do you mean by "write multiple lines?" Unix command pipes read one line at a time, so writing multiple lines to the command file will not do what I think you think it will.

Re: Sending multiple lines to passive check

Posted: Mon Oct 05, 2015 3:26 pm
by stonefury
Tnx for such a quick reply. I appreciate it!

Writing multiple lines, as in, nagios reads the first line as it's title, and other lines after that are put into the body of the alert.

The passive check works, I get my title, such as OK, or FAILED, but I wanted to provide some information about the failure if there is one, like I would do for an active check.

It can't be done?

Thanks again. cheers

Re: Sending multiple lines to passive check

Posted: Tue Oct 06, 2015 9:18 am
by eloyd
It does not work that way. You would need to send everything as a single line of performance data that Nagios will display on the screen. Passive checks are just like active checks except that Nagios has no control over when passive checks are run, so they must follow the same nagios.cmd file protocol.

Look at https://assets.nagios.com/downloads/nag ... mands.html for more information.

Re: Sending multiple lines to passive check

Posted: Tue Oct 06, 2015 1:43 pm
by hsmith
Thanks, Eric.

@stonefury, let us know if we can help you with anything else.

Thanks!