Restart Service on Windows using Event Handlers

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Restart Service on Windows using Event Handlers

Post by Sampath.Basireddy »

Hello There,

I am trying to configure event handler to auto start/restart Service on Windows Servers with NCPA.

I do have link for "how to restart a Windows service via NRPE and NSClient++". Is there any similar documentation for NCPA as well?

Thank You
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Restart Service on Windows using Event Handlers

Post by gormank »

Off topic but my first defense would be to tell the service to restart itself twice before dying. Example for nsclient:

sc failure nscp reset= 86400 actions= restart/120000/restart/120000/none/120000
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Re: Restart Service on Windows using Event Handlers

Post by Sampath.Basireddy »

That is already in place. My requirement is kind of different. I want to configure event handlers on NCPA.

Starting of Service when it goes down is not my exact requirement, but for other reasons where any application has a dependency of a service and it might need a service restart.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Restart Service on Windows using Event Handlers

Post by scottwilkerson »

Here is a document outlining the procedure

https://support.nagios.com/kb/article/n ... -nrpe.html
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Re: Restart Service on Windows using Event Handlers

Post by Sampath.Basireddy »

That link has instructions for NRPE and NSClient++. Is there a similar document for NCPA?
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Restart Service on Windows using Event Handlers

Post by mcapra »

Refer to the documentation for the NCPA plugins endpoint:
https://www.nagios.org/ncpa/help/2.0/ap ... es-plugins

Basically, you store the script (such as one that restarts a service) in the plugin_path and call it via the plugins endpoint:

Code: Select all

https://my.host.com:5693/api/plugins/<plugin name>/<arg1>/<arg2>/?token=mytoken
Or as a check_ncpa command:

Code: Select all

check_ncpa.py -H my.host.com -t mytoken -M 'plugins/restart_service.bat'
Former Nagios employee
https://www.mcapra.com/
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Restart Service on Windows using Event Handlers

Post by scottwilkerson »

Thanks @mcapra this is exactly how to do it.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Re: Restart Service on Windows using Event Handlers

Post by Sampath.Basireddy »

Perfect. Thank You @mcapra

I created a command like below and selected it as Event handler and it worked..

Code: Select all

$USER1$/check_ncpa.py -H $HOSTADDRESS$ -t <String> -M 'plugins/restart_service.bat'
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Restart Service on Windows using Event Handlers

Post by scottwilkerson »

Excellent! Going to Lock this thread
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked