NSClient++ Help (#1) - Can Nsclient++ restart Windows Services? (#132) - Message List

Can Nsclient++ restart Windows Services?

Is is possible to restart an Windows Service per NSClient++?

thanks

greeting Elric

  • Message #346

    in short: no

    slightly longer: nsclient++ is a monitoring agent and thus only supports monitoring things, restarting would be "changing" things and given the security issues that check_nt and check_nrpe has I think that is a "good idea". On the other hand nsclient++ support scripts written in various languages so if you want you can easily write a script that does just that, but I have not done so my self so there is nothing out of the box. But since a lot of people has requested this I am considering it, so maybe for next version? (feel free to request a feature)

    MickeM

    • Message #352

      You could probably write a VBScript which would check the status of a service passed in as an argument.

      Here's one I've prepared earlier (seems OK on my test system but no guarantee whatsoever):

      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
      

      Just call it by running whatever.vbs service (works with the short service name or long one).

Subscriptions