LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-07-2011, 11:46 AM   #1
nomolos
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 08-08-2011, 01:38 AM   #2
norbert74
Member
 
Registered: Apr 2006
Posts: 63

Rep: Reputation: 23
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{
	...
	action_url	/path/restartxyz
}
2. The cgi executes the nagios plugin check_nrpe to access nsclient++ on the windows server and passes a command name for this operation:
Code:
...
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.123 -p 5666 -c restartxyz
...
3. nsclient++ on the windows server must be configured in NSC.ini to execute a local script which restarts the service.

Last edited by norbert74; 08-08-2011 at 04:34 AM. Reason: wrong info
 
Old 08-08-2011, 02:40 AM   #3
nomolos
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
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!
 
Old 08-08-2011, 04:44 AM   #4
norbert74
Member
 
Registered: Apr 2006
Posts: 63

Rep: Reputation: 23
Wmic from ZenOSS can only query status info.
You need nsclient++ for operations like restarting services.
Nagios object definitions
nsclient++ with check_nrpe
 
Old 08-08-2011, 01:26 PM   #5
nomolos
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.

Last edited by nomolos; 08-08-2011 at 01:36 PM.
 
Old 08-09-2011, 04:00 AM   #6
norbert74
Member
 
Registered: Apr 2006
Posts: 63

Rep: Reputation: 23
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
This command executed on the nagios machine would trigger nsclient++ on the windows machine to execute the external script restartxyz.

It works only if NSC.ini is configured to recognize restartxyz. It must contain a line like this:
Code:
[External Scripts]
...
restartxyz=java restartservice xyz
Wether it is java, VB, power shell,... does not matter. You need an external script which does the operation you need.
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.
 
Old 08-09-2011, 04:08 AM   #7
nomolos
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-10-2011, 01:46 AM   #8
norbert74
Member
 
Registered: Apr 2006
Posts: 63

Rep: Reputation: 23
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{
	...
        action_url                      /nagios/cgi-bin/restartxyz.php
        }
Write the script /usr/local/nagios/sbin/restartxyz.php
Code:
<?php
$output = shell_exec('/usr/local/nagios/libexec/check_nrpe -H 192.168.1.123 -p 5666 -c restartxyz');
echo "<pre>$output</pre>";
?>
Set permissions
Code:
chmod 775 /usr/local/nagios/sbin/restartxyz.php
chown nagios.nagios /usr/local/nagios/sbin/restartxyz.php
Reload Nagios

There are probably more secure ways of doing this but you get the idea and it should basically work.
 
Old 08-12-2011, 03:37 AM   #9
nomolos
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi Norbert,

That was fantastic. Thank you very much for your help. I'm sure many people would find this page helpful.

-SoLoMoN-
 
Old 08-13-2011, 03:01 AM   #10
norbert74
Member
 
Registered: Apr 2006
Posts: 63

Rep: Reputation: 23
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 :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Nagios service divyashree Linux - Server 7 10-18-2010 07:55 PM
Cron service and oracle service stopped unexpectedly. Can't restart oracle. camron Linux - Newbie 6 06-10-2010 06:00 PM
Configuring Nagios to monitor a Windows service JeremyInNC Linux - Server 3 01-13-2009 09:19 AM
start und stop windows service using nagios cccc Debian 1 03-11-2008 07:43 AM
How do I set the regulatory daemon to restart when I restart the network service? zahadumy Linux - Networking 0 11-05-2006 11:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration