Export (0) Print
Expand All

ExpressionType

System Center

Updated: August 10, 2011

Applies To: Operations Manager 2007 R2

ExpressionType complex data type defines an expression that can be evaluated to either true or false.


<xsd:complexType name="ExpressionType">
  <xsd:choice minOccurs="0" maxOccurs="1">
    <xsd:element name="SimpleExpression" type="SimpleCriteriaType"/>
    <xsd:element name="DayTimeExpression" type="DayTimeCriteriaType"/>
    <xsd:element name="RegExExpression" type="RegExCriteriaType"/>
    <xsd:element name="And" type="AndType"/>
    <xsd:element name="Or" type="OrType"/>
    <xsd:element name="Not" type="NotType"/>
    <xsd:element name="Exists" type="ExistsType"/>
  </xsd:choice>
</xsd:complexType>

The ExpressionType schema allows for many different comparison scenarios.

The basic expression types that can be combined with logical operators are described in the following table.

 

Expression Type Description

SimpleExpression

Evaluates two values by using a simple comparison (equal, not equal, less than, greater than, less than or equal, greater than or equal). The two values can be cast to the appropriate type for comparison.

DayTimeCriteriaType

Evaluates one date value against a defined date range.

RegexExpression

Evaluates one value against a regular expression or a wildcard expression; or searches for a substring.

For more information about the SimpleExpression parameter, see SimpleCriteriaType.

DayTimeExpression

The DayTimeExpression type evaluates a date value expression to determine whether it is either within or outside of the specified date range on the specified days.

The Value element must always be of type DateTime, as in the following sample.


<Expression>
  <DayTimeExpression>
    <ValueExpression>
      <Value Type="DateTime">2005-03-30T14:00:00.0000000Z</Value>
    </ValueExpression>
    <StartTime>46800</StartTime>
    <EndTime>86399</EndTime>
    <Days>15</Days>
    <InRange>true</InRange>
  </DayTimeExpression>
</Expression>

The StartTime element specifies the start time of the range in seconds.

The EndTime element specifies the end time of the range in seconds.

The Days element represents the days in which the specified date range is to occur. You can specify either one or multiple days. The Days element in the preceding sample includes Sunday, Monday, Tuesday, and Wednesday.

 

Day Value

Sunday

1

Monday

2

Tuesday

4

Wednesday

8

Thursday

16

Friday

32

Saturday

64

To specify a single day, enter the enumerator value for that day directly into the Days configuration element.

To specify multiple days, add the enumerator values for the days together. For example, for Monday, Wednesday, and Friday, specify 42 (2+8+32).

You can specify multiple days and times to execute on by using the weekly schedule. Any number of daily elements can be added to the configuration.

If the InRange element is true, the expression will return true only if the Value element exists within the specified range. If the InRange element is false, it will return true only if the Value element does not exist within the specified range.

RegexExpression

The RegExExpression type compares a value expression (left side) to a wildcard or regular expression (right side). The value expression is specified in the same way as the simple expression described previously. The regular expression is specified by using a pattern element.

The allowed operators for regular expression comparisons are described in the following table.

 

Operator Description

MatchesWildcard

The expression evaluates as true if it matches the specified wildcard expression. The following wildcard characters are allowed:

  • # — represents a number [0–9].

  • ? — represents any single character.

  • * — represents any sequence of characters.

  • \ — escapes the following character; for example, \# is used to specify the # character.

ContainsSubstring

Expression evaluates as true if it contains the substring specified in the pattern. The pattern is mapped to a regular expression, such as "^.*EscapedPattern.*$".

MatchesRegularExpression

The expression evaluates as true if it matches the specified regular expression pattern. The regular expression evaluation uses the ATL regular expression engine.

DoesNotContainSubstring

The expression evaluates as true if it does not contain the substring specified in the pattern.

DoesNotMatchWildcard

The expression evaluates as true if it does not match the specified wildcard pattern.

DoesNotMatchRegularExpression

The expression evaluates as true if it does not match the specified regular expression pattern.

noteNote
Some Operations Manager 2005 comparison types are allowed in the operator for backward compatibility only. These should not be used for new management packs.

The following code shows an example of the use of the RegExExpression type:


<Expression>
  <RegExExpression>
    <ValueExpression>
      <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
    </ValueExpression>
    <Operator>MatchesRegularExpression</Operator>
    <Pattern>^(200|201|202|203)$</Pattern>
  </RegExExpression>
</Expression>

