Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
Hmm seems to exeucte if I use "." for server name (local) - so something to do with the fact that we're querying a remote server. –  Krip Oct 29 '10 at 13:46

1 Answer 1

Does the SCOM Action Account have rights to WMI on the remote servers. You may have to create a Run-As Profile to associate with the monitor and an account to go with it that will have rights to WMI on the remote servers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.