Windows Service Event Handler Not Working

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
jimmlegs
Posts: 49
Joined: Thu Jun 20, 2013 11:50 am

Windows Service Event Handler Not Working

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Windows Service Event Handler Not Working

Post 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
You do not have the required permissions to view the files attached to this post.
jimmlegs
Posts: 49
Joined: Thu Jun 20, 2013 11:50 am

Re: Windows Service Event Handler Not Working

Post by jimmlegs »

That was it! Thank you very much, I was pulling my hair out.

Please close/lock this case
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Windows Service Event Handler Not Working

Post by vtrac »

Great!! .... ticket closed/locked!!
Locked