Using Event Handler to Restart Windows Services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
knottyau75
Posts: 6
Joined: Wed Nov 13, 2019 11:14 pm

Using Event Handler to Restart Windows Services

Post by knottyau75 »

Hi Guys,
Hoping you can help me with this.

I've followed the Guide to using the event Handler to Restart Windows Services using NCPA

https://assets.nagios.com/downloads/nag ... h-NCPA.pdf

I seem to have all the NCPA Side working, I can use the Command Line on the NagiosXi Box to restart the Services

[root@auqlddcnms1di libexec]# /usr/local/nagios/libexec/restart_service.sh CRITICAL 10.203.3.156 XXXXXXX spooler
The Print Spooler service is stopping.
The Print Spooler service was stopped successfully.

The Print Spooler service is starting.
The Print Spooler service was started successfully.
You have mail in /var/spool/mail/root


I have configured the Command in Core Configurator
Name: Service Restart - Windows
Command: $USER1$/restart_service.sh $SERVICESTATE$ $HOSTADDRESS$ XXXXXXXXX $_SERVICESERVICE$[/i

and have then setup the event handling on a service.

Event handler = Service Restart - Windows
Event handler enabled = on


and have set the Free variables as such

name: _service
Value: OpenDNS

This is the Shortname assigned to the Service I'm trying to restart. The Sevice Goes down, but the Event handler doesnt seem to fire as far as I can see. The service certainly doesnt start again.

Any Ideas what I can do to trouble shoot this one?


Matthew
You do not have the required permissions to view the files attached to this post.
knottyau75
Posts: 6
Joined: Wed Nov 13, 2019 11:14 pm

Re: Using Event Handler to Restart Windows Services

Post by knottyau75 »

Found the Issue, and it was a doozy.


so, it seems that Windows Services now no longer have to have a shortname and so can have spaces in the name etc.
The Batch files in the example only support services that have a Proper Shortname (no spaces)

What I ened up doing is changing the batch files to the Following.

@echo off
@set string=%1
@set string2=%string:.= %
net stop "%string2%"
net start "%string2%"
@exit 0


and then replacing the Spaces with Fullstops in the Service name specified in the Free Variable.


This seemed to have Worked.

[root@auqlddcnms1di libexec]# /usr/local/nagios/libexec/restart_service.sh CRITICAL 10.203.3.156 XXXXXX OpenDNS.Active.Directory.Service
/usr/local/nagios/libexec/check_ncpa.py -H 10.203.3.156 -P 5693 -t XXXXXX -M plugins/restart_svc.cmd -a OpenDNS.Active.Directory.Service
The OpenDNS Connector service is stopping.
The OpenDNS Connector service was stopped successfully.

The OpenDNS Connector service is starting.
The OpenDNS Connector service was started successfully.


Matthew
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Using Event Handler to Restart Windows Services

Post by vtrac »

Great!! ..... Glad you has figured it out.

Locking post/ticket .... :-)
Locked