none
Timed Script Two State Monitor - Monitors Automatic Services RRS feed

  • Question

  • Searching forums and groups I was able to put together a sort of working monitor for all of my windows servers services set to automatic that are running, if they are stopped or stop, an alert is generated.  Most of the data was generated from this forum.  I have a couple of issues I can't seem to iron out.  I am on SCOM2007 R2.

    I created the monitor for 'Windows Server'

    The Script I run is: (No parameters set)

    Dim oAPI, oBag

    Set oAPI = CreateObject("MOM.ScriptAPI")

    Set oBag = oAPI.CreatePropertyBag()

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_Service WHERE StartMode = 'Auto' AND Started = false")

     

    If colListOfServices.Count > 0 Then

    For Each objService in colListOfServices

     

    If strDesc = "" Then

    strDesc = objService.Caption

    Else

    StrDesc = StrDesc & ", " & objService.Caption

    End if

    Next

    Call oBag.AddValue("Description", strDesc)

    Call oBag.AddValue("State", "BAD")

    Else

    Call oBag.AddValue("State", "OK")

    End if

    -----------------------------

     

    Alert description of the monitor is defined as:

    $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$

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

     

    ------------------------------------------------

     

    Diagnostic and Recovery is Defined as; Recovery Task Script; Run automatically Yes; Recalculate monitor Yes

    If colListOfServices.Count > 0 Then

    For Each objService in colListOfServices

    If strDesc = "" Then

    strDesc = objService.Caption

    Else

    StrDesc = StrDesc & ", " & objService.Caption

    End if

    objService.StartService()

    End if

     

    ------------------------------------------------

    My questions are:

    1. The monitor works, I do get alerted if the service is set to auto and it is stopped or the process is killed.  However, it only seems to alert on this once in a 24 hour period, even though the monitor is set to run every 5 minutes.  Any direction I can look at to solve that issue?

    2. I cannot get the data to pull into alert description.  The only way I know of the downed monitor is to actually go into SCOM, and open alert context to see which monitor is down.  With my current alert description parameters, I am actually having an SCOM alert generated; which says "Alert Parameter Replacement Failure"  Is my syntax incorrect?

    Failed to replace parameter while creating the alert for monitor state change.


    Workflow: UIGeneratedMonitorad8b00f7447d4545876b78627fd52f88

    Instance: srvch-server.chicago.domain.com

    Instance ID: 451E9F94-780D-C253-36E6-9AB8E4DC40BD

    Management Group: SCOM


    Failing replacement: $Data/Property[@Name='Description']$

     

    3.  The recovery does not seem to work.  The downed service does not recover with the recovery script in place. 

     

    4.  Any better target for the monitor then Windows Server?  That seems to populate every dependant target.

    Thanks for any direction.

     

    Justin

    Friday, July 9, 2010 2:17 PM

Answers

  • Hi Justin,

    >Failing replacement: $Data/Property[@Name='Description']$

     

    Dim oAPI, oBag

    Set oAPI = CreateObject("MOM.ScriptAPI")

    Set oBag = oAPI.CreatePropertyBag()

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_Service WHERE StartMode = 'Auto' AND Started = false")

     

    If colListOfServices.Count > 0 Then

    For Each objService in colListOfServices

     

    If strDesc = "" Then

    strDesc = objService.Caption

    Else

    StrDesc = StrDesc & ", " & objService.Caption

    End if

    Next

    Call oBag.AddValue("Description", strDesc)

    Call oBag.AddValue("State", "BAD")

    Else

    Call oBag.AddValue("Description", "All services - OK")

    Call oBag.AddValue("State", "OK")

    End if

    >However, it only seems to alert on this once in a 24 hour period, even though the monitor is set to run every 5 minutes.  Any direction I can look at to solve that issue?

    This monitor will not alert you if monitor is already in 'bad' state. If ServiceA is stopped and ServiceB is stopped this monitor will generate alert only for a service stopped first. Is that your case?

    > The recovery does not seem to work.  The downed service does not recover with the recovery script in place. 

    >If colListOfServices.Count > 0 Then

    >For Each objService in colListOfServices

    >If strDesc = "" Then

    >strDesc = objService.Caption

    >Else

    >StrDesc = StrDesc & ", " & objService.Caption

    >End if

    >objService.StartService()

    >End if

     

    It's just a PART of script you need. Try this: 

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_Service WHERE StartMode = 'Auto' AND Started = false")

    If colListOfServices.Count > 0 Then

     

    For Each objService in colListOfServices

    objService.StartService()

    End if

     

     

    HTH

     


    http://OpsMgr.ru/
    Wednesday, July 14, 2010 4:01 PM
    Moderator

All replies

  •  

    anyone?

    Wednesday, July 14, 2010 2:36 PM
  • Hi Justin,

    >Failing replacement: $Data/Property[@Name='Description']$

     

    Dim oAPI, oBag

    Set oAPI = CreateObject("MOM.ScriptAPI")

    Set oBag = oAPI.CreatePropertyBag()

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_Service WHERE StartMode = 'Auto' AND Started = false")

     

    If colListOfServices.Count > 0 Then

    For Each objService in colListOfServices

     

    If strDesc = "" Then

    strDesc = objService.Caption

    Else

    StrDesc = StrDesc & ", " & objService.Caption

    End if

    Next

    Call oBag.AddValue("Description", strDesc)

    Call oBag.AddValue("State", "BAD")

    Else

    Call oBag.AddValue("Description", "All services - OK")

    Call oBag.AddValue("State", "OK")

    End if

    >However, it only seems to alert on this once in a 24 hour period, even though the monitor is set to run every 5 minutes.  Any direction I can look at to solve that issue?

    This monitor will not alert you if monitor is already in 'bad' state. If ServiceA is stopped and ServiceB is stopped this monitor will generate alert only for a service stopped first. Is that your case?

    > The recovery does not seem to work.  The downed service does not recover with the recovery script in place. 

    >If colListOfServices.Count > 0 Then

    >For Each objService in colListOfServices

    >If strDesc = "" Then

    >strDesc = objService.Caption

    >Else

    >StrDesc = StrDesc & ", " & objService.Caption

    >End if

    >objService.StartService()

    >End if

     

    It's just a PART of script you need. Try this: 

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_Service WHERE StartMode = 'Auto' AND Started = false")

    If colListOfServices.Count > 0 Then

     

    For Each objService in colListOfServices

    objService.StartService()

    End if

     

     

    HTH

     


    http://OpsMgr.ru/
    Wednesday, July 14, 2010 4:01 PM
    Moderator
  • Thank you for the reply.

     

    I have been focusing on the Alerting issue and made the adjustment to the initial script by adding

    Call oBag.AddValue("Description", "All services - OK")

    But I still get the failed parameter alert.   Would this be related to my monitor target at all?  Right now, it is 'Windows Server'

     

    - For the single monitor alert in a 24 hour period, I deleted and re-entered the monitor, it seems to perform as normal.  If it goes down, and is resolved, then goes down again, an alert will be triggered.  I think it might have been a timing issue last time, but for whatever reason it is working properly. 

    - As for the recovery script - "doh"  - thanks.

    Friday, July 16, 2010 8:24 PM
  • >But I still get the failed parameter alert.  

    Hmm. Try to replace $Data/Property[@Name='Description']$ with Property[@Name='Description']


    http://OpsMgr.ru/
    Saturday, July 17, 2010 2:47 AM
    Moderator
  • Finally got it.  It was this:

     

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

     

     

    Thanks for all of your help.  Much appreciated!

    Monday, July 19, 2010 2:17 PM