Creating OpsMgr Instance Group for All Computers Running an Application and Their Health Service Watchers
OK, the title of this blog is pretty long, but please let me explain what I’m trying to do here. In OpsMgr, it’s quite common to create an instance group which contains some computer objects as well as the Health Service Watchers for these computers. This kind of groups can be used for alert subscriptions, overrides, and also maintenance mode targets.
There are many good posts around this topic, i.e.
- From Tim McFadden: Dynamic Computer groups that send heartbeat alerts
- From Kevin Holman: Creating Groups of Health Service Watcher Objects based on other Groups
Yesterday, I needed to create several groups that contains computer and health service watcher objects for:
- All Hyper-V servers
- All SQL servers
- All Domain Controllers
- All ConfigMgr servers
Because all the existing samples I can find on the web are all based on computer names, so I thought I’ll post how I created the groups for above mentioned servers. In this post, I will not go through the step-by-step details of how to create these groups, because depending on the authoring tool that you are using the steps are totally different. But I will go through what the actual XML looks like in the management pack.
Step 1: Create the group class
This is straightforward, because this group will not only contain computer objects, but also the health service watcher objects, we must create an instance group.
i.e. Using SQL servers as an example, the group definition looks like this:
<TypeDefinitions>
<EntityTypes>
<ClassTypes>
<ClassType ID="TYANG.SQL.Server.Computer.And.Health.Service.Watcher.Group" Accessibility="Public" Abstract="false" Base="MSIL!Microsoft.SystemCenter.InstanceGroup" Hosted="false" Singleton="true" />
</ClassTypes>
</EntityTypes>
</TypeDefinitions>
Note: the MP alias “MSIL” is referencing “Microsoft.SystemCenter.InstanceGroup.Library” management pack.
Step 2: Find the Root / Seed Class from the MP for the specific application
Most likely, the application that you are working on (for instance, SQL server) is already defined and monitored by another set of management packs. Therefore, you do not have to define and discover these servers by yourself. The group discovery for the group you’ve just created need to include:
- All computers running any components of the application (in this instance, SQL Server).
- And all Health Service Watcher objects for the computers listed above.
In any decent management packs, when multiple application components are defined and discovered, most likely, the management pack author would define a root (seed) class, representing a computer that runs any application components (in this instance, we refer this as the “SQL server”). Once an instance of this seed class is discovered on a computer, there will be subsequent discoveries targeting this seed class that discovers any other application components (using SQL as example again, these components would be DB Engine, SSRS, SSAS, SSIS, etc.).
So in this step, we need to find the root / seed class for this application. Based on what I needed to do, the seed classes for the 4 applications I needed are listed below:
- SQL Server:
- Source MP: Microsoft.SQLServer.Library
- Class Name: Microsoft.SQLServer.ServerRole
- Alias in my MP: SQL
- HyperV Server:
- Source MP: Microsoft.Windows.HyperV.Library
- Class Name: Microsoft.Windows.HyperV.ServerRole
- Alias in my MP: HYPERV
- Domain Controller:
- Source MP: Microsoft.Windows.Server.AD.Library
- Class Name: .Windows.Server.AD.DomainControllerRole
- Alias in my MP: AD
- ConfigMgr Server
- Source MP: Microsoft.SystemCenter2012.ConfigurationManager.Library
- Class Name: Microsoft.SystemCenter2012.ConfigurationManager.Server
- Alias in my MP: SCCM
Tip: you can use MPViewer to easily check what classes are defined in a sealed MP. Use SQL as example again, in the Microsoft.SQLServer.Library:
You can easily identify that “SQL Role” is the seed class because it is based on Microsoft.Windows.ComputerRole and other classes use this class as the base class. You can get the actual name (not the display name) from the “Raw XML” tab.
Step 3: Create MP References
Your MP will need to reference the instance group library, as well as the MP of which the application seed class is defined (i.e. SQL library):
Step 4: Create the group discovery
The last component we need to create is the group discovery.The Data Source module for the group discovery is Microsoft.SystemCenter.GroupPopulator, and there will be 2
As shown above, I’ve translated each membership rule to plain English. And the XML is listed below. If you want to reuse my code, simply change the line I highlighted in above screenshot to suit your needs.
<Monitoring>
<Discoveries>
<Discovery ID="TYANG.SQL.Server.Computer.And.Health.Service.Watcher.Group.Discovery" Enabled="true" Target="TYANG.SQL.Server.Computer.And.Health.Service.Watcher.Group" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryRelationship TypeID="MSIL!Microsoft.SystemCenter.InstanceGroupContainsEntities" />
</DiscoveryTypes>
<DataSource ID="DS" TypeID="SC!Microsoft.SystemCenter.GroupPopulator">
<RuleId>$MPElement$</RuleId>
<GroupInstanceId>$MPElement[Name="TYANG.SQL.Server.Computer.And.Health.Service.Watcher.Group"]$</GroupInstanceId>
<MembershipRules>
<MembershipRule>
<MonitoringClass>$MPElement[Name="Windows!Microsoft.Windows.Computer"]$</MonitoringClass>
<RelationshipClass>$MPElement[Name="MSIL!Microsoft.SystemCenter.InstanceGroupContainsEntities"]$</RelationshipClass>
<Expression>
<Contains>
<MonitoringClass>$MPElement[Name="SQL!Microsoft.SQLServer.ServerRole"]$</MonitoringClass>
</Contains>
</Expression>
</MembershipRule>
<MembershipRule>
<MonitoringClass>$MPElement[Name="SC!Microsoft.SystemCenter.HealthServiceWatcher"]$</MonitoringClass>
<RelationshipClass>$MPElement[Name="MSIL!Microsoft.SystemCenter.InstanceGroupContainsEntities"]$</RelationshipClass>
<Expression>
<Contains>
<MonitoringClass>$MPElement[Name="SC!Microsoft.SystemCenter.HealthService"]$</MonitoringClass>
<Expression>
<Contained>
<MonitoringClass>$MPElement[Name="Windows!Microsoft.Windows.Computer"]$</MonitoringClass>
<Expression>
<Contained>
<MonitoringClass>$Target/Id$</MonitoringClass>
</Contained>
</Expression>
</Contained>
</Expression>
</Contains>
</Expression>
</MembershipRule>
</MembershipRules>
</DataSource>
</Discovery>
</Discoveries>
</Monitoring>
Result
After I imported the MP into my lab management group, all the SQL computer and Health Service Watcher objects are listed as members of this group:
Leave a comment