Signature:
- function regex(pattern, text)
+ function regex(pattern, value, mode)
-Returns true if the regular expression matches the text, false otherwise. The mode argument is
-optional and can be either MatchAll (in which case all elements for an array have to match) or MatchAny
-(in which case at least one element has to match). The default mode is MatchAll.
+Returns true if the regular expression `pattern` matches the `value`, false otherwise.
+The `value` can be of the type [String](#string-type) or [Array](#array-type) (which
+contains string elements).
+
+The `mode` argument is optional and can be either `MatchAll` (in which case all elements
+for an array have to match) or `MatchAny` (in which case at least one element has to match).
+The default mode is `MatchAll`.
**Tip**: In case you are looking for regular expression tests try [regex101](https://regex101.com).
-Example:
+Example for string values:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => host.vars.os_type = "Linux/Unix"
null
<2> => regex("^Linux", host.vars.os_type)
<3> => regex("^Linux$", host.vars.os_type)
false
+Example for an array of string values:
+
+ $ icinga2 console
+ Icinga 2 (version: v2.7.0)
+ <1> => host.vars.databases = [ "db-prod1", "db-prod2", "db-dev" ]
+ null
+ <2> => regex("^db-prod\\d+", host.vars.databases, MatchAny)
+ true
+ <3> => regex("^db-prod\\d+", host.vars.databases, MatchAll)
+ false
+
+
### match <a id="global-functions-match"></a>
Signature:
function match(pattern, text, mode)
-Returns true if the wildcard (`?*`) pattern matches the text, false otherwise. The mode argument is
-optional and can be either MatchAll (in which case all elements for an array have to match) or MatchAny
-(in which case at least one element has to match). The default mode is MatchAll.
+Returns true if the wildcard (`?*`) `pattern` matches the `value`, false otherwise.
+The `value` can be of the type [String](#string-type) or [Array](#array-type) (which
+contains string elements).
-Example:
+The `mode` argument is optional and can be either `MatchAll` (in which case all elements
+for an array have to match) or `MatchAny` (in which case at least one element has to match).
+The default mode is `MatchAll`.
+
+Example for string values:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
- <1> => host.display_name = "NUE-DB-PROD-586"
+ Icinga 2 (version: v2.7.0)
+ <1> => var name = "db-prod-sfo-657"
null
- <2> => match("NUE-*", host.display_name)
+ <2> => match("*prod-sfo*", name)
true
- <3> => match("*NUE-*", host.display_name)
- true
- <4> => match("NUE-*-DEV-*", host.display_name)
+ <3> => match("*-dev-*", name)
false
+Example for an array of string values:
+
+ $ icinga2 console
+ Icinga 2 (version: v2.7.0-28)
+ <1> => host.vars.application_types = [ "web-wp", "web-rt", "db-local" ]
+ null
+ <2> => match("web-*", host.vars.application_types, MatchAll)
+ false
+ <3> => match("web-*", host.vars.application_types, MatchAny)
+ true
+
+
### cidr_match <a id="global-functions-cidr_match"></a>
Signature:
- function cidr_match(pattern, ip)
+ function cidr_match(pattern, ip, mode)
Returns true if the CIDR pattern matches the IP address, false otherwise.
+
IPv4 addresses are converted to IPv4-mapped IPv6 addresses before being
-matched against the pattern. The mode argument is optional and can be
-either MatchAll (in which case all elements for an array have to match) or MatchAny
-(in which case at least one element has to match). The default mode is MatchAll.
+matched against the pattern. The `mode` argument is optional and can be
+either `MatchAll` (in which case all elements for an array have to match) or `MatchAny`
+(in which case at least one element has to match). The default mode is `MatchAll`.
-Example:
+Example for a single IP address:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => host.address = "192.168.56.101"
null
<2> => cidr_match("192.168.56.0/24", host.address)
<3> => cidr_match("192.168.56.0/26", host.address)
false
+Example for an array of IP addresses:
+
+ $ icinga2 console
+ Icinga 2 (version: v2.7.0)
+ <1> => host.vars.vhost_ips = [ "192.168.56.101", "192.168.56.102", "10.0.10.99" ]
+ null
+ <2> => cidr_match("192.168.56.0/24", host.vars.vhost_ips, MatchAll)
+ false
+ <3> => cidr_match("192.168.56.0/24", host.vars.vhost_ips, MatchAny)
+ true
+
### range <a id="global-functions-range"></a>
Signature:
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => range(5)
[ 0.000000, 1.000000, 2.000000, 3.000000, 4.000000 ]
<2> => range(2,4)
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => host.groups = [ "linux-servers", "db-servers" ]
null
<2> => host.groups.len()
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => var dev_notification_groups = [ "devs", "slack" ]
null
<2> => var host_notification_groups = [ "slack", "noc" ]
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => var dev_notification_groups = [ "devs", "slack" ]
null
<2> => var host_notification_groups = [ "slack", "noc" ]
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => host.vars.disks["/"] = {}
null
<2> => host.vars.disks["/var"] = {}
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => 5.to_string()
"5"
<2> => false.to_string()
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => number(false)
0.000000
<2> => number("78")
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => bool(1)
true
<2> => bool(0)
Returns a random value between 0 and RAND\_MAX (as defined in stdlib.h).
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => random()
1263171996.000000
<2> => random()
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => log(LogCritical, "Console", "First line")
critical/Console: First line
null
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => typeof(3) == Number
true
<2> => typeof("str") == String
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => get_time()
1480072135.633008
<2> => get_time()
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => var pd = "'time'=1480074205.197363;;;"
null
<2> => parse_performance_data(pd)
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => var path = "/etc/icinga2/scripts/xmpp-notification.pl"
null
<2> => dirname(path)
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => var path = "/etc/icinga2/scripts/xmpp-notification.pl"
null
<2> => basename(path)
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => escape_shell_arg("'$host.name$' '$service.name$'")
"''\\''$host.name$'\\'' '\\''$service.name$'\\'''"
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => escape_shell_cmd("/bin/echo 'shell test' $ENV")
"/bin/echo 'shell test' \\$ENV"