Here is the raw definition of the service:
Code: Select all
define service {
host_name sabudtrhqttc001.cinf.net
service_description Drive F: Disk Usage
use xiwizard_windowsserver_nsclient_service
check_command check_xi_service_nsclient!B0az!USEDDISKSPACE!-l F -w 80 -c 95!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
event_handler ServiceIssue_Event_Handler
event_handler_enabled 1
notification_interval 60
notification_period xi_timeperiod_24x7
contacts nagiosadmin
_xiwizard windowsserver
register 1Code: Select all
$USER1$/event_handler_SERVICEISSUE.sh $HOSTNAME$ $HOSTADDRESS$ $SERVICESTATE$ $SERVICEPROBLEMID$ $LASTSERVICEPROBLEMID$ $SERVICEDESC$ $LONGSERVICEOUTPUT$ $SERVICEGROUP$ $SERVICEGROUPNAMES$to include extra macros:
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$ Yes/code]
Here is the script:
[code]#!/bin/bash
#$USER1$/event_handler_SERVICEISSUE.sh $HOSTNAME$ $HOSTADDRESS$ $SERVICESTATE$ $SERVICEPROBLEMID$ $LASTSERVICEPROBLEMID$ $SERVICEDESC$ $LONGSERVICEOUTPUT$ $SERVICEGROUP$ $SERVICEGROUPNAMES$
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/Svchandlertest.txt
HOSTNAME=$1
HOSTADDR=$2
ServiceState=$3
ServiceProbId=$4
ServiceLastProbId=$5
ServiceDesc=$6
ServiceOutput=$7
ServiceGroup=$8
ServiceGroupNames=$9
#
# Variable population for testing
#
#HOSTNAME="Johntest.cinfin.com"
#HOSTADDR="1.2.3.4"
#ServiceProbId="789123"
#ServiceLastProbId="789456"
#ServiceState="OK"
#ServiceDesc="URL check"
#ServiceOutput='This is a test from Nagios Serivce Handler'
#SERVICESTATETYPE="Set"
# SERVICEPROBLEMID and HOSTPROBLEMID are unique and are by far the best way to
#track issues detected by Nagios
#SERVICEPROBLEMID=12345
SysContact="Dave.....what are you doing Dave....."
#
#
echo $HOSTNAME >> /tmp/Svchandlertest.txt
echo "HostAddress" >> /tmp/Svchandlertest.txt
echo $HOSTADDR >> /tmp/Svchandlertest.txt
echo "ServiceDescription" >> /tmp/Svchandlertest.txt
echo $ServiceDesc >> /tmp/Svchandlertest.txt
echo "ServiceOutput" >> /tmp/Svchandlertest.txt
echo $ServiceOutput >> /tmp/Svchandlertest.txt
echo "ServiceProlemID" >> /tmp/Svchandlertest.txt
echo $ServiceProbId >> /tmp/Svchandlertest.txt
echo "LastServiceProlemID" >> /tmp/Svchandlertest.txt
echo $ServiceLastProbId >> /tmp/Svchandlertest.txt
echo "ServiceGROUPNAMES" >> /tmp/Svchandlertest.txt
echo $ServiceGROUPNAMES >> /tmp/Svchandlertest.txt
echo "ServiceGroupNames" >> /tmp/Svchandlertest.txt
echo $ServiceGroupNames >> /tmp/Svchandlertest.txt
echo "SysContact" >> /tmp/Svchandlertest.txt
echo $SysContact >> /tmp/Svchandlertest.txt
#
#
# 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
case "$ServiceState" in
OK)
#msend -n @corpnmshqpcf010.cinfin.com:1832#mc -a PATROL_EV -b "msg=$SERVICEDESC ; severity=OK; mc_host=$HOSTNAME; mc_host_address='1.2.3.4';"
$CALLMSEND -n @corpnmshqpcf010.cinfin.com:1832#mc -a Nagios -b "Nagios_service=$ServiceDesc; Nagios_msg=$ServiceOutput; severity=OK; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_SvcProbId=$ServiceProbId;Nagios_SvcLastProbId=$ServiceLastProbId;Nagios_Clearable=CLEAR;Nagios_SysContact=$SysContact;"
echo "OK sent to BEM" >> /tmp/Svchandlertest.txt
exit 0
;;
WARNING)
#msend -n @corpnmshqpcf010.cinfin.com:1832#mc -a PATROL_EV -b "msg=$SERVICEDESC ; severity=WARNING; mc_host=$HOSTNAME; mc_host_address='1.2.3.4';"
$CALLMSEND -n @corpnmshqpcf010.cinfin.com:1832#mc -a Nagios -b "Nagios_service=$ServiceDesc; Nagios_msg=$ServiceOutput; severity=WARNING; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_Nagios_SvcProbId=$ServiceProbId;Nagios_SvcTLastProbId=$ServiceLastProbId;Nagios_Clearable=SET;Nagios_SysContact=$SysContact;"
exit 0
;;
CRITICAL)
#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';"
$CALLMSEND -n @corpnmshqpcf010.cinfin.com:1832#mc -a Nagios -b "Nagios_service=$ServiceDesc; Nagios_msg=$ServiceOutput; severity=CRITICAL; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_SvcProbId=$ServiceProbId;Nagios_SvcLastProbId=$ServiceLastProbId;Nagios_Clearable=SET;Nagios_SysContact=$SysContact;"
echo "Critical Alert send to BEM" >> /tmp/Svchandlertest.txt
exit 0
;;
UNKNOWN)
exit 2
;;
esac
#print "Sent to BEM...\n";
Code: Select all
The Service has changed state at Thu Aug 16 13:00:55 EDT 2018
sabudtrhqttc001.cinf.net
HostAddress
sabudtrhqttc001.cinf.net
ServiceDescription
Drive
ServiceOutput
ServiceProlemID
1145
LastServiceProlemID
1144
ServiceGROUPNAMES
ServiceGroupNames
Usage
SysContact
Dave.....what are you doing Dave.....
Critical Alert send to BEM
I did expect data in the group names macros but it looks like in broke up the description as I mentioned.
Can anyone see what I might have done wrong here? Maybe I have been looking at this too long.
Thanks
JK