Trying to get SERVICENOTES into event handler

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
jkelly1959
Posts: 49
Joined: Tue Jun 06, 2017 10:59 am

Trying to get SERVICENOTES into event handler

Post by jkelly1959 »

We are trying to Flapping info in our service handler. We have attempted to use $ServiceNotes$ macro to capture that data. I setup the command and modified the xi_service_event_handler to include service notes. I am testing with a server where the service is considered to be flapping and the indicator is in what we think is servicenotes(at least thats the label). When I force state change the handler fires but ServiceNotes as we have set it up shows blank in my echo's to the log I create. I have included the associated pieces including my small log. I went through the macro doc and it seems ServiceNotes are ok with the service handlers. Looking for a different set of eyes to review. Right now Im only worried about the field being popbulated. Thanks John

xi_service_event_handler code:

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_event.php --handler-type=service --host="$HOSTNAME$" --service="$SERVICEDESC$" --hostaddress="$HOSTADDRESS$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --servicestate=$SERVICESTATE$ --servicestateid=$SERVICESTATEID$ --lastservicestate=$LASTSERVICESTATE$ --lastservicestateid=$LASTSERVICESTATEID$ --servicestatetype=$SERVICESTATETYPE$ --currentattempt=$SERVICEATTEMPT$ --maxattempts=$MAXSERVICEATTEMPTS$ --serviceeventid=$SERVICEEVENTID$ --serviceproblemid=$SERVICEPROBLEMID$ --serviceoutput="$SERVICEOUTPUT$" --longserviceoutput="$LONGSERVICEOUTPUT$" --servicedowntime=$SERVICEDOWNTIME$ --lastserviceproblemid=$LASTSERVICEPROBLEMID$ --servicegroupname=$SERVICEGROUPNAME$ --servicegroupnames=$SERVICEGROUPNAMES$ --servicenotes=$SERVICENOTES$
Command "ServiceIssue_Flapping_Handler_Nagios " code:

Code: Select all

$USER1$/event_handler_flapping.sh "$HOSTNAME$" "$HOSTADDRESS$" "$SERVICESTATE$" "$SERVICEPROBLEMID$" "$LASTSERVICEPROBLEMID$" "$SERVICEDESC$" "$SERVICENOTES$" "$SERVICEGROUPNAMES$" "$SERVICESTATETYPE$"
Sevice Handler script:

Code: Select all

#!/bin/bash
#$USER1$/event_handler_HOSTDOWNtoBEM.sh  $HOSTNAME$ $HOSTADDRESS$ $SERVICESTATE$ $SERVICEPROBLEMID$ $LASTSERVICEPROBLEMID$ $SERVICEDESC$  $SERVICENOTES$ $SERVICEGROUPNAMES$ $SERVICESTATETYPE$
#set -x

DATE=$(date)
CALLMSEND=/home/nagios/msend/bin/msend
#echo "The host has changed state at $DATE" > /tmp/hostinfo.txt
echo "The Service has changed state at $DATE" > /tmp/Flappingtest.txt
HOSTNAME=$1
HOSTADDR=$2
ServiceState=$3
ServiceProbId=$4
ServiceLastProbId=$5
ServiceDesc=$6
#ServiceOutput=$7
#ServiceGroup=$8
ServiceGroupNames=$8
ServiceStateType=$9
ServiceNotes=$7
#ServiceNotes="Service is flapping"
#
# 
#
SysContact="Dave.....what are you doing Dave....."
Category="Test"
#
#
echo $HOSTNAME >> /tmp/Flappingtest.txt
echo "HostAddress" >> /tmp/Flappingtest.txt
echo $HOSTADDR >> /tmp/Flappingtest.txt 
echo "ServiceDescription" >> /tmp/Flappingtest.txt
echo $ServiceDesc >> /tmp/Flappingtest.txt 
echo "SERVICENOTES" >> /tmp/Flappingtest.txt
echo $ServiceNotes >> /tmp/Flappingtest.txt 
echo "ServiceProlemID" >> /tmp/Flappingtest.txt
echo $ServiceProbId >> /tmp/Flappingtest.txt
echo "LastServiceProlemID" >> /tmp/Flappingtest.txt
echo $ServiceLastProbId >> /tmp/Flappingtest.txt
echo "ServiceGroupNames" >> /tmp/Flappingtest.txt
echo $ServiceGroupNames >> /tmp/Flappingtest.txt 
echo "SysContact" >> /tmp/Flappingtest.txt
echo $SysContact >> /tmp/Flappingtest.txt
echo "ServiceState" >> /tmp/Flappingtest.txt
echo $ServiceState >> /tmp/Flappingtest.txt
echo "ServiceStateType" >> /tmp/Flappingtest.txt
echo $ServiceStateType >> /tmp/Flappingtest.txt
#
echo "$DATE,$HOSTNAME,$ServiceState,$ServiceStateType,$ServiceProbId,$ServiceLastProbId,$ServiceDesc,$ServiceNotes" >> /tmp/Flappinghandle.log
#
# The message below is a mock up. You will need to edit the format to one
#acceptable to your ticketing system
#if [[ "$HOSTSTATETYPE" == "Set" && "$SERVICESTATE" == "DOWN" ]]; then
#msend -n @corpnmshqpcf010.cinfin.com:1832#mc -a  PATROL_EV -b "msg=$SERVICEDESC ; severity=CRITICAL; mc_host=$HOSTNAME; mc_host_address='1.2.3.4';" 
#exit 0
#else
#exit 0
#fi
#
# The message handels FLAPPING
#acceptable to your ticketing system
if [[ "$ServiceNotes" = *Service is flapping* ]]; then
 $ServiceOutput = "Service is Flapping"
$CALLMSEND -n @corpnmshqpcf010.cinfin.com:1831#mc -a  Nagios -b "Nagios_service=$ServiceDesc; Nagios_msg=$ServiceNotes; severity=CRITICAL; Nagios_Category=$Category; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_SvcProbId=$ServiceProbId;Nagios_SvcLastProbId=$ServiceLastProbId;Nagios_Clearable=SET;Nagios_SysContact=$SysContact;"
 echo "FLAPPING Alert send to BEM" >> /tmp/Flappinghandle.log
else
 echo "NO Flapping found" >> /tmp/Flappinghandle.log
fi
#
#print "Sent to BEM...\n";
Log output:

Code: Select all

The Service has changed state at Wed Apr  1 11:08:06 EDT 2020
AIXTESTLOCALHOST.CINFIN.COM
HostAddress
1.2.3.4
ServiceDescription
Current Load
SERVICENOTES

ServiceProlemID
4646337
LastServiceProlemID
4646229
ServiceGroupNames

SysContact
Dave.....what are you doing Dave.....
ServiceState
OK
ServiceStateType
HARD
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: Trying to get SERVICENOTES into event handler

Post by mbellerue »

Here are some things I would look at.

xi_service_event_handler code:
I would try wrapping this --servicenotes=$SERVICENOTES$ in double quotes, just in case spaces are throwing it off.

Service Handler Script:
Is this right? if [[ "$ServiceNotes" = *Service is flapping* ]]; then
Or should it be this? if [[ "$ServiceNotes" == "Service is flapping" ]]; then

And also, you can enable logging of event handlers if you go to Configure -> Core Config Manager -> Core Configs. In the nagios.cfg file, there should be an entry for log_event_handlers, probably set to 0. Set it to 1, and then it should log to /usr/local/nagios/var/nagios.log.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked