Sending multiple lines to passive check
Posted: Mon Oct 05, 2015 1:27 pm
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.
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.
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"