How often do you get the question: “What Monitors, Rules and Discoveries are running on an OpsMgr Agent?” from your co-workers? Especially when they don’t have a clue what is being monitored for their servers.

Most of the time you just use the EffectiveConfigurationViewer from the OpsMgr Resource Kit. It let’s you pick different objects, besides the Agents you are monitoring with OpsMgr.

image

image

It’s shows quite some interesting information and let’s you export the result to an XML file. But that’s not always your co-workers want’s to see. IMO they often want to have an Excel sheet with all the Monitors and Rules running on a specific Agent. That’s what they understand and can easily read.

What options do you have now?

  1. You can try to build some wrapper around the exported XML file, with PowerShell.
    image
  2. Use a third-party tool, like MP Studio to export the Monitors, Rules and Discoveries (workflows) running on an Agents
  3. Create a PowerShell script that does the magic Winking smile

Let’s look at the options.

 

Build some wrapper around the exported XML file

This is possible, but would not give us all the information we would like to see. It can only give us the Monitor/Rule or Discovery Name and it’s state. We are interested in much more, like: Name, Description, Type, Management Pack, Overrides, etc.

So let’s skip this option.

 

Use a third-party tool

In the next version of MP Studio a new feature called Silect’s Agent Explorer will be added. I’m lucky to be able to test the latest evaluation version of MP Studio and it will be able to give you almost all the information you probably need.

If you want to see what Monitors, Rules and Discoveries are running on an Agent, you can use the Explore workflow tasks feature (Agent Explorer) to view all workflows running on all agents or a specific server.

image

 

It will give you an overview of all Workflows running on a specified Agent and you can export the result to Excel.

image

This is almost what I want to see. The only thing I’m missing in the current Agent Explorer feature is if there are overrides configured for a Monitor, Rule or Discovery. I talked with Randy Roffey from Silect about this, and he told me that would be challenge, because there can be be multiple override settings for the same workflow. Good point, but it would be nice to see if there are any overrides for a workflow, than you can always manually check the configured overrides later.

 

PowerShell script that does the magic

The last option we have is to create a PowerShell script that does all we want. And what do we want? We want an Excel sheet with all Monitors, Rules and Discoveries running on an Agent, with their Type, DisplayName, Description, possible Override and ManagementPack.

image

image

Here you can see again 768 workflows running on the OpsMgr Agent (just like in MP Studio) but it also shows if there is an Override* being configured for the Monitor, Rule or Discovery. This still does not mean that the override is applicable for the Agent though.

* Retrieving the Override information can be a time (CPU and Memory) consuming exercise, so I commented that part of the PowerShell script.

 

Drawback I found using this script is the impact on the CPU and Memory when running this script and the time it takes before this script finishes. So you may take that into consideration when you run this script. First it retrieves all the Monitors, Rules and Discoveries and saves that in Memory and loops through this data in memory for finding the workflow information.

When I tested this script in my small OpsMgr 2007 R2 environment it took 1:47 seconds to run.

image

But it can also take much longer Sad smile, like 27 minutes in another larger OpsMgr 2007 R2 environment.

image

 

If you are still interested to give the script a try, here it is:

###############################################################################                        
# Get OpsMgr 2007 Running Workflows using PowerShell                        
# This script retrieves the workflows running on an OpsMgr Agent                        
# Authors: Jeremy Pavleck & Stefan Stranger (Microsoft)            
# Example usage (run from OpsMgr Command Shell): Get-OpsMgrWorkflows_v1.ps1 -agentname "myagent.contoso.com" | export-csv -path c:\temp\workflows.csv            
# Date:		30-11-2010                        
# Name: 	Get-AgentWorkflows_v1.ps1            
# Remarks: 	Warning: Script is CPU and Memory intensive!!            
#		Retrieving the overrides for the Monitors, Rules and Discoveries turned out to be a time, CPU and Memory consuming exercise and I disabled it.            
#          	You can enable it by Uncommenting that part of the script if you want to.            
#		Script needs to run in PowerShell version 2.            
# v1.000 - 	30/11/2010 - stefstr - initial sstranger's release                        
###############################################################################            
            
param ([string]$agentname = $(read-host "Please enter OpsMgr Agent Name"))             
            
