Need help on restarting multiple windows services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Need help on restarting multiple windows services

Post by bsivavani »

Hi,

We are planning to restart 2 windows services using single Nagios service.

We are currently able to restart single service using below link

https://assets.nagios.com/downloads/nag ... 1496420094

Now, we are facing an issue to restart multiple services using single Nagios service.

We tried with below service and we have added both services under Misc Settings, but still we are not able to restart both the services.
/usr/local/nagios/libexec/check_nt -H XXXXX -t 120 -s XXXXX -p 12489 -v SERVICESTATE -l 'chef-client','WinRM' 

Could you please suggest on how to restart multiple services using the same Nagios service ?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Need help on restarting multiple windows services

Post by lmiltchev »

You could set up your restart_service.bat file as something like this:

Code: Select all

@echo off
net stop %1
net start %1 
net stop %2
net start %2
@exit 0
Next, define a command in the nsclient.ini file as such:

Code: Select all

restart_service = scripts\restart_service.bat "$ARG1$" "$ARG2$"
Restart the nsclinet++ service on the Windows machine, and test your check from the command line on the Nagios XI server.

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <ip address> -c restart_service -a <service 1> <service 2>
Example:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c restart_service -a spooler ncpalistener
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.


The NCPA Listener - ncpalistener service was stopped successfully.

The NCPA Listener - ncpalistener service is starting.
The NCPA Listener - ncpalistener service was started successfully.
Be sure to check out our Knowledgebase for helpful articles and solutions!
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Re: Need help on restarting multiple windows services

Post by bsivavani »

Thanks for the hint, but this method will restart both the services even one service is down.

Is there any way to restart only particular service ?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Need help on restarting multiple windows services

Post by lmiltchev »

This is correct. If you wanted to restart only one service (the one that is currently down), you have two options the way I see it:

1. Monitor the two services separately (create two separate checks).

2. Create a custom (e.g. Powershell) script on the Windows machine, which would take a list of services, check the status of each one, then restart the services that are down. You could call this PS script via NSClient++ or NCPA.

Note: The second option falls in the scope of custom development, and it is out of the realm of Nagios support. Option 1 is a lot easier to implement. Thank you!
Be sure to check out our Knowledgebase for helpful articles and solutions!
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Re: Need help on restarting multiple windows services

Post by bsivavani »

We can go with first option, but I have 600 servers we need to add couple of services for all servers, this might increase the load on XI server.

We are planning to go with second option, Any idea on how to pass two service variables from Nagios to Powershell script ?

I know we can pass single service using _SERVICE Macro defined under Misc settings.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Need help on restarting multiple windows services

Post by scottwilkerson »

you would need to pass then as the comma separated list, and then have powershell break them into an array and act on each element.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked