Constants
Following the overview is an optional constants section. Each constant takes the form:
name := expression;
The name is a valid variable name; the expression is a literal or any expression that depends only on other constants previously declared in the pattern. Named constants are available in the subsequent trigger, body and removal sections. Constant values are not available outside the pattern in which they are declared.
Constants should be used for values that are likely to be changed by pattern authors, such as regular expressions to extract versions from paths, and so on. They should not be used for values that are expected to be changed by normal users of the pattern — in those situations, a Pattern Configuration block should be used.
For example, this defines two regular expressions to be used in the pattern body:
constants cmd_expr := regex "Xvnc"; display_expr := regex "\b:\(\[0-9\]+)\b"; end constants;
Referencing pattern constants
From TPL version 1.5 (BMC Discovery 8.2) it is possible to reference constants defined in one pattern from other patterns.
In the first pattern Tomcat 1.0
the constant Tomcat.si_type
is defined.
tpl 1.5 module ApacheFoundation.Tomcat; pattern Tomcat 1.0 '''Define contains constants which we want to use elsewhere.''' [...] constants si_type := 'Apache Tomcat Application Server'; end constants; [...] end pattern
In the second code sample, the Tomcat 1.0
pattern is imported and in the ExtendedTomcat 1.0
pattern the Tomcat.si_type
is referenced.
tpl 1.5 module ApacheFoundation.ExtendedTomcat; from ApacheFoundation.Tomcat import Tomcat 1.0; pattern ExtendedTomcat 1.0 '''Use specified constant.''' [...] triggers on process := DiscoveredProcess where type := Tomcat.si_type; end triggers; [...] end pattern
Comments
Log in or register to comment.