CONSTRAINT Command

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:

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