Kevin Holman's System Center Blog

Posts in this blog are provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified in the Terms of UseAre you interested in having a dedicated engineer that will be your Mic

Targeting workflows to Resource pools

Targeting workflows to Resource pools

  • Comments 4
  • Likes

 

Resource Pools in SCOM 2012 are an advancement over SCOM 2007, where a resource pool can be used to host instances, that have targeted workflows, and make them highly available.  This allowed the “All Management Servers Resource Pool” to host the instances that the RMS used to run in SCOM 2007.  This allowed for all management servers, in the AMSRP, to automatically load balance the old RMS workflows, across all management servers.

This also is used for thing like the Notifications Resource pool, which hosts two instances (or Top Level Managed Entities) which are the Pool object itself, and the “Alert Notification Subscription Server” which have many monitoring workflows target it to monitor the notification process health.

 

Well, we can also write workflows and target resource pools.  We might do this if we want a workflow to run on the management servers, but be highly available. 

In this example, I will take a VERY simple script that does nothing but log an event, and target the All Management Servers Resource Pool.

First, here is my PowerShell script:

$api = new-object -comObject 'MOM.ScriptAPI' $api.LogScriptEvent("momscriptevent.ps1",9999,0,"this is a test event")

This script simply loads the MOM.ScriptAPI which is necessary to perform specific SCOM actions in script, such as logging events to the SCOM event lot, creating property bags, submitting discovery data, etc.

Then, it logs an informational event for the script in the SCOM event log wherever it is running.

Next up – write my rule to run the script.

We cannot use the SCOM 2007R2 Authoring Console to write this rule, as we need to target the Resource Pool object which SCOM 2007R2 does not understand, nor can it reference.  If you are most familiar with authoring in that tool, and you really want to use that SCOM 2007R2 Authoring Console, you can do that, and just target something else, like “Windows Server Operating System” and then change the class later in an XML editor.

Here is my manifest section.  Note – I need to reference the SCOM 2012 versions of these MP’s since this MP will not work on SCOM 2007:

<Manifest> <Identity> <ID>Target.ResourcePool.Example</ID> <Version>1.0.0.1</Version> </Identity> <Name>Target.ResourcePool.Example</Name> <References> <Reference Alias="SC"> <ID>Microsoft.SystemCenter.Library</ID> <Version>7.0.8427.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="Windows"> <ID>Microsoft.Windows.Library</ID> <Version>7.5.8500.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="Health"> <ID>System.Health.Library</ID> <Version>7.0.8427.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="System"> <ID>System.Library</ID> <Version>7.5.8500.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> </References> </Manifest>

Next, my simple rule.  Notice – I target the AMSRP class, I add a simple scheduler module to run this workflows every 30 seconds, and I have a simple write action based on Microsoft.Windows.PowerShellWriteAction module.

<Monitoring> <Rules> <Rule ID="Target.ResourcePool.Example.RunSampleScriptRule" Enabled="true" Target="SC!Microsoft.SystemCenter.AllManagementServersPool" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100"> <Category>Custom</Category> <DataSources> <DataSource ID="SchedDS" TypeID="System!System.SimpleScheduler"> <IntervalSeconds>30</IntervalSeconds> <SyncTime></SyncTime> </DataSource> </DataSources> <WriteActions> <WriteAction ID="PoshWA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction"> <ScriptName>momscriptevent.ps1</ScriptName> <ScriptBody><![CDATA[ $api = new-object -comObject 'MOM.ScriptAPI' $api.LogScriptEvent("momscriptevent.ps1",9999,0,"this is a test event") ]]></ScriptBody> <TimeoutSeconds>30</TimeoutSeconds> </WriteAction> </WriteActions> </Rule> </Rules> </Monitoring>

That’s it!  I will post my full XML as a sample attached to this article.

Now, when I import this MP, ONE of my management servers should start running this workflow.  It will be whichever MS is hosting the AMSRP class at that time.  This could change as loads are reshuffled, or as management servers are taken down for maintenance.

I have three management servers, SCOM01, SCOM02, and SCOM03.  I can see this workflow is running happily on SCOM02:

image

I will stop the health service on SCOM02, or shut the OS down.

The last event I got from the test script was at 9:09:56 AM.

What happens now, is the other management servers are waiting for a heartbeat failure threshold to take a vote, and evict SCOM02 from the pool.  The SCOM database is also a “default observer” and plays a role in the voting process. 

At 9:12:36 AM, I start to see the pool manager events coming in, showing that they other management servers are redistributing the workflows.  My 9999 event is now being created on SCOM03, with my first event showing up at 9:12:55 AM, or about 3 minutes after SCOM02 went down.

image

 

My sample XML is provided below.

Attachment: Target.ResourcePool.Example.zip
Comments
  • Very usefull, thanks for sharing!

  • Had not thought about targeting resource pools in monitoring workflows before now. This can be useful in certain types of operational tasks that you might want to run in the management group. Previously, I would have targeted the RMSE, but will now target a resource pool. Thanks for the idea :)

  • Back in November I blogged a variant of this that will make a SCOM-2007-safe MP. http://blogs.technet.com/b/omx/archive/2013/11/15/use-the-all-management-servers-resource-pool-to-run-scheduled-tasks.aspx Although I'm curious if/how you could target a different resource pool. For example, I have a group of gateways in a remote data center that are in a resource pool. How could I target their resource pool? I never figured that one out.

  • I created a couple of two-state script monitors targeting the AMSRP which works great, however, if I place one monitor into MMode, the entire pool goes into MMode. What targeting consideration am I missing?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
Search Blogs