Logical Expressions and Regular Expressions
CCS supports logical expressions and regular expressions for more-complex value matching and triggering only when two or more conditions are met.
Consider the following statement:
Trigger-Filter:
$adminMode ne "trunk" and $operMode ne "trunk"
The scripting statement calls two variables ($adminMode
and $operMod
e). In this case, both are well-known variables. The logical and operator determines that the match applies only if both variable values (a show interface operation listing the administrative mode and operational mode for a switch port) do not reflect the stated equivalence of "trunk
", and because the statement is part of a trigger-filter
, the corresponding
Trigger-Section
is called by the script.
Valid Boolean logical operators include:
-
and
(&&) -
or
(| |)
The meta characters that can be used to build regular expressions for CCS scripts include the following:
| | OR operator. Provides alternatives for matching. The left side of the | may match, or the right side may. To be meaningful, it must be enclosed by parentheses “( ).” |
* | Match the preceding item 0 to n times, of a character or set of characters. Classic wildcard operator. |
[ ] | (Square brackets) Set an inclusive range of values or an inclusive operation within a pattern, or a match against alternatives. |
{ } | (Curly brackets) Allows matching against a specific number of occurrences of a pattern, a range defining the minimum and maximum number of instances to match against, and a starting value for n to infinite matches for a pattern. Its function is related to the + and * operators. |
( ) | Enables matching against one of a set of alternatives, if combined with the OR operator (|). |
+ | 1 to n occurrences of a character or set of characters. |
^ | Boolean NOT operator. Prevents a specified character, delimiter, value or string from being included in a match within the specified pattern. |
/<pattern>/ | Encloses the pattern/regular expression to be compared against the fetched value in the variable $_. |
. | Matches any single character. |
" " | Double quote marks enclose the entire pattern to match. |
A string variable with a regex may be used to match against multiple instances of similar values in the same variable:
Trigger-Variables:
$ifName "/FastEthernet[^ ]*/"
A Perl-style regex is used to define $ifName
. First, the entire string is enclosed in quote marks (“”) to ensure that the entire string, including any spacebar characters (such as you would see in a Cisco int FastEthernet0/11
command string) is treated as a single parameter when declaring the variable.
/FastEthernet[^ ]*/
The two forward slashes encapsulate the full string to match against, which contains a regular expression.
FastEthernet[^ ]*
An extensive discussion of regular expressions is beyond the scope of this document; CCS supports the same conventions for regular expressions as the Perl language.