I have a two state script I've added to Monitoring that checks the state of a service on two servers and reports if it's running on both or none (should only run on one). It runs fine interactively but it's not working once in SCOM 2007. Anyone know what I'm missing?
I have added in healthy and unhealthy checks based on propertybag value.
Here's the script:
Dim oAPI
Dim oBag
Dim strService
Dim strComputer1
Dim strComputer2
Dim isService1Running
Dim isService2Running
Dim isProblem
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
strService = "My Service Name"
strComputer1 = "myServer1"
strComputer2 = "myServer2"
isService1Running = IsServiceRunning(strComputer1, strService)
isService2Running = IsServiceRunning(strComputer2, strService)
isProblem = (isService1Running And isService2Running) Or (Not isService1Running And Not isService2Running)
If isProblem Then
Call oBag.AddValue("State", "BAD")
Else
Call oBag.AddValue("State", "GOOD")
End If
Call oAPI.Return(oBag)
Function IsServiceRunning(strComputer, strService)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = '" & strService & "'")
IsServiceRunning = false
For Each objItem in colItems
If objItem.status <> "OK" or objItem.state <> "Running" then
Else
IsServiceRunning = true
End If
Next
End Function