Archive

Archive for the ‘Script’ Category

Check For Not Running Services In Automatic Mode

November 9th, 2009 Amit Gatenyo 1 comment

Ever needed to get alerts on all services that are set to Automatic but not running?

Use the following SCOM monitor to do just that:

1. Create a Unit Monitor of type “Timed script two state monitor”, call it “Check For Not Running Services In Automatic Mode” or name it whatever you want

2. Check of “Monitor is enabled” (we will enable it to run only on specific servers later with overrides)

3. Monitor target – Agent

4. Put the following script:

Call Main ()

Sub Main()

‘ Monitor if automatic process is not running

Dim oAPI, oBag, wshShell
Set oAPI = CreateObject("MOM.ScriptAPI")

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

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

Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where StartMode = ‘Auto’")

For Each objService in colListOfServices
Set oBag = oAPI.CreatePropertyBag()
If Not objService.Started = True Then
strDesc = "Service " & objService.Caption & " is not running on " & strComputer
Call oBag.AddValue("Description", strDesc)
Call oBag.AddValue("State", "BAD")
Else
Call oBag.AddValue("State", "GOOD")
End If

oAPI.Additem(oBag)

Next

oAPI.ReturnItems

End Sub

 

5. As Unhealthy expression put

Property[@Name='State'] Contains BAD

6. As Healthy expression put

Property[@Name='State'] Contains GOOD

7. Turn on Alerting

8. As Alert Description put

$Data/Context/Property[@Name='Description']$

9. Turn on Override for specified servers and change option Enabled to TRUE

Enjoy!

VN:F [1.9.3_1094]
VN:F [1.9.3_1094]
Categories: SCOM, Script Tags: ,

.