function Get-AgentWorkflow($agentname)            
{            
 #Original Script from Jeremy Pavleck.            
 #http://www.pavleck.net/2008/06/sp1-gem-finding-rules-running-on-remote-agents/            
 #Use the OpsMgr Task Show Running Rules and Monitors.            
 $taskobj = Get-Task | Where-Object {$_.Name -eq "Microsoft.SystemCenter.GetAllRunningWorkflows"}            
             
 # Grab HealthService class object            
 $hsobj = Get-MonitoringClass -name "Microsoft.SystemCenter.HealthService"            
 # Find HealthService object defined for named server            
 $monobj = Get-MonitoringObject -MonitoringClass $hsobj | Where-Object {$_.DisplayName -match $agentname}            
             
 #Start Task GetAllRunningWorkflows            
 $taskOut = Start-Task -Task $taskobj -TargetMonitoringObject $monobj            
 [xml]$taskXML = $taskOut.OutPut             
             
 #Get Workflows            
 $workflows=$taskXML.selectnodes("/DataItem/Details/Instance/Workflow")            
             
 #Retrieve Monitors            
 $monitors = get-monitor            
             
 #Retrieve Rules            
 $rules = get-rule            
             
 #Retrieve Discoveries"            
 #Used the Group-object because there are some discovery rules with the same DisplayName            
 $discoveries = get-discovery | select-object -Unique            
             
 #Get Overrides"            
 #monitoroverrides = foreach ($monitor in Get-ManagementPack | get-override | where {$_.monitor}) {get-monitor | where {$_.Id -eq $monitor.monitor.id}}            
 #$rulesoverrides = foreach ($rule in Get-ManagementPack | get-override | where {$_.rule}) {get-rule | where {$_.Id -eq $rule.rule.id}}            
 #$discoveryoverrides = foreach ($discovery in Get-ManagementPack | get-override | where {$_.discovery}) {get-discovery | where {$_.Id -eq $discovery.discovery.id}}            
            
            
 #Check for each workflow if it's a Rule or Monitor or Discovery.            
 foreach ($workflow in $workflows)            
 {            
  #Check for Monitor            
  $monitor = $monitors | where-object {$_.Name -eq $workflow."#text"}            
              
  if ($monitor -eq $null)            
  {            
   #Check for Rule            
   $rule = $rules | where-object {$_.Name -eq $workflow."#text"}            
   if ($rule -eq $null)            
   {             
    #Check for Discovery            
    $discovery = $discoveries | where-object {$_.Name -eq $workflow."#text"}            
    if ($discovery -eq $null)            
    {            
                
    }            
    else            
    {            
     #Get ManagementPack            
     $mp = $discovery.getmanagementpack()            
     #Check if Discovery has an override            
     #$flag = $discoveryoverrides | Where-Object {$_.DisplayName -eq $discovery.DisplayName}            
     #if ($flag -eq $null)            
     #{            
     #	$override = "false"            
     #}            
     #else            
     #{            
     #	$override = "true"            
     #}            
     $discobject = new-object System.Management.Automation.PSObject            
     $discobject = $discobject | add-member -membertype NoteProperty -name Type -value "Discovery" -passthru            
     $discobject = $discobject | add-member -membertype NoteProperty -name DisplayName -value $discovery.DisplayName -passthru            
     $discobject = $discobject | add-member -membertype NoteProperty -name Description -value $discovery.Description -passthru            
     #$discobject = $discobject | add-member -membertype NoteProperty -name Override -value $override -passthru            
     $discobject = $discobject | add-member -membertype NoteProperty -name ManagementPack -value $mp.DisplayName -passthru            
     $discobject            
    }            
   }            
   else            
   {            
    $mp = $rule.getmanagementpack()            
    #Check if Rule has an override            
    #$flag = $ruleoverrides | Where-Object {$_.DisplayName -eq $rule.DisplayName}            
    #if ($flag -eq $null)            
    #{            
    #	$override = "false"            
    #}            
    #else            
    #{            
    #	$override = "true"            
    #}            
    $ruleobject = new-object System.Management.Automation.PSObject            
    $ruleobject = $ruleobject | add-member -membertype NoteProperty -name Type -value "Rule" -passthru            
    $ruleobject = $ruleobject | add-member -membertype NoteProperty -name DisplayName -value $rule.DisplayName -passthru            
    $ruleobject = $ruleobject | add-member -membertype NoteProperty -name Description -value $rule.Description -passthru            
    #$ruleobject = $ruleobject | add-member -membertype NoteProperty -name Override -value $override -passthru            
    $ruleobject = $ruleobject | add-member -membertype NoteProperty -name ManagementPack -value $mp.DisplayName -passthru            
    $ruleobject            
   }            
  }            
  else            
  {            
   #Get ManagementPack for Monitor            
   $mp = $monitor.getmanagementpack()            
   #Check if Monitor has an override            
   #$flag = $monitoroverrides | Where-Object {$_.DisplayName -eq $monitor.DisplayName}            
   #if ($flag -eq $null)            
   #{            
   #	$override = "false"            
   #}            
   #else            
   #{            
   #	$override = "true"            
   #}            
   $monitorobject = new-object System.Management.Automation.PSObject            
   $monitorobject = $monitorobject | add-member -membertype NoteProperty -name Type -value "Monitor" -passthru            
   $monitorobject = $monitorobject | add-member -membertype NoteProperty -name DisplayName -value $monitor.DisplayName -passthru            
   $monitorobject = $monitorobject | add-member -membertype NoteProperty -name Description -value $monitor.Description -passthru            
   #$monitorobject = $monitorobject | add-member -membertype NoteProperty -name Override -value $override -passthru            
   $monitorobject = $monitorobject | add-member -membertype NoteProperty -name ManagementPack -value $mp.DisplayName -passthru            
   $monitorobject            
  }            
 }            
            
            
}            
            
Get-AgentWorkflow $agentname

Disclaimer

This sample is not supported under any Microsoft standard support program or service. This sample is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of this sample and documentation

remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of this sample be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use this sample or documentation, even if Microsoft has been advised of the possibility of such damages.