-
Re: Restart Service on alarm
Questionario Aug 2, 2010 11:04 AM (in response to Questionario)anyone?
I found this so far:
not able to restart a IIS service if website goes down with advanced alerts
But I will need to restart the dependencies as well or the service wont restart either.
-
Re: Restart Service on alarm
Questionario Aug 2, 2010 12:22 PM (in response to Questionario)ok, I got this so far:
'
' Script: restart-service.vbs
'
' Purpose: Restart a service as a result of a SolarWinds
' NPM alert action.
'
' Usage: .\restart-service.vbs <computer> <service>
'==============================================================================
Option Explicit
Dim objWMIService, objItem, objService, objSubService, objselService
Dim colListOfServices, colListOfSubServices, strComputer, strService, intSleep, Return
intSleep = 3000
strComputer = WScript.Arguments.Item(0)
strService = WScript.Arguments.Item(1)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objItem = objWMIService.Get("Win32_Service.Name='" & strService & "'")
Set colListOfServices = objWMIService.ExecQuery("Associators of " & "{Win32_Service.Name='" & strService & "'} Where " & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For Each objService in colListOfServices
Set colListOfSubServices = objWMIService.ExecQuery("Associators of " & "{Win32_Service.Name='" & objService.Name & "'} Where " & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For Each objSubService in colListOfServices
objSubService.StopService()
WScript.Echo(objSubService.Name)
WScript.Sleep(intSleep)
Next
WScript.Echo(objService.Name)
objService.StopService()
WScript.Sleep(intSleep)
Next
objItem.StopService()
WScript.Echo("All stopped")
WScript.Sleep(intSleep)
objItem.StartService()
For Each objService in colListOfServices
Set colListOfSubServices = objWMIService.ExecQuery("Associators of " & "{Win32_Service.Name='" & objService.Name & "'} Where " & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For Each objSubService in colListOfServices
objSubService.StartService()
WScript.Sleep(intSleep)
Next
objService.StartService()
WScript.Sleep(intSleep)
Next
WScript.Quit(0)Now, while this works fine I think it needs some fine-tuning....
Because of some inter-related dependencies, all services are being stopped (same problem with starting) like 2-4times or something like that, therefore the script does unnecessary work and takes a while to finish. Nonetheless it works :)
Could anybody help me to make this script more efficient?
-