locked
Custom Monitor Type Question - Building a custom Process Monitor with a pre-condition RRS feed

  • Question

  • In the past, I have built a custom Monitor Type using the WMI Provider and the SchedulerFilter.  But, instead of using a schedulerFilter I want to determine whether a service is running or not to be trigger.  (This is to monitor only the active servers in a active/passive File Caching solution)  I've already created the custom class and discovies to limit the monitor to only these type of servers.  It did not seem appropriate to use another discovery to determine the active or passive state, and it would need to be run often.  I am looking for suggestions.  Should I attempt to create a custom Condition Detection Module Type?  And, I'll need help there.  Or, should I create another DS Module and somehow order the modules accordingly?

    Wednesday, October 28, 2009 2:58 PM

Answers

  • No, unfortunately this is a vendor HA solution.  For now, I was able to just use a standard timed script monitor (vbscript).  I used a previously borrowed script and just added the extra if statement (example below).  This solution isn't as elegant as borrowing the Processor Monitor and DataSource types in the template where I could exploit the other three monitors like memory limit, etc.  If the built in Process Monitor would take a minimum value of zero that would also have worked in this case.  Unfortunately, the ProcessMonitor template appears to require at least one process in order for it's discovery to work.

    ' Script to send back "TooFew" "Good" or "TooMany" depending upon the number of processes of a specific name running on the system
    '
    Dim oAPI, oBag
    Dim ErrorCount
    Dim WarningCount
    Dim SuccessCount
    Dim propertyBag
    Set oAPI = CreateObject("MOM.ScriptAPI")
    Set oArgs = WScript.Arguments

    'map event types & numbers to friendly names
    Const EVENT_TYPE_ERROR = 1
    Const EVENT_TYPE_WARNING = 2
    Const EVENT_TYPE_SUCCESS = 4

    If oArgs.Count < 3 Then
     ' If the script is called without the required arguments,
     ' create an information event and then quit.

    ' Set objShell = Wscript.CreateObject("Wscript.Shell")
    ' objShell.LogEvent EVENT_TYPE_ERROR, _
    ' "ProcessMonitor run with an incorrect number of arguments."
     WScript.Quit -1
    End If

    'Get script parameter values for OpsMgr
    strProcess = oArgs.Item(0)
    GoodLowerCount = oArgs.Item(1)
    GoodUpperCount = oArgs.Item(2)

    ' Set objShell = Wscript.CreateObject("Wscript.Shell")
    ' objShell.LogEvent EVENT_TYPE_SUCCESS, _
    ' "ProcessMonitor run with " & strProcess & " " & GoodLowerCount & " " & GoodUpperCount & " as arguments."

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT State FROM Win32_Service WHERE Name='VivService'")
    For Each objItem in colItems
    If objItem.State = "Running" Then
     Set objWMIService = GetObject("winmgmts:" _
         & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     Set colProcesses = objWMIService.ExecQuery _
         ("Select * from Win32_Process Where Name = '" & strProcess & "'")

    '  Set objShell = Wscript.CreateObject("Wscript.Shell")
    '  objShell.LogEvent EVENT_TYPE_SUCCESS, _
    '  "ProcessMonitor colProcesses.Count equals " & colProcesses.Count & "."

     if colProcesses.Count > cInt(GoodUpperCount) Then
       Set objShell = Wscript.CreateObject("Wscript.Shell")
    '   objShell.LogEvent EVENT_TYPE_WARNING, _
    '   "The process, " & strProcess & ", is running too many times. " & colProcesses.Count & " were running."
       Set propertyBag = oAPI.CreatePropertyBag ()
       Call propertyBag.AddValue ("Status", "TooMany")
       Call propertyBag.AddValue ("Process", strProcess)
     End If

     if colProcesses.Count < cInt(GoodLowerCount) Then
       Set objShell = Wscript.CreateObject("Wscript.Shell")
    '   objShell.LogEvent EVENT_TYPE_ERROR, _
    '   "There are not enough " & strProcess & " running. " & colProcesses.Count & " were running."
       Set propertyBag = oAPI.CreatePropertyBag ()
       Call propertyBag.AddValue ("Status", "TooFew")
       Call propertyBag.AddValue ("Process", strProcess)
     End If

     if colProcesses.Count => cInt(GoodLowerCount) and colProcesses.Count <= cInt(GoodUpperCount) Then
       Set objShell = Wscript.CreateObject("Wscript.Shell")
    '   objShell.LogEvent EVENT_TYPE_SUCCESS, _
    '   "The process, " & strProcess & ", has " & colProcesses.Count & " processes running."
       Set propertyBag = oAPI.CreatePropertyBag ()
       Call propertyBag.AddValue ("Status", "Good")
       Call propertyBag.AddValue ("Process", strProcess)
     End If

     Call oAPI.Return(propertyBag)
    Else
     Set objWMIService = Nothing                           
    End If
    Next

    Friday, October 30, 2009 1:30 AM

All replies

  • Is this being managed in a MSCS cluster?
    Microsoft Corporation
    Thursday, October 29, 2009 2:26 PM
  • No, unfortunately this is a vendor HA solution.  For now, I was able to just use a standard timed script monitor (vbscript).  I used a previously borrowed script and just added the extra if statement (example below).  This solution isn't as elegant as borrowing the Processor Monitor and DataSource types in the template where I could exploit the other three monitors like memory limit, etc.  If the built in Process Monitor would take a minimum value of zero that would also have worked in this case.  Unfortunately, the ProcessMonitor template appears to require at least one process in order for it's discovery to work.

    ' Script to send back "TooFew" "Good" or "TooMany" depending upon the number of processes of a specific name running on the system
    '
    Dim oAPI, oBag
    Dim ErrorCount
    Dim WarningCount
    Dim SuccessCount
    Dim propertyBag
    Set oAPI = CreateObject("MOM.ScriptAPI")
    Set oArgs = WScript.Arguments

    'map event types & numbers to friendly names
    Const EVENT_TYPE_ERROR = 1
    Const EVENT_TYPE_WARNING = 2
    Const EVENT_TYPE_SUCCESS = 4

    If oArgs.Count < 3 Then
     ' If the script is called without the required arguments,
     ' create an information event and then quit.

    ' Set objShell = Wscript.CreateObject("Wscript.Shell")
    ' objShell.LogEvent EVENT_TYPE_ERROR, _
    ' "ProcessMonitor run with an incorrect number of arguments."
     WScript.Quit -1
    End If

    'Get script parameter values for OpsMgr
    strProcess = oArgs.Item(0)
    GoodLowerCount = oArgs.Item(1)
    GoodUpperCount = oArgs.Item(2)

    ' Set objShell = Wscript.CreateObject("Wscript.Shell")
    ' objShell.LogEvent EVENT_TYPE_SUCCESS, _
    ' "ProcessMonitor run with " & strProcess & " " & GoodLowerCount & " " & GoodUpperCount & " as arguments."

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT State FROM Win32_Service WHERE Name='VivService'")
    For Each objItem in colItems
    If objItem.State = "Running" Then
     Set objWMIService = GetObject("winmgmts:" _
         & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     Set colProcesses = objWMIService.ExecQuery _
         ("Select * from Win32_Process Where Name = '" & strProcess & "'")

    '  Set objShell = Wscript.CreateObject("Wscript.Shell")
    '  objShell.LogEvent EVENT_TYPE_SUCCESS, _
    '  "ProcessMonitor colProcesses.Count equals " & colProcesses.Count & "."

     if colProcesses.Count > cInt(GoodUpperCount) Then
       Set objShell = Wscript.CreateObject("Wscript.Shell")
    '   objShell.LogEvent EVENT_TYPE_WARNING, _
    '   "The process, " & strProcess & ", is running too many times. " & colProcesses.Count & " were running."
       Set propertyBag = oAPI.CreatePropertyBag ()
       Call propertyBag.AddValue ("Status", "TooMany")
       Call propertyBag.AddValue ("Process", strProcess)
     End If

     if colProcesses.Count < cInt(GoodLowerCount) Then
       Set objShell = Wscript.CreateObject("Wscript.Shell")
    '   objShell.LogEvent EVENT_TYPE_ERROR, _
    '   "There are not enough " & strProcess & " running. " & colProcesses.Count & " were running."
       Set propertyBag = oAPI.CreatePropertyBag ()
       Call propertyBag.AddValue ("Status", "TooFew")
       Call propertyBag.AddValue ("Process", strProcess)
     End If

     if colProcesses.Count => cInt(GoodLowerCount) and colProcesses.Count <= cInt(GoodUpperCount) Then
       Set objShell = Wscript.CreateObject("Wscript.Shell")
    '   objShell.LogEvent EVENT_TYPE_SUCCESS, _
    '   "The process, " & strProcess & ", has " & colProcesses.Count & " processes running."
       Set propertyBag = oAPI.CreatePropertyBag ()
       Call propertyBag.AddValue ("Status", "Good")
       Call propertyBag.AddValue ("Process", strProcess)
     End If

     Call oAPI.Return(propertyBag)
    Else
     Set objWMIService = Nothing                           
    End If
    Next

    Friday, October 30, 2009 1:30 AM
  • No activity for 30 days, will close this thread, feel free to open it again.
    Anders Bengtsson | Microsoft MVP - Operations Manager | http://www.contoso.se
    Thursday, December 17, 2009 9:47 PM