Nagios Restart Windows Service on Demand
I've recently implemented Nagios for our organization and have successfully implemented it accordingly.
We'd like to further enhance Nagios functionality to be able to restart the windows service on demand. Basically, if we make a judgement call that the service needs to be restarted, we want to do so via Nagios instead of remote desktop into the server. The existing Nagios Event Handler is able to restart the service on failure. This is not feasible for us as the service does not fail, but the processing behind it is actually failing. This is something Nagios is not able to monitor. Hope I can get some input through you guys. Thanks in advance. |
If you want to restart the windows service manually you could use an action_url in the nagios service which points to a cgi.
This cgi executes the nagios plugin check_nrpe to contact nsclient++ on the windows server. nsclient++ executes a local script (VB, Java, power shell,...) which restarts the service. 1. Create a link in nagios for the corresponding service or host with action_url that points to a cgi: Code:
define service{ Code:
... |
Hi Norbert,
Thank you for your feedback. Do you happen to know where I can get more resources pertaining this? Or in fact the best guide. Cheers! |
Wmic from ZenOSS can only query status info.
You need nsclient++ for operations like restarting services. Nagios object definitions nsclient++ with check_nrpe |
Hi Norbert,
I've attempted the instructions that you gave. When i clicked on the URL it directed me to http://NAGIOSIP/scripts/test.bat (my input in action_url is scripts/test.bat). I've also configured my NSC.ini to recognize test.bat using the command nrpe_test (nrpe_test=scripts/test.bat). Can you advise me where am I doing it wrong. Additional Note: - NRPE has been tested and is functional - My configuration for Nagios is via NagiosQL Thank you in advance. |
Hi nomolos,
NSC.ini does not recognize test.bat. There is one step missing: NSC.ini must recognize the command which you pass when you execute the check_nrpe command (what comes after -c, see below). Please make sure first that the communication between check_nrpe (nagios server) and nsclient++ (windows server) works. Open a shell on the nagios server and execute a command, something similar to this: Code:
/usr/local/nagios/libexec/check_nrpe -H [IP windows server] -p [port nsclient++] -c restartxyz It works only if NSC.ini is configured to recognize restartxyz. It must contain a line like this: Code:
[External Scripts] In this case it is a java class called restartservice which needs one parameter. (Of course you must make sure that the windows service for nslient++ is actually running and that it has enough permissions to execute the desired operation.) If you can't get this running I would recommend to work through this page: http://www.nsclient.org/nscp/wiki/gu...ios/check_proc As soon as you can restart the service from the nagios server with the check_nrpe command from the shell you can integrate it into the nagios web interface. Write a cgi which executes the check_nrpe command and use the url in the action_url directive. |
Hi Norbert,
Thanks for sticking up with my hassle. I've configured Nagios to work with nrpe. The test that you mention was successful. The area that I fail to implement is the cgi writing. I'm not sure how to implement the command to the web interface. I tried scouting for leads on web sites but it's just a little tricky for my understanding. Can you provide me a basic CGI sample to call the command. Thank you in advance. |
The most simple way I can think of is like this:
Add the action_url in the desired service definition in the Nagios configuration Code:
define service{ Code:
<?php Code:
chmod 775 /usr/local/nagios/sbin/restartxyz.php There are probably more secure ways of doing this but you get the idea and it should basically work. |
Hi Norbert,
That was fantastic. Thank you very much for your help. I'm sure many people would find this page helpful. -SoLoMoN- |
Yes, the external scripts feature of nsclient++ is really great.
With it you can do just everything with a windows box from Nagios. I like this very much too :-) |
All times are GMT -5. The time now is 11:50 PM. |