Service on windows controlled by nagios

Hello people,

I have a service on windows and it’s monitored by nagios.
At this phase no problem, the other problem it’s the service is started and the files dosen’t pass after restart the files goes through.
I wondering if the services could be control if they could not contact the other part could nagios make a restart automatically to the service ?

Thanks in advanced.

If I understand correctly you are asking if you can have Nagios automatically restart a service when it detects it is down? Yes, this is called an Event Handler. It is basically a script (perl, VB, batch file, etc.) that you create and tell Nagios to execute in response to a specific event.

This is the documentation page regarding setting up event handlers, I think it would be the best place to start.

nagios.sourceforge.net/docs/3_0/ … dlers.html

A warning though, Event handlers aren’t a substitute for notifications or good administration, someone should always check when a service goes down. The reason for this is because if the service goes down for some other reason the handler can restart it but that won’t fix the problem, so it will just crash again. Sometimes restarting over and over can actually make things worse, so use care when setting them up.

Hi,

Here’s a VB Script plugin I use to do just that. Unfortunately you will need to load a NRPE Agent on each Server you want to use it on, as it is written to execute on the server it is located on - IOW ->

Restarting services on server 2 will not work if your NRPE client and the plugin is on SERVER01 as the plugin will only work on server01.

format of command cscript /nologo winsvc-restart.vbs [Service-Name]

Here is the code for the script - copy it into a text file and give it a .vbs (vbscript) extention:

If WScript.Arguments.Count > 0 Then

	strService = WScript.Arguments(0)

	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

	Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service Where (Name = '" & strService & "' Or Caption = '" & strService & "')")

	For Each objService in colRunningServices

		If objService.State = "Running" Then

			WScript.StdOut.WriteLine objService.Caption & " OK: " & objService.State

			WScript.Quit(0)

		Else

			WScript.StdOut.WriteLine objService.Caption & " error (" & objService.State & "), attempting to restart"

			objService.StartService()

			WScript.Quit(1)

		End If

	Next

Else

	WScript.StdOut.WriteLine "ERROR: Service Name or Display Name required."

	WScript.Quit(3)

End If