Page 1 of 1

Event Handler fails to call script

Posted: Tue Sep 14, 2021 5:19 pm
by WillH
I've enabled eventhandlers in nagios.cfg (and restarted)
XI 5.7.2 on RHEL 7

I've created an event handler called UC4-Incident.sh , chown'd to nagios:nagios and chmod'd to 775
The event handler command is defined
/usr/local/nagios/libexec/UC4-Incident.sh $SERVICESTATE$ $SERVICESTATETYPE$ $OUTPUT$

The service has the event handler defined and enabled

Code: Select all

#!/bin/bash
date=$(date)
servicedesc="uc4-batchfile"
SERVICESTATE=$1
SERVICESTATETYPE=$2
#serviceproblemid=$5
log=uclog.txt

$date >> $log
echo $#
echo -------------------------------------------------
echo $3
#incidentdescription=""
echo -------------------------------------------------
incidentdescription=$3
#echo $incidentdescription
echo $incidentdescription >> $log
echo -------------------------------------------------
part1='curl -k --basic -h <an api call I can't put in a public forum :)> '
part2=$incidentdescription
part3='<the end of the api call that dare not speak its name>'
echo -------------------------------------------------
full=$part1$part2$part3
echo $full
if [[ "$SERVICESTATETYPE" == "HARD" && "$SERVICESTATE" == "CRITICAL" ]]; then
#eval $full
echo $date >> $log
echo eval $full >> $log
exit 0
else
echo $date " failed on eval" >> $log
exit 0
fi
Now, if I call the script as nagios from the cli UC4-Incident.sh CRITICAL HARD EXAMPLETEXT (stolen from an actual check) all is well
It write to the log in the script and calls the api it's bult to engage.
If I give it other values like SOFT or OK, it again writes to the log and skips the api call.
However, when the check triggers in Nagios it doens't seem to call the script

looking in the nagios/var/nagios.log
[1631657469] SERVICE NOTIFICATION: nagiosadmin;<hostredacted>;APP-UC4-Log-check;CRITICAL;xi_service_notification_handler;CRITICAL:<output>
[1631657469] SERVICE ALERT: <hostredacted>;APP-UC4-Log-check;CRITICAL;HARD;1;CRITICAL: <output>
[1631657469] GLOBAL SERVICE EVENT HANDLER: <hostredacted>;APP-UC4-Log-check;CRITICAL;HARD;1;xi_service_event_handler
[1631657469] SERVICE EVENT HANDLER: <hostredacted>;APP-UC4-Log-check;CRITICAL;HARD;1;UC4-Batch-Ticket

So it looks like it was called, but I see nothing written to the local log file created by the script the event handler calls.
If I remove $OUTPUT$ from the mix I get the same results. Calling the script by hand, all OK, leaving it up to the event handler, no evidence the script was called.

Re: Event Handler fails to call script

Posted: Wed Sep 15, 2021 1:43 pm
by gsmith
Hi,

Could you try changing:
log=uclog.txt

to:
log=/var/log/uclog.txt

Thanks

Re: Event Handler fails to call script

Posted: Wed Sep 22, 2021 7:49 am
by WillH
@gsmith
No change. Log file is created called manually, but not when the event triggers

Re: Event Handler fails to call script

Posted: Wed Sep 22, 2021 7:49 am
by WillH
@gsmith
No change. Log file is created called manually, but not when the event triggers

Re: Event Handler fails to call script

Posted: Wed Sep 22, 2021 5:03 pm
by benjaminsmith
Hi,
No change. Log file is created called manually, but not when the event triggers
The command and script look okay.

Are you running the script manually as root or the nagios user account? Try logging in as the nagios user, su - nagios, and let us know what results you get. Might still be a path or permissions issue.