The two expression types in the preceding example can be combined to form multiple comparisons. For example, it would not be possible to compare the event ID and publisher name in an event data item in a single expression. Multiple expression types can be combined by using the logical operators, listed in the following table, between expression definitions:

 

Operator Element Description

And

Combines two or more expressions with a logical AND. All expressions contained in the And element must evaluate to true for the overall expression to evaluate to true; otherwise, the result is false.

Or

Combines two or more expressions with a logical OR. At least one expression contained in the Or element must evaluate to true for the overall expression to evaluate to true; otherwise, the result is false.

Not

Contains only a single expression. This element reverses the result of the contained expression, so if the contained expression returned true, the overall result would be false.

Multiple expression types are represented in the XML configuration with the operator as the element and then one or more expressions contained as sub-elements.

The following example shows how to combine two expressions in an AND operation:


<Expression>
  <And>
    <Expression>
      <SimpleExpression>
        <ValueExpression>
          <XPathQuery Type="String">PublisherName</XPathQuery>
        </ValueExpression>
        <Operator>Equal</Operator>
        <ValueExpression>
          <Value Type="String">EventCreate</Value>
        </ValueExpression>
      </SimpleExpression>
    </Expression>
    <Expression>
      <SimpleExpression>
        <ValueExpression>
          <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
        </ValueExpression>
        <Operator>Equal</Operator>
        <ValueExpression>
          <Value Type="UnsignedInteger">101</Value>
        </ValueExpression>
      </SimpleExpression>
    </Expression>
  </And>
</Expression>

There is no limit to how many expressions can be combined with a single operator. Multiple operators can be combined as required.

The following code shows example shows an AND expression contained within an OR expression:


<Expression>
  <Or>
    <Expression>
      <And>
        <Expression>
          <SimpleExpression>
            <ValueExpression>
              <XPathQuery Type="String">PublisherName</XPathQuery>
            </ValueExpression>
            <Operator>Equal</Operator>
            <ValueExpression>
              <Value Type="String">EventCreate</Value>
            </ValueExpression>
          </SimpleExpression>
        </Expression>
        <Expression>
          <SimpleExpression>
            <ValueExpression>
              <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
            </ValueExpression>
            <Operator>Equal</Operator>
            <ValueExpression>
              <Value Type="UnsignedInteger">101</Value>
            </ValueExpression>
          </SimpleExpression>
        </Expression>
      </And>
    </Expression>
    <Expression>
      <And>
        <Expression>
          <SimpleExpression>
            <ValueExpression>
              <XPathQuery Type="String">PublisherName</XPathQuery>
            </ValueExpression>
            <Operator>Equal</Operator>
            <ValueExpression>
              <Value Type="String">EventCreate</Value>
            </ValueExpression>
          </SimpleExpression>
        </Expression>
        <Expression>
          <RegExExpression>
            <ValueExpression>
              <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
            </ValueExpression>
            <Operator>MatchesRegularExpression</Operator>
            <Pattern>^(200|201|202|203)$</Pattern>
          </RegExExpression>
        </Expression>
      </And>
    </Expression>
  </Or>
</Expression>

The following code shows how the preceding example could be written logically:

(PublisherName = EventCreate AND EventDisplayNumber = 101) OR (PublisherName = EventCreate2 AND EventDisplayNumber Matches ^(200|201|202|203)$)

The following XML sample shows a collection by using a simple expression:


<Rule ID="Microsoft.Samples.CollectEvent101" Target="Microsoft.Samples.ApplicationX">
  <Category>AvailabilityHealth</Category>
  <DataSources>
    <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.EventProvider">
      <ComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
      <LogName>Application</LogName>
      <Expression>
        <And>
          <Expression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery Type="String">PublisherName</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="String">EventCreate</Value>
              </ValueExpression>
            </SimpleExpression>
          </Expression>
          <Expression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="UnsignedInteger">101</Value>
              </ValueExpression>
            </SimpleExpression>
          </Expression>
          <Expression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery Type="String">Params/Param[1]</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="String">$Target/Property[Type="Microsoft.Samples.ApplicationX"]/ServiceName$</Value>
              </ValueExpression>
            </SimpleExpression>
          </Expression>
        </And>
      </Expression>
    </DataSource>
  </DataSources>
  <WriteActions>
    <WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectEvent"/>
    <WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishEventData"/>
  </WriteActions>
</Rule>

 

   

Schema Type

System.ExpressionEvaluatorSchema

Library

System.Library

 
Show:
© 2014 Microsoft