- May 27th, 2010 – I wanted to tell you about a scenario I encountered recently and the thought process I went through as I attempted to build a group formula in XML in System Center Operations Manager 2007. If you’re like me, XML is not your first language. Actually, if you’re like me, XML is my second language either. However, I do believe this can be overcome…it takes some practice and repetition and winning small battles over time. I’ll share with you a thought process that incorporates natural language evaluation of the required formula along with a couple of great resources I found I believe will help you make more sense of the process. XML in plain English….so to speak.
I will warn you that you must either understand the relationships between existing classes are working with or have the MP viewer and the management packs handy to look them up… anybody can do that easily.
This was our challenge. We had Windows servers belonging to different departments, and each group wanted to handle their tuning separately. Additionally, they wanted a number of common objects on these servers, such as SQL databases, web sites and logical disks hosted on these servers, dynamically grouped (per department) as part of a fully automated process.
Segmenting the Servers
Step one was to find which servers belong to which departments. This is easily handled by incorporating a custom registry key(s) and/or value into the server build process. This gave us a basis for a custom class that we could then use to group servers by department (unique key / class for each dept)
Step two is more challenging…. dynamically grouping SQL databases or IIS websites by department. Since we’re not grouping computers, going to create an instance group in the authoring console using an XML group population formula created in notepad. This is challenging because or custom class is outside the chain of containment (hosting) relationships inherently present the Microsoft management packs. We considered custom classes derived from computer rules and from the objects themselves, but nothing resulted in a simple group population formulas for the objects we needed to group that could be easily assembled in the Operations console. That being said, we used Windows Computer Role as a base (Local Application would work equally well).
Pondering the Possibilities with GroupCalc
While he didn’t have an example that fit my scenario, Mike Eisenstein had an explanation for advanced formula construction with the GroupCalc provider that really struck a chord with me (available HERE). I think it was Albert Einstein who said “if you can’t explain it simply, then you don’t understand the problem”. Mike clearly understands the challenge very well and proves this in several well explained examples. Truly a brilliant guy. The most important thing he said in the article from my perspective is this:
“The GroupCalc provider is actually a database query, so it’s not a coincidence that the syntax can be mapped to SQL.”
What this tells us if we can state in pseudo code what we require, we can easily adapt some XML from existing sources to build what at first glance seem to be very complicated formulas. Let’s apply that to the scenario described above.
Describing the Formula for GroupCalc in Plain English (or language of your choice)
In the end, we needed to build groups that dynamically grouped objects based on a formula that in plain English, reads something like this in pseudo (and pictured below):
- populate my group with SQL 2008 databases
- equal to the databases that are contained by SQL instances
- which are hosted by Windows Computers
- which contain my custom class
I’ve basically described here the chain of containment that leads me from my custom class to the databases I need to add to the group…
Now let’s write the formula for each step of the pseudo code above.
Writing the GroupCalc Formula
NOTE: If you want a downloadable copy of this formula, see the attachment on our original forum discussion HERE.
1. populate my group with SQL 2008 databases (the MembershipRule)
<RuleId>$MPElement$</RuleId><br /><GroupInstanceId>$Target/Id$</GroupInstanceId><br /><MembershipRules><br /> <MembershipRule><br /> <MonitoringClass>$MPElement[Name=<span style="color: #006080;">'MicrosoftSQLServer2008Discovery!Microsoft.SQLServer.2008.Database'</span>]$</MonitoringClass><br /> <RelationshipClass>$MPElement[Name=<span style="color: #006080;">'MicrosoftSystemCenterInstanceGroupLibrary!Microsoft.SystemCenter.InstanceGroupContainsEntities'</span>]$</RelationshipClass>
2. equal to the databases that are contained by SQL instances (represented by the SQL DB Engine class)
<Expression><br /> <Contained><br /> <MonitoringClass>$MPElement[Name=<span style="color: #006080;">'MicrosoftSQLServer2008Discovery!Microsoft.SQLServer.2008.DBEngine'</span>]$</MonitoringClass>
3. which are contained (hosted) by Windows Computers
<Expression><br /> <Contained><br /> <MonitoringClass>$MPElement[Name=<span style="color: #006080;">'Windows!Microsoft.Windows.Computer'</span>]$</MonitoringClass>
4. which contains my custom class (which is my class based on registry keys to ID the dept that owns the server)
<Expression><br /> <Contains><br /> <MonitoringClass>$MPElement[Name=<span style="color: #006080;">'My.Custom.Class'</span>]$</MonitoringClass>
5. and here’s the remaining XML… and just the closing tags for the expressions we started above
Again, to download the xml code snippet, log into systemcentercentral.com and grab the txt file attached in my last comment on this thread - http://www.systemcentercentral.com/tabid/60/indexId/67720/tag/Forums+MP_Development/Default.aspx#vindex67776
And your next step is to add this into an instance group. Microsoft guru Jonathan Almquist has this covered very nicely, so I’ll not duplicate his work here.
How to Create an Instance Group in the Authoring Console
Here’s the step-by-step from Jonathan Almquist on how to make this happen in the Authoring console.
The XML you need for your instance group is attached to this post (login to download). A step-by-step for creating an instance group is available at http://blogs.technet.com/b/jonathanalmquist/archive/2010/05/08/how-to-create-an-instance-group-in-the-r2-authoring-console.aspx
Feedback and Questions
I’d love to hear not only your feedback, but your grouping challenges…I’d like to further Explorer the demystification of GroupCalc and XML with you. Post your object grouping challenges, whatever they may be, to the MP Development forums at SystemCenterCentral.com and we’ll explore the possibilities.
Follow System Center Central
Sponsors and Supporters
Become an IRON CHEF in the System Center community. Enter the MANAGEMENT PACK EXTENSION CONTEST for a chance to win fame and fortune!