Event Handler fails to call script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
WillH
Posts: 54
Joined: Mon Aug 03, 2020 10:37 am

Event Handler fails to call script

Post 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.
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Event Handler fails to call script

Post by gsmith »

Hi,

Could you try changing:
log=uclog.txt

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

Thanks
WillH
Posts: 54
Joined: Mon Aug 03, 2020 10:37 am

Re: Event Handler fails to call script

Post by WillH »

@gsmith
No change. Log file is created called manually, but not when the event triggers
WillH
Posts: 54
Joined: Mon Aug 03, 2020 10:37 am

Re: Event Handler fails to call script

Post by WillH »

@gsmith
No change. Log file is created called manually, but not when the event triggers
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Event Handler fails to call script

Post 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.
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