Use CONSTRAINT commands to add conditional logic to the pattern-matching process.
Format
CONSTRAINT expression
where expression provides the conditional logic for pattern matching to occur. The expression must evaluate to true for the pattern to match the message.
Expressions are described in 5.1.
Rules for Using CONSTRAINT Command
Observe the following rules when using the CONSTRAINT command:
You can include any number of CONSTRAINT commands in a pattern.
You can use CONSTRAINT commands in addition to or instead of TOKEN commands. If TOKEN and CONSTRAINT commands appear in the same pattern, TOKEN commands are evaluated first.
The CONSTRAINT command uses an expression to constrain pattern matching. The result of the expression must be true for the pattern to match the message. If the result of the expression is false, the pattern is not matched.
You cannot use masking within a CONSTRAINT expression.
If you have more than one CONSTRAINT command in a pattern, the expression in each CONSTRAINT command must evaluate to true for the pattern to match the message.
Pattern matching does not succeed in the event of a run-time error while evaluating the CONSTAINT wxpression, such as an invalid token number reference.
Do not refer to the variable _STATUS or _ERRORS (see Section 3) in a CONSTRAINT command because AMS resets the values of _STATUS and _ERRORS before matching the next message.
CP-AMS/SP-AMS Example
The following example shows part of a pattern that requires that the string "ABC" be the value of either the third or fourth token from the end of the message. In this example, parentheses are not required for the order of precedence, but they make the expression easier to understand.
CONSTRAINT (_NEGTOKEN3 = "ABC") | (_NEGTOKEN4 = "ABC")
SP-AMS Examples
The following example shows part of a pattern that matches a file system free space message associated with the root file system on host "sp-1" or host "un20", where the file system is more than 90 percent utilized. In the MESSAGE command of the pattern, %used is token number 6.
DEFINE "filesystem" MESSAGE "/ /dev/root <blocks> <used> <free> %used" /* *1*-----2---*----3---*---4--*---5--*--6--* */ TOKEN KEYWORD 2 CONSTRAINT ( \_HOSTID\ = "sp-1" │ \_HOSTID\ = "un20") CONSTRAINT #\ _TOKEN6 "%" 1\ >90
In the first constraint, the value of the predefined variable _HOSTID (see Section 3) is the name of the host that sent the message. The backslashes around this predefined variable are optional since the variable is not inside a string. The parentheses around the expression, ( \_HOSTID\ = "sp-1" │ \_HOSTID\ = "un20"), are also optional. The vertical bar, │, indicates that the constraint is satisfied if either part of the expression is true.
The second constraint uses the value of the sixth token as a number. The % character is a delimiter that is used to extract the numeric part of the token. The # operator converts the value from a character string to a numeric value. For example, if the token %used were 92%, the second constraint would be satisfied because 92 is greater than 90. If the second token of the message was "/dev/root" and both constraints were satisfied, the pattern would match the message.
The following example shows part of a pattern that matches a message when the name of the host that sent the message exists as a member of the variable group HostidList:
CONSTRAINT ?HostidList:HOSTID