HP Operations Manager for Windows

User-defined variables in patterns


Any matched string can be assigned to a variable, which can be used to compose messages or used as a parameter for action calls. To define a parameter, add ". parametername " before the closing bracket. The pattern:

	^errno: <#.number> - <*.error_text>

matches a message such as:

	errno: 125 - device does not exist 

and assigns "125" to number and "device does not exist" to error_text.

When using these variables, the syntax is <variable_name> (for example, <number>).

Rules by which HP Operations assigns strings to variables

In matching the pattern <*.var1><*.var2> against the string "abcdef", it is not immediately clear which substring of the input string will be assigned to each variable. For example, it is possible to assign an empty string to var1 and the whole input string to var2, as well as assigning "a" to var1 and "bcdef" to var2, and so forth.

HP Operations' pattern matching algorithm always scans both the input line and the pattern definition (including alternative expressions) from left to right. <*> expressions are assigned as few characters as possible. <#>, <@>, <S> expressions are assigned as many characters as possible. Therefore, var1 will be assigned an empty string in the example above.

To match an input string such as:

	this is error 100: big bug

use a pattern such as:

	error<#.errnumber>:<*.errtext>

In which:

For performance and pattern readability purposes, you can specify a delimiting substring between two expressions. In the above example, ":" is used to delimit <#> and <*>.

Matching <@.word><#.num> against "abc123" assigns "abc12" to word and "3" to num, as digits are permitted for both <#> and <@>, and the left expression takes as many characters as possible.

Patterns without expression anchoring can match any substring within the input line. Therefore, patterns such as:

	this is number<#.num>

are treated in the same way as:

	<*>this is number<#.num><*>
Using subpatterns to assign strings to variables

In addition to being able to use a single operator, such as * or #, to assign a string to a variable, you can also build up a complex subpattern composed of a number of operators, according to the following pattern: <[ subpattern ].var>

For instance: <[<@>file.tmp].fname>

In the example above, the period ( . ) between "file" and "tmp" matches a similar dot character, while the dot between "]" and "fname" is necessary syntax. This pattern would match a string such as "Logfile.tmp" and assigns the complete string to fname.

Other examples of subpatterns are:

In the first example above, any line with either the word "Error" or the word "Warning" is assigned to the variable, sev. In the second example, any line containing the word "Error" has the error number assigned to the variable, n, and any further text assigned to msg. Finally, both number and text are assigned to complete.

Related Topics: