Article ID: 2702651 - View products that this article applies to.
The authoring of management packs may need to include regular expression matching in discoveries and groups, as well as for pattern matching in expression criteria in monitors and rules.
There are two different types of regular expression support in the SCOM product, and you have to know which element you are working in to choose the correct one. Specifically, Group membership calculation and expression filters use distinctly different syntaxes for pattern matching.
Group calculation uses PERL regular expression syntax. By default the matching is case insensitive, but in the XML you can specify that an expression needs to be case sensitive by way of a special attribute dedicated to specifying that the expression content should be evaluated in a case sensitive way. For more information please see http://msdn.microsoft.com/en-us/library/hh135104.aspx.
Group Calculation is found in your MP whenever you are using the Group Calc module.
The GroupCalc expression has an operator called MatchesRegularExpression that is used to create dynamic group membership based on pattern matching expressions. The implementation of this operator passes the expression found in the MP XML to the SQL call name dbo.fn_MatchesRegularExpression. If this call returns 0, the match is false. If the expression returns 1, the match is true.
GroupCalc also supports two special sub-elements that abstract away a couple of common regex style queries.
Table 1: GroupCalc special functions
Note: If either of these two special operators are used, the evaluation will always be case sensitive.
Expression Filter matching criteria
Expression filters used in management packs use .NET Regex expression syntax. A summary of the .NET regular expression syntax elements appears below. Expression filters are present in your management pack whenever you are using the Expression Eval module.
Table 2: SCOM Regex syntax
Regular expressions via SDK
The SCOM SDK has a Matches criteria operator for filtering objects. This operator use the same functionality as MatchesCriteria in the GroupCalc case explained above.
When using the SDK to construct a criteria expression to find objects in the Ops Manager database, the following syntax elements are valid (see below). This syntax is useful when creating a criteria expression that includes any of the following elements:
· Comparison operators
· Wildcard characters
· DateTime values
· Integer to XML Enumeration comparisons
You can use comparison operators when constructing a criteria expression. The valid operators are described in the following table:
Table 3: SDK comparison operators
The following table defines the wildcard characters you can use to construct a pattern when using the LIKE operator:
Table 4: Wildcard operators used with LIKE operator
When you use a DateTime value in a query expression, use the general DateTime format ("G") to convert the DateTime value to a string value. For example,
string qStr = "TimeCreated <= '" + myInstant.ToString("G") + "'";
ManagementPackCriteria mpCriteria = new ManagementPackCriteria(qStr);
All date values need to be converted to the G format (GMT) so that valid string comparisons can be made.
Integer value comparison to enumerations
When you use an integer enumeration value in a query expression, cast the enumeration value to an integer. For example,
string qStr = "Severity > " + (int)ManagementPackAlertSeverity.Warning;
MonitoringAlertCriteria alertCriteria = new MonitoringAlertCriteria(qStr);
(http://go.microsoft.com/fwlink/?LinkId=151500)for other considerations.
Article ID: 2702651 - Last Review: June 10, 2013 - Revision: 4.0