Page 1 of 1

PROCESS_SERVICE_CHECK_RESULT use

Posted: Thu Jul 12, 2018 3:06 pm
by SteveBeauchemin
I would like to use the Nagios Pipe to submit a test result.
The Message portion of the submission has multiple lines and may use the semi-colon character.

My code uses this syntax:

Code: Select all

#Create the completed syntax that will go to the Nagios Pipe
my $result = "PROCESS_SERVICE_CHECK_RESULT;$srce;$service;$state;$message\n";
where

Code: Select all

$srce = "hostname.domain.com";
$service= "service_name";
$State = "2";
$message = "Message Text: MSGTXT: PR1X TWS - #J12345(AB_CDEFGHI_DATA) has abended
POC: POC48
Contact: Someone Somewhere; Someone Else; Maybe Thirdperson
Instructions: email [email protected]; [email protected]; [email protected] 
Help text: A job has entered the ABEND state following the automatic recovery actions for the job. Contact the 
schedule's owner to determine the appropriate action. Cancelling the abended job will permit other dependent 
jobs and schedules to proceed.  Rerunning an abended job will also work if the job finished successfully. The 
operator action for this event will execute a conman rerun command on the job.";

This is a sample of what I would like to send to the Nagios pipe. I would like the Nagios status in the display to be usable.

PROCESS_SERVICE_CHECK_RESULT;hostname.domain.com;service_name;2;Message Text: MSGTXT: PR1X TWS - #J12345(AB_CDEFGHI_DATA) has abended
POC: POC48
Contact: Someone Somewhere; Someone Else; Maybe Thirdperson
Instructions: email [email protected]; [email protected]; [email protected]
Help text: A job has entered the ABEND state following the automatic recovery actions for the job. Contact the
schedule's owner to determine the appropriate action. Cancelling the abended job will permit other dependent
jobs and schedules to proceed. Rerunning an abended job will also work if the job finished successfully. The
operator action for this event will execute a conman rerun command on the job.

The test is getting data from a log file, and also uses a csv file to look up and populate additional data. The csv file has 11,175 lines and the possibilities are too many to make a service for each. The log triggers an event multiple times a day.

I just need to get the test results into the Nagios Status information column and have the correct line breaks. It needs to be readable to the folks in our Data Center.

Ultimately, I need to pass all this data to a Ticketing System. Once the Nagios alert triggers, the communication to ticketing happens.

Any ideas?

Thanks

Steve B

P.S. I bet you are glad this is not a 5.5 upgrade issue...

Re: PROCESS_SERVICE_CHECK_RESULT use

Posted: Thu Jul 12, 2018 3:31 pm
by scottwilkerson
Like this?

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the PROCESS_SERVICE_CHECK_RESULT command
# to Nagios.  Adjust variables to fit your environment as necessary.

srce="hostname.domain.com";
service="service_name";
State="2";
message="Message Text: MSGTXT: PR1X TWS - #J12345(AB_CDEFGHI_DATA) has abended
POC: POC48
Contact: Someone Somewhere; Someone Else; Maybe Thirdperson
Instructions: email [email protected]; [email protected]; [email protected]
Help text: A job has entered the ABEND state following the automatic recovery actions for the job. Contact the
schedule's owner to determine the appropriate action. Cancelling the abended job will permit other dependent
jobs and schedules to proceed.  Rerunning an abended job will also work if the job finished successfully. The
operator action for this event will execute a conman rerun command on the job.";

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

`which printf` "[%lu] PROCESS_SERVICE_CHECK_RESULT;$srce;$service;$state;$message\n" $now > $commandfile

Re: PROCESS_SERVICE_CHECK_RESULT use

Posted: Thu Jul 12, 2018 4:12 pm
by SteveBeauchemin
Yes,

Like that.

I have 21 different scripts doing that (just counted them) and they work fine, as long as the $message is just a short one line text.

When $message is multiple lines and contains blank lines, semi-colons, and lots of data, many times I get partial data in the Nagios Status information. I would like to see the entire thing in there. Is there a character limit in the Status information field?

Should I use <BR> or \n and get it all on one line in the $message variable before I push it to the pipe? When I use \n the \n shows up in the text but does not format on screen properly. Is <BR> my only solution? If I use <BR> then the data sent to the ticketing system will have <BR> in the JSON dump.

Steve B

Re: PROCESS_SERVICE_CHECK_RESULT use

Posted: Thu Jul 12, 2018 4:18 pm
by scottwilkerson
I see the issue, ya I think a <br> is the best bet

Re: PROCESS_SERVICE_CHECK_RESULT use

Posted: Fri Jul 13, 2018 12:32 pm
by SteveBeauchemin
Thanks Scott.

I just wasn't sure where and why I was losing informational text.

I have the items going in to Nagios using the <BR> now. And in the code sending the alert to the Ticketing system I just search and replace the <BR> with \n and it looks good there. So now I am good in both places.
in perl...
$SERVICESTATUSTEXT =~ s/<BR>/\n/g;

This can be closed if you like.

Thanks,

Steve B

Re: PROCESS_SERVICE_CHECK_RESULT use

Posted: Fri Jul 13, 2018 12:45 pm
by jomann
Great, closing this up.