Page 1 of 1
Need help on restarting multiple windows services
Posted: Mon Jul 02, 2018 7:02 am
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 ?
Re: Need help on restarting multiple windows services
Posted: Mon Jul 02, 2018 1:00 pm
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.
Re: Need help on restarting multiple windows services
Posted: Tue Jul 03, 2018 6:08 am
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 ?
Re: Need help on restarting multiple windows services
Posted: Tue Jul 03, 2018 9:02 am
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!
Re: Need help on restarting multiple windows services
Posted: Tue Jul 03, 2018 12:34 pm
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.
Re: Need help on restarting multiple windows services
Posted: Tue Jul 03, 2018 2:58 pm
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.