Page 1 of 1

Trouble getting Macro values to Global Event Handler

Posted: Mon Mar 19, 2018 12:15 pm
by jkelly1959
I am trying to take a script I use as a local event handler for host status and make it a global event handler. All works fine as local. When setting up as global the script does kick off but it appears that the hostgroup and hostgroupnames value do not pass through. The script looks for 8 parms/macros to be passed.


My global event hander command looks like:

Code: Select all

/usr/local/nagios/libexec/event_handler_HOSTDOWNtoBEM.sh  "%host%" "%hostaddress%" "%hoststate%" "%hostproblemid%" "%lasthostproblemid%" "%longhostoutput%" "%hostgroup%" "%hostgroupnames%"
I modified xi_host_event_hander to pass the lashostproblemid:

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_event.php --handler-type=host --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --hostdowntime="$HOSTDOWNTIME$"  --hostgroup="$HOSTGROUP$" --lasthostproblemid="$LASTHOSTPROBLEMID$"  --hostgroupnames=”$HOSTGROUPNAMES$”

My Script:

Code: Select all

#!/bin/bash
#$USER1$/event_handler_HOSTDOWNtoBEM.sh  $HOSTNAME$ $HOSTADDRESS$ $HOSTSTATE$ $HOSTPROBLEMID$ $LASTHOSTPROBLEMID$ $LONGHOSTOUTPUT$ $HOSTGROUP$ $HOSTGROUPNAMES$
set -x
DATE=$(date)
CALLMSEND=/home/nagios/msend/bin/msend
echo "The host has changed state at $DATE" > /tmp/hostinfo.txt
echo "The host has changed state at $DATE" > /tmp/parmtest.txt
HOSTNAME=$1
HOSTADDR=$2
HOSTSTATE=$3
HostProbId=$4
HostLastProbId=$5
LongHostOutup=$6
HOSTGROUP=$7
HOSTGROUPNAMES=$8
#SVCDESC=$6
#SVCSTATE=$7
#SVCPROBLEMID=$8
#SVCLastProblemID=$9
#
# Variable population for testing
#
##HOSTADDR="1.2.3.4"
#HostProbId="789123"
#HostLastProbId="789456"
#HOSTSTATE=$1
#HOSTSTATEYPE=$2
#LongHostOutput='This is a test from Nagios hostdown'
#SERVICEDESC="this is a test from Nagios"
#SERVICESTATE="WARNING"
#SERVICESTATETYPE="Set"
# SERVICEPROBLEMID and HOSTPROBLEMID are unique and are by far the best way to
#track issues detected by Nagios
#SERVICEPROBLEMID=12345
SysContact="I have no Clue"

#
if (( echo $HOSTGROUP | grep -q CORE ) || ( echo $HOSTGROUP | grep -q Network )); then
  SysContact="NOC"
fi
if ( echo $HOSTGROUP | grep -q Windows ); then
  SysContact="Windows Server Team"
fi
#if [[ $HOSTGROUP == "windows" ]]; then
#  SysContact="Windows"
#fi
if ( echo $HOSTGROUP | grep -q Linux ); then
  SysContact="Linux Server Team"
fi
if ( echo $HOSTGROUP | grep -q AIX ); then
  SysContact="Unix Systems Administration"
fi
if ( echo $HOSTGROUP | grep -q Facilities ); then
  SysContact="Facilities"
fi
#
echo "HOSTNAME" >> /tmp/parmtest.txt
echo $HOSTNAME >> /tmp/parmtest.txt
echo "HostAddress" >> /tmp/parmtest.txt
echo $HOSTADDR >> /tmp/parmtest.txt
echo "HOSTGROUP" >> /tmp/parmtest.txt
echo $HOSTGROUP >> /tmp/parmtest.txt 
echo "HOSTGROUPNAMES" >> /tmp/parmtest.txt
echo $HOSTGROUPNAMES >> /tmp/parmtest.txt 
echo "hostprobid" >> /tmp/parmtest.txt
echo $HostProbId >> /tmp/parmtest.txt
echo "HostLastProbId" >> /tmp/parmtest.txt
echo $HostLastProbId >> /tmp/parmtest.txt
echo "SysContact" >> /tmp/parmtest.txt
echo $SysContact >> /tmp/parmtest.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 "$HOSTSTATE" in
UP)
#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_msg=$LongHostOutput ; severity=OK; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_HostProbId=$HostProbId;Nagios_HostLastProbId=$HostLastProbId;Nagios_Clearable=CLEAR;Nagios_SysContact=$SysContact;"
echo "UP send to BEM" >> /tmp/parmtest.txt
exit 0
;;
UNREACHABLE)
#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_msg=$LongHostOutput ; severity=WARNING; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_HostProbId=$HostProbId;Nagios_HostTLastProbId=$HostLastProbId;Nagios_Clearable=SET;Nagios_SysContact=$SysContact;"
exit 0
;;
DOWN)
#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_msg=$LongHostOutput ; severity=CRITICAL; Nagios_host=$HOSTNAME; Nagios_address=$HOSTADDR;Nagios_HostProbId=$HostProbId;Nagios_HostLastProbId=$HostLastProbId;Nagios_Clearable=SET;Nagios_SysContact=$SysContact;"
echo "Down send to BEM" >> /tmp/parmtest.txt
exit 0
;;
UNKNOWN)
exit 2
;;
esac
#print "Sent to BEM...\n";
My echos of the values returns:

Code: Select all

HOSTNAME
WindowsTest.cinfin.com
HostAddress
127.0.0.4
HOSTGROUP
$
HOSTGROUPNAMES
%hostgroupnames%
hostprobid
13066
HostLastProbId
13024
SysContact
I have no Clue
Down send to BEM
Have I missed a step somewhere

Re: Trouble getting Macro values to Global Event Handler

Posted: Mon Mar 19, 2018 12:41 pm
by npolovenko
Hi, @jkelly1959.
I couldn't find the $HOSTGROUP$ macro in the official reference. Instead, I've seen $HOSTGROUPNAME$.

As far as $HOSTGROUPNAMES$ which displays:
A comma-separated list of the short names of all the host groups that this host belongs to.
Can you show me the host definition so that I can make sure that it actually belongs to host groups?

Re: Trouble getting Macro values to Global Event Handler

Posted: Mon Mar 19, 2018 3:02 pm
by jkelly1959
Arg....don't I feel silly. Its suppose to be set to $HOSTGROUPNAME$ in the xi handler. changed that and worked like a charm.
Thanks for seeing that. I'd probably been staring at that to long.

We are good to go

Re: Trouble getting Macro values to Global Event Handler

Posted: Mon Mar 19, 2018 3:17 pm
by npolovenko
@jkelly1959, Haha. No worries, I'm glad this was an easy fix.
I'll go ahead and lock this thread.