Page 1 of 1

Windows Service Event Handler Not Working

Posted: Thu Feb 18, 2021 1:00 pm
by jimmlegs
Good Day,

I am unable to get a simple service restart event handler working, the components all function separately (I.e., I can call the restart.bat from nrpe as well as execute the "libexec/restart_service.sh CRITICAL HOST spooler" command), however the service check appears to not execute it on failure. I've spent hours looking through the support forum and reviewing the documentation but nothing seems to work.

restart_service.sh perms:
ls -la libexec/restart_service.sh
-rwxr-xr-x. 1 apache nagios 158 Feb 18 10:01 libexec/restart_service.sh

restart_service.sh:
#!/bin/sh
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c restart_service -a "$3"
;;
esac
exit 0

restart_service.bat:
@echo off
net stop %1
net start %1
@exit 0

Relevant nsclient.ini settings:
[/modules]
CheckExternalScripts = enabled
CheckHelpers = enabled
[/settings/NRPE/server]
allow arguments = true
[/settings/external scripts]
allow arguments = true
[/settings/external scripts/scripts]
restart_service=scripts\restart_service.bat "$ARG1$" (I have tried not wrapping $ARG1$ in quotes and get the same results)

Thank you

Re: Windows Service Event Handler Not Working

Posted: Fri Feb 19, 2021 2:26 pm
by vtrac
Hi jimmlegs,
I think the issue that you are passing the "-H" to the "restart_service.sh", which is the argument "$1" and that does not match your "case" condition (please see picture).
F1.png
Remove the "-H" and your event handler should runs through the "case" statement.


Regards,
Vinh

Re: Windows Service Event Handler Not Working

Posted: Mon Feb 22, 2021 2:06 pm
by jimmlegs
That was it! Thank you very much, I was pulling my hair out.

Please close/lock this case

Re: Windows Service Event Handler Not Working

Posted: Mon Feb 22, 2021 3:10 pm
by vtrac
Great!! .... ticket closed/locked!!