次の方法で共有


What Monitors, Rules and Discoveries are running on an OpsMgr Agent?

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.             #https://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.

Tweet

Comments

  • Anonymous
    January 01, 2003
    Here's one of the errors Method invocation failed because [System.Object[]] doesn't contain a method named 'getman agementpack'. At C:tempscomgetinfo.ps1:118 char:36
  •    $mp = $monitor.getmanagementpack <<<< ()    + CategoryInfo          : InvalidOperation: (getmanagementpack:String) [], RuntimeEx   ception    + FullyQualifiedErrorId : MethodNotFound
  • Anonymous
    January 01, 2003
    Sorry that didn't make sense. I need a dump of all monitors and rules running for a Linux server that is monitored by SCOM. I have made some progess. I figured out that I need to use the healthservice for the Management Server that is the proxy for the Linux servers. Here is my curent problem. I am monitoring 60 Linux servers with this MS. When I run the report (which takes 4 hours) I get 60 instances of each monitor, I assume one for each server. My question now is this. Is there a way to display which Linux server each rule or monitor is for. For Example: Monitor : Logical Disk % Free Space : Red Hat Enterprise Linux Server 4 Logical Disk % Free Space Monitor : Red Hat Enterprise Linux Server 4 Operating System : <Linux Server name>

  • Anonymous
    January 01, 2003
    Ran OK on my laptop connecting to my slow dev RMS, took about 20 min. I've enabled the overrides part of the script and am re-running it, it's been chewing over an hour now!

  • Anonymous
    January 01, 2003
    Hi Alyssa, I've not had time to look into this. Hope Dom has found a way and shares his info. /Stefan

  • Anonymous
    January 01, 2003
    Hi Alan, Thanks for the tip! Not thought about using the -criteria paramater. When I've some more time, I'll try to write an update. But if you have some time you can always try to improve the script yourself :-) /Stefan

  • Anonymous
    January 01, 2003
    Hi Dom, Great to hear you like it. /Stefan

  • Anonymous
    January 01, 2003
    Here is a less complicated script that will show running workflows on either the RMS or an Agent.

==============================================================================================

Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2011

NAME: ps.getAgentWorkflows.ps1

AUTHOR: microsoft provided.

DATE  : 5/24/2012

COMMENT: used to see whats running from the Agent health service

==============================================================================================

$server = "Your_RMS" Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"-ErrorVariable errSnapin; Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;new-managementGroupConnection -ConnectionString:$server -ErrorVariable errSnapin; Set-Location $server -ErrorVariable errSnapin;

Create the Task object

$taskobj = Get-Task | Where-Object {$_.Name -eq "Microsoft.SystemCenter.GetAllRunningWorkflows"}

Grab HealthService class object

$hsobj = Get-MonitoringClass -name "Microsoft.SystemCenter.HealthService" #Specify the Server $server = "Server_You_want_to_check"

Find HealthService object defined for named server

$monobj = Get-MonitoringObject -MonitoringClass $hsobj | Where-Object {$_.DisplayName -match $server}

See what tasks are running

$taskOut = Start-Task -Task $taskobj -TargetMonitoringObject $monobj [xml]$taskXML = $taskOut.OutPut $ruleCount = $taskXML.DataItem.Count $taskOut.OutPut | Out-File c:output1.xml

  • Anonymous
    January 01, 2003
    Hi ? Cannot remember if I used some code about the overrides from a script from Daniele, but we work ofter together so it could be;-) Sorry if I forgot to mention Daniele...

  • Anonymous
    January 01, 2003
    Finished after 3+ hrs with the overrides enabled and it failed. I will re-run it and capture the error for you.

  • Anonymous
    January 01, 2003
    Is ther a way to modify this for Linux (RHEL)?

  • Anonymous
    January 01, 2003
    Hi BHansen, I don't understand what you mean by "is there a way to modify this for Linux (RHEL)?" Could you please explain?

  • Anonymous
    January 01, 2003
    Hi Andy, Yes it's performance intensive :-) Talked to James Brundage yesterday evening and asked for some pointers on performance improvements, but have not had time to look into them. And I warned you ;-) Stefan

  • Anonymous
    December 02, 2010
    Hi Andy, I've seen that error before. That will happen when there are some monitors with the same name. That's why I added -unique for the discoveries (that's where I had seen that error before). Maybe I also need to that for the monitors and rules. Because when there are multiple monitors with the same name it will became an array. Technical story ;-) Will look into that. Maybe you can try to add #Retrieve Monitors             $monitors = get-monitor  | select-object -Unique             #Retrieve Rules             $rules = get-rule     | select-object -Unique             #Retrieve Discoveries"             #Used the Group-object because there are some discovery rules with the same DisplayName             $discoveries = get-discovery | select-object -Unique   Thanks for testing this...        

  • Anonymous
    December 03, 2010
    Very nice Stefan. I really hope we see some progress in this on OM vNext. I also wanted to mention that several of this script looks very much alike to an overrides script Daniele Muscetta did a few months ago. Was some of this maybe sourced from Daniele also? See "Command Shell: Dumping all overrides in Operations Manager 2007 (Script) " -  www.systemcentercentral.com/.../Default.aspx. This was also enhanced to create a proper overrides report at www.systemcentercentral.com/.../Default.aspx

  • Anonymous
    May 06, 2011
    Can we use SQL query to determine the data? If so , can i have the Query.

  • Anonymous
    May 18, 2012
    Hello Stefan, Is it possible to output a couple more pieces of information using your PowerShell script as follows: 1: Wheather or not the Monitor or Rule is currently configured to "Generate Alert" 2: If an override is configured the value or the override/s in question I will have a go at adjusting the powershell script, however I would be grateful if you would let me know the answer/code to the above two questions. Thank you in advance Ernie [removed email address]

  • Anonymous
    May 24, 2012
    The comment has been removed

  • Anonymous
    April 04, 2013
    Have you thought of not querying all the monitors, rules and discoveries? If you use the -criteria parameter when getting these objects instead of using where, you'll certeinly use much less CPU and memory with the same results! Guess I'll need to do this, so if I really do, I'll post it here :) Great post, by the way!

  • Anonymous
    August 01, 2013
    Hello, Excellent script thanks a lot I got all the monitors and rules listed with threshold also which is really good. Now I need the link to the server name...Still looking Thanks, Dom

  • Anonymous
    August 21, 2013
    I also found this script to be almost perfect.  One question - how do I get the agent name listed with each row?  Dominique, did you find a way? Thanks in advance, --Alyssa

  • Anonymous
    January 17, 2014
    A small, but usefull link collection to use for configuration and upgrading System Center Operations

  • Anonymous
    February 07, 2014
    Hi Stefan. This looks like an excellent script. Is there any way to get this to work in SCOM 2012? I'm a SCOM novice and I don't think I'm competent enough just yet to change the cmdlets and make it work. Or maybe there's another way to make it work in 2012 that I haven't found yet? Thanks, /Erik