Dyanamic Group Population by Subnet(s) in OpsMgr / SCE - Advanced Formula Examples

 

As you may be aware, Operations Manager and Essentials 2007 store the IP address for managed systems in Operational database in the IP Address property of the Windows Computer class. You will also find it in version-specific Windows Computer classes. But did you know you can use this information to dynamically populate computer groups in OpsMgr?

In this post, I’ll include advanced regular expressions as reference to illustrate dynamic grouping of computers in multiple subnets into a single group through a dynamic inclusion formula using regular expressions (this would have use, for example, in rolling up branch sites into a single group with their parent, or sites containing multiple contiguous subnets).

NOTE: I’ve included the regular expressions above the screen shots for easy cut-and-paste (and in case the regex is difficult to make out in the images).

Building the Regular Expression for the Dynamic Inclusion Formula

If you have one or two distinct subnets in a small network, it’s quite easy to group by a single subnet. For example, targeting the 192.168.1.0 / 24 subnet is shown in figure 0.

Figure 0 - Formula for dynamic population of a single class C subnet.

However, if you have many subnets in a large enterprise (where class A and B addressing schemes may exist) and/or need to dynamically populate computers from multiple subnets into a single group, dynamic group population using regular expressions can potentially be faster and more flexible.

Let’s take the following sample regular expression:

^10\.(22)\.(1)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

which would match the following IP address range 10.22.*.*

And to break down this query just a bit….

^ = matches beginning of string

\. = performs a literal match on the . (period) between the octets

(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) = This rather large string will match any number from 0-255.

And so, if repeated twice separated by a \. covers any value in the last two octets. I will break it down into the 3 possibilities for the given octet

(25[0-5] = 25 and any number from 0-5. This covers values 250-255

| = OR

2[0-4][0-9] = 2 plus any number 0-4 followed by any number 0-9. This covers values 200-249

| = OR

[01]?[0-9][0-9]? = 0 or 1 plus any number 0-9 zero or more times plus again any number 0-9 zero or more times. This addresses values of 0-199

$ = matches end of string

If you’re familiar with regex, you may note that \b could be used to replace ^ and $ in normal use, but I stick with ^ and $ when using regular expressions in OpsMgr, mostly for consistency.

Creating the Dynamic Inclusion Formula

So finally, how do we use this information to build a formula to populate a group? When pasted into the textbox provided on the “Create a Membership Formula” dialogue of an OpsMgr group, this would incorporate our regular expression above
into the following formula for group population, as shown below and in figure 1.

^10\.(22)\.(1)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Figure 1 - Formula for dynamic population of multiple subnets with IP address range 10.22.*.*

And you could concatenate multiple statements with the OR operator all day long to match multiple subnets. For example, the following would match all 10.22.1.* and 10.24.5.* addresses, as shown below and in figure 2.

OR
^10\.(22)\.(1)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
^10\.(24)\.(5)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Figure 2 - Formula for dynamic population of multiple subnets with IP address ranges 10.22.1.* and 10.24.5.*

If your subnets only differ in one octet, it is easier than that. For example, to match subnets
10.22.1.0\24 and 10.22.2.0\24 in a formula, we’d need simply to use the OR operator | to define the
third octet, as shown below and in figure 3:

^10\.(22)\.(1|2)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Figure 3 - Formula for dynamic population of multiple subnets - 10.22.1.0\24 and 10.22.2.0\24

And of course with the OR operator we can address multiple formulas if necessary.

Conclusion

Hope you find this helpful. Comments, questions, ideas or corrections are welcome via e-mail at administrator [AT] systemcenterforum.org or the Contact Page.

——————

Get System Center Operations Manager and Essentials 2007 training from the system center experts. We now offer classroom training for System Center Essentials 2007.

Leave a Reply

privacy policy | terms of use | copyright © 2008 pete zerger