Sending multiple lines to passive check

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
stonefury
Posts: 4
Joined: Mon Sep 21, 2015 6:39 pm

Sending multiple lines to passive check

Post 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"
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Sending multiple lines to passive check

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
stonefury
Posts: 4
Joined: Mon Sep 21, 2015 6:39 pm

Re: Sending multiple lines to passive check

Post 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
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Sending multiple lines to passive check

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Sending multiple lines to passive check

Post by hsmith »

Thanks, Eric.

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

Thanks!
Former Nagios Employee.
me.
Locked