-# <a id="library-reference"></a> Library Reference
+# Library Reference <a id="library-reference"></a>
-## <a id="global-functions"></a> Global functions
+## Global functions <a id="global-functions"></a>
-These functions are globally available in [assign/ignore where expressions](3-monitoring-basics.md#using-apply-expressions),
+These functions are globally available in [assign/ignore where expressions](03-monitoring-basics.md#using-apply-expressions),
[functions](17-language-reference.md#functions), [API filters](12-icinga2-api.md#icinga2-api-filters)
and the [Icinga 2 debug console](11-cli-commands.md#cli-command-console).
as a sandbox to test these functions before implementing
them in your scenarios.
-### <a id="global-functions-regex"></a> regex
+### regex <a id="global-functions-regex"></a>
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](18-library-reference.md#string-type) or [Array](18-library-reference.md#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
-### <a id="global-functions-match"></a> match
+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](18-library-reference.md#string-type) or [Array](18-library-reference.md#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
-### <a id="global-functions-cidr_match"></a> cidr_match
+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
-### <a id="global-functions-range"></a> range
+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)
<3> => range(2,10,2)
[ 2.000000, 4.000000, 6.000000, 8.000000 ]
-### <a id="global-functions-len"></a> len
+### len <a id="global-functions-len"></a>
Signature:
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()
10.000000
-### <a id="global-functions-union"></a> union
+### union <a id="global-functions-union"></a>
Signature:
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" ]
<3> => union(dev_notification_groups, host_notification_groups)
[ "devs", "noc", "slack" ]
-### <a id="global-functions-intersection"></a> intersection
+### intersection <a id="global-functions-intersection"></a>
Signature:
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" ]
<3> => intersection(dev_notification_groups, host_notification_groups)
[ "slack" ]
-### <a id="global-functions-keys"></a> keys
+### keys <a id="global-functions-keys"></a>
Signature:
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"] = {}
<3> => host.vars.disks.keys()
[ "/", "/var" ]
-### <a id="global-functions-string"></a> string
+### string <a id="global-functions-string"></a>
Signature:
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => 5.to_string()
"5"
<2> => false.to_string()
<6> => DateTime(2016, 11, 25).to_string()
"2016-11-25 00:00:00 +0100"
-### <a id="global-functions-number"></a> number
+### number <a id="global-functions-number"></a>
Signature:
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => number(false)
0.000000
<2> => number("78")
78.000000
-### <a id="global-functions-bool"></a> bool
+### bool <a id="global-functions-bool"></a>
Signature:
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => bool(1)
true
<2> => bool(0)
false
-### <a id="global-functions-random"></a> random
+### random <a id="global-functions-random"></a>
Signature:
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()
108402530.000000
-### <a id="global-functions-log"></a> log
+### log <a id="global-functions-log"></a>
Signature:
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
critical/Console: ["devs","slack"]
null
-### <a id="global-functions-typeof"></a> typeof
+### typeof <a id="global-functions-typeof"></a>
Signature:
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => typeof(3) == Number
true
<2> => typeof("str") == String
<5> => typeof({ a = 2, b = 3 }) == Dictionary
true
-### <a id="global-functions-get_time"></a> get_time
+### get_time <a id="global-functions-get_time"></a>
Signature:
Example:
$ icinga2 console
- Icinga 2 (version: v2.6.0)
+ Icinga 2 (version: v2.7.0)
<1> => get_time()
1480072135.633008
<2> => get_time()
1480072140.401207
-### <a id="global-functions-parse_performance_data"></a> parse_performance_data
+### parse_performance_data <a id="global-functions-parse_performance_data"></a>
Signature:
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)
warn = null
}
-### <a id="global-functions-dirname"></a> dirname
+### dirname <a id="global-functions-dirname"></a>
Signature:
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)
"/etc/icinga2/scripts"
-### <a id="global-functions-basename"></a> basename
+### basename <a id="global-functions-basename"></a>
Signature:
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)
"xmpp-notification.pl"
-### <a id="global-functions-escape_shell_arg"></a> escape_shell_arg
+### path\_exists <a id="global-functions-path-exists"></a>
+
+Signature:
+
+ function path_exists(path)
+
+Returns true if the specified path exists, false otherwise.
+
+Example:
+
+ $ icinga2 console
+ Icinga 2 (version: v2.7.0)
+ <1> => var path = "/etc/icinga2/scripts/xmpp-notification.pl"
+ null
+ <2> => path_exists(path)
+ true
+
+### glob <a id="global-functions-glob"></a>
+
+Signature:
+
+ function glob(pathSpec, type)
+
+Returns an array containing all paths which match the
+`pathSpec` argument.
+
+The `type` argument is optional and specifies which types
+of paths are matched. This can be a combination of the `GlobFile`
+and `GlobDirectory` constants. The default value is `GlobFile | GlobDirectory`.
+
+ $ icinga2 console
+ Icinga 2 (version: v2.7.0)
+ <1> => var pathSpec = "/etc/icinga2/conf.d/*.conf"
+ null
+ <2> => glob(pathSpec)
+ [ "/etc/icinga2/conf.d/app.conf", "/etc/icinga2/conf.d/commands.conf", ... ]
+
+### glob\_recursive <a id="global-functions-glob-recursive"></a>
+
+Signature:
+
+ function glob_recursive(path, pattern, type)
+
+Recursively descends into the specified directory and returns an array containing
+all paths which match the `pattern` argument.
+
+The `type` argument is optional and specifies which types
+of paths are matched. This can be a combination of the `GlobFile`
+and `GlobDirectory` constants. The default value is `GlobFile | GlobDirectory`.
+
+ $ icinga2 console
+ Icinga 2 (version: v2.7.0)
+ <1> => var path = "/etc/icinga2/zones.d/"
+ null
+ <2> => var pattern = "*.conf"
+ null
+ <3> => glob_recursive(path, pattern)
+ [ "/etc/icinga2/zones.d/global-templates/templates.conf", "/etc/icinga2/zones.d/master/hosts.conf", ... ]
+
+### escape_shell_arg <a id="global-functions-escape_shell_arg"></a>
Signature:
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$'\\'''"
-### <a id="global-functions-escape_shell_cmd"></a> escape_shell_cmd
+### escape_shell_cmd <a id="global-functions-escape_shell_cmd"></a>
Signature:
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"
-### <a id="global-functions-escape_create_process_arg"></a> escape_create_process_arg
+### escape_create_process_arg <a id="global-functions-escape_create_process_arg"></a>
Signature:
Escapes a string for use as an argument for CreateProcess(). Windows only.
-### <a id="global-functions-sleep"></a> sleep
+### sleep <a id="global-functions-sleep"></a>
Signature:
Sleeps for the specified amount of time (in seconds).
-## <a id="object-accessor-functions"></a> Object Accessor Functions
+
+## Scoped Functions <a id="scoped-functions"></a>
+
+This chapter describes functions which are only available
+in a specific scope.
+
+### macro <a id="scoped-functions-macro"></a>
+
+Signature:
+
+```
+function macro("$macro_name$")
+```
+
+The `macro` function can be used to resolve [runtime macro](03-monitoring-basics.md#runtime-macros)
+strings into their values.
+The returned value depends on the attribute value which is resolved
+from the specified runtime macro.
+
+This function is only available in runtime evaluated functions, e.g.
+for [custom attributes](03-monitoring-basics.md#custom-attributes-functions) which
+use the [abbreviated lambda syntax](17-language-reference.md#nullary-lambdas).
+
+This example sets the `snmp_address` custom attribute
+based on `$address$` and `$address6`.
+
+```
+ vars.snmp_address = {{
+ var addr_v4 = macro("$address$")
+ var addr_v6 = macro("$address6$")
+
+ if (addr_v4) {
+ return addr_v4
+ } else {
+ return "udp6:[" + addr_v6 + "]"
+ }
+ }}
+```
+
+More reference examples are available inside the [Icinga Template Library](10-icinga-template-library.md#icinga-template-library)
+and the [object accessors chapter](08-advanced-topics.md#access-object-attributes-at-runtime).
+
+## Object Accessor Functions <a id="object-accessor-functions"></a>
These functions can be used to retrieve a reference to another object by name.
-### <a id="objref-get_check_command"></a> get_check_command
+### get_check_command <a id="objref-get_check_command"></a>
Signature:
Returns the CheckCommand object with the specified name, or `null` if no such CheckCommand object exists.
-### <a id="objref-get_event_command"></a> get_event_command
+### get_event_command <a id="objref-get_event_command"></a>
Signature:
Returns the EventCommand object with the specified name, or `null` if no such EventCommand object exists.
-### <a id="objref-get_notification_command"></a> get_notification_command
+### get_notification_command <a id="objref-get_notification_command"></a>
Signature:
Returns the NotificationCommand object with the specified name, or `null` if no such NotificationCommand object exists.
-### <a id="objref-get_host"></a> get_host
+### get_host <a id="objref-get_host"></a>
Signature:
Returns the Host object with the specified name, or `null` if no such Host object exists.
-### <a id="objref-get_service"></a> get_service
+### get_service <a id="objref-get_service"></a>
Signature:
function get_service(host_name, service_name);
+ function get_service(host, service_name);
+
+Returns the Service object with the specified host name or object and service name pair,
+or `null` if no such Service object exists.
+
+Example in the [debug console](11-cli-commands.md#cli-command-console)
+which fetches the `disk` service object from the current Icinga 2 node:
+
+```
+$ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/'
+Icinga 2 (version: v2.7.0)
+
+<1> => get_service(NodeName, "disk")
+<2> => get_service(NodeName, "disk").__name
+"icinga2-master1.localdomain!disk"
+
+<3> => get_service(get_host(NodeName), "disk").__name
+"icinga2-master1.localdomain!disk"
+```
+
+### get_services <a id="objref-get_services"></a>
+
+Signature:
+
+ function get_services(host_name);
+ function get_services(host);
+
+Returns an [array](17-language-reference.md#array) of service objects for the specified host name or object,
+or `null` if no such host object exists.
+
+Example in the [debug console](11-cli-commands.md#cli-command-console)
+which fetches all service objects from the current Icinga 2 node:
+
+```
+$ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/'
+Icinga 2 (version: v2.7.0)
+
+<1> => get_services(NodeName).map(s => s.name)
+[ "disk", "disk /", "http", "icinga", "load", "ping4", "ping6", "procs", "ssh", "users" ]
+```
+
+Note: [map](18-library-reference.md#array-map) takes a [lambda function](17-language-reference.md#lambdas) as argument. In this example
+we only want to collect and print the `name` attribute with `s => s.name`.
-Returns the Service object with the specified name, or `null` if no such Service object exists.
+This works in a similar fashion for a host object where you can extract all service states
+in using the [map](18-library-reference.md#array-map) functionality:
+```
+<2> => get_services(get_host(NodeName)).map(s => s.state)
+[ 2.000000, 2.000000, 2.000000, 0.000000, 0.000000, 0.000000, 2.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000 ]
+```
-### <a id="objref-get_user"></a> get_user
+### get_user <a id="objref-get_user"></a>
Signature:
Returns the User object with the specified name, or `null` if no such User object exists.
-### <a id="objref-get_host_group"></a> get_host_group
+### get_host_group <a id="objref-get_host_group"></a>
Signature:
Returns the HostGroup object with the specified name, or `null` if no such HostGroup object exists.
-### <a id="objref-get_service_group"></a> get_service_group
+### get_service_group <a id="objref-get_service_group"></a>
Signature:
Returns the ServiceGroup object with the specified name, or `null` if no such ServiceGroup object exists.
-### <a id="objref-get_user_group"></a> get_user_group
+### get_user_group <a id="objref-get_user_group"></a>
Signature:
Returns the UserGroup object with the specified name, or `null` if no such UserGroup object exists.
-### <a id="objref-get_time_period"></a> get_time_period
+### get_time_period <a id="objref-get_time_period"></a>
Signature:
Returns the TimePeriod object with the specified name, or `null` if no such TimePeriod object exists.
-### <a id="objref-get_object"></a> get_object
+### get_object <a id="objref-get_object"></a>
Signature:
to a type object.
-### <a id="objref-get_objects"></a> get_objects
+### get_objects <a id="objref-get_objects"></a>
Signature:
to a type object.
-## <a id="math-object"></a> Math object
+## Math object <a id="math-object"></a>
The global `Math` object can be used to access a number of mathematical constants
and functions.
-### <a id="math-e"></a> Math.E
+### Math.E <a id="math-e"></a>
Euler's constant.
-### <a id="math-ln2"></a> Math.LN2
+### Math.LN2 <a id="math-ln2"></a>
Natural logarithm of 2.
-### <a id="math-ln10"></a> Math.LN10
+### Math.LN10 <a id="math-ln10"></a>
Natural logarithm of 10.
-### <a id="math-log2e"></a> Math.LOG2E
+### Math.LOG2E <a id="math-log2e"></a>
Base 2 logarithm of E.
-### <a id="math-pi"></a> Math.PI
+### Math.PI <a id="math-pi"></a>
The mathematical constant Pi.
-### <a id="math-sqrt1_2"></a> Math.SQRT1_2
+### Math.SQRT1_2 <a id="math-sqrt1_2"></a>
Square root of 1/2.
-### <a id="math-sqrt2"></a> Math.SQRT2
+### Math.SQRT2 <a id="math-sqrt2"></a>
Square root of 2.
-### <a id="math-abs"></a> Math.abs
+### Math.abs <a id="math-abs"></a>
Signature:
Returns the absolute value of `x`.
-### <a id="math-acos"></a> Math.acos
+### Math.acos <a id="math-acos"></a>
Signature:
Returns the arccosine of `x`.
-### <a id="math-asin"></a> Math.asin
+### Math.asin <a id="math-asin"></a>
Signature:
Returns the arcsine of `x`.
-### <a id="math-atan"></a> Math.atan
+### Math.atan <a id="math-atan"></a>
Signature:
Returns the arctangent of `x`.
-### <a id="math-atan2"></a> Math.atan2
+### Math.atan2 <a id="math-atan2"></a>
Signature:
Returns the arctangent of the quotient of `y` and `x`.
-### <a id="math-ceil"></a> Math.ceil
+### Math.ceil <a id="math-ceil"></a>
Signature:
Returns the smallest integer value not less than `x`.
-### <a id="math-cos"></a> Math.cos
+### Math.cos <a id="math-cos"></a>
Signature:
Returns the cosine of `x`.
-### <a id="math-exp"></a> Math.exp
+### Math.exp <a id="math-exp"></a>
Signature:
Returns E raised to the `x`th power.
-### <a id="math-floor"></a> Math.floor
+### Math.floor <a id="math-floor"></a>
Signature:
Returns the largest integer value not greater than `x`.
-### <a id="math-isinf"></a> Math.isinf
+### Math.isinf <a id="math-isinf"></a>
Signature:
Returns whether `x` is infinite.
-### <a id="math-isnan"></a> Math.isnan
+### Math.isnan <a id="math-isnan"></a>
Signature:
Returns whether `x` is NaN (not-a-number).
-### <a id="math-log"></a> Math.log
+### Math.log <a id="math-log"></a>
Signature:
Returns the natural logarithm of `x`.
-### <a id="math-max"></a> Math.max
+### Math.max <a id="math-max"></a>
Signature:
Returns the largest argument. A variable number of arguments can be specified.
If no arguments are given, -Infinity is returned.
-### <a id="math-min"></a> Math.min
+### Math.min <a id="math-min"></a>
Signature:
Returns the smallest argument. A variable number of arguments can be specified.
If no arguments are given, +Infinity is returned.
-### <a id="math-pow"></a> Math.pow
+### Math.pow <a id="math-pow"></a>
Signature:
Returns `x` raised to the `y`th power.
-### <a id="math-random"></a> Math.random
+### Math.random <a id="math-random"></a>
Signature:
Returns a pseudo-random number between 0 and 1.
-### <a id="math-round"></a> Math.round
+### Math.round <a id="math-round"></a>
Signature:
Returns `x` rounded to the nearest integer value.
-### <a id="math-sign"></a> Math.sign
+### Math.sign <a id="math-sign"></a>
Signature:
Returns -1 if `x` is negative, 1 if `x` is positive
and 0 if `x` is 0.
-### <a id="math-sin"></a> Math.sin
+### Math.sin <a id="math-sin"></a>
Signature:
Returns the sine of `x`.
-### <a id="math-sqrt"></a> Math.sqrt
+### Math.sqrt <a id="math-sqrt"></a>
Signature:
Returns the square root of `x`.
-### <a id="math-tan"></a> Math.tan
+### Math.tan <a id="math-tan"></a>
Signature:
Returns the tangent of `x`.
-## <a id="json-object"></a> Json object
+## Json object <a id="json-object"></a>
The global `Json` object can be used to encode and decode JSON.
-### <a id="json-encode"></a> Json.encode
+### Json.encode <a id="json-encode"></a>
Signature:
Encodes an arbitrary value into JSON.
-### <a id="json-decode"></a> Json.decode
+### Json.decode <a id="json-decode"></a>
Signature:
Decodes a JSON string.
-## <a id="number-type"></a> Number type
+## Number type <a id="number-type"></a>
-### <a id="number-to_string"></a> Number#to_string
+### Number#to_string <a id="number-to_string"></a>
Signature:
var example = 7
example.to_string() /* Returns "7" */
-## <a id="boolean-type"></a> Boolean type
+## Boolean type <a id="boolean-type"></a>
-### <a id="boolean-to_string"></a> Boolean#to_string
+### Boolean#to_string <a id="boolean-to_string"></a>
Signature:
var example = true
example.to_string() /* Returns "true" */
-## <a id="string-type"></a> String type
+## String type <a id="string-type"></a>
-### <a id="string-find"></a> String#find
+### String#find <a id="string-find"></a>
Signature:
"Hello World".find("World") /* Returns 6 */
-### <a id="string-contains"></a> String#contains
+### String#contains <a id="string-contains"></a>
Signature:
"Hello World".contains("World") /* Returns true */
-### <a id="string-len"></a> String#len
+### String#len <a id="string-len"></a>
Signature
"Hello World".len() /* Returns 11 */
-### <a id="string-lower"></a> String#lower
+### String#lower <a id="string-lower"></a>
Signature:
"Hello World".lower() /* Returns "hello world" */
-### <a id="string-upper"></a> String#upper
+### String#upper <a id="string-upper"></a>
Signature:
"Hello World".upper() /* Returns "HELLO WORLD" */
-### <a id="string-replace"></a> String#replace
+### String#replace <a id="string-replace"></a>
Signature:
Returns a copy of the string with all occurences of the string specified in `search` replaced
with the string specified in `replacement`.
-### <a id="string-split"></a> String#split
+### String#split <a id="string-split"></a>
Signature:
"x-7,y".split("-,") /* Returns [ "x", "7", "y" ] */
-### <a id="string-substr"></a> String#substr
+### String#substr <a id="string-substr"></a>
Signature:
"Hello World".substr(6) /* Returns "World" */
-### <a id="string-to_string"></a> String#to_string
+### String#to_string <a id="string-to_string"></a>
Signature:
Returns a copy of the string.
-### <a id="string-reverse"></a> String#reverse
+### String#reverse <a id="string-reverse"></a>
Signature:
Returns a copy of the string in reverse order.
-### <a id="string-trim"></a> String#trim
+### String#trim <a id="string-trim"></a>
Signature:
Removes trailing whitespaces and returns the string.
-## <a id="object-type"></a> Object type
+## Object type <a id="object-type"></a>
This is the base type for all types in the Icinga application.
-### <a id="object-clone"></a> Object#clone
+### Object#clone <a id="object-clone"></a>
Signature:
reference values (e.g. objects such as arrays or dictionaries) the entire
object is recursively copied.
-### <a id="object-to-string"></a> Object#to_string
+### Object#to_string <a id="object-to-string"></a>
Signature:
[ 3, true ].to_string() /* Returns "[ 3.000000, true ]" */
-### <a id="object-type-field"></a> Object#type
+### Object#type <a id="object-type-field"></a>
Signature:
get_host("localhost").type /* Returns "Host" */
-## <a id="type-type"></a> Type type
+## Type type <a id="type-type"></a>
Inherits methods from the [Object type](18-library-reference.md#object-type).
All types are registered as global variables. For example, in order to obtain a reference to the `String` type the global variable `String` can be used.
-### <a id="type-base"></a> Type#base
+### Type#base <a id="type-base"></a>
Signature:
Dictionary.base == Object /* Returns true, because the Dictionary type inherits directly from the Object type. */
-### <a id="type-name"></a> Type#name
+### Type#name <a id="type-name"></a>
Signature:
Returns the name of the type.
-### <a id="type-prototype"></a> Type#prototype
+### Type#prototype <a id="type-prototype"></a>
Signature:
3.to_string() /* Even though '3' does not have a to_string property the Number type's prototype object does. */
-## <a id="array-type"></a> Array type
+## Array type <a id="array-type"></a>
Inherits methods from the [Object type](18-library-reference.md#object-type).
-### <a id="array-add"></a> Array#add
+### Array#add <a id="array-add"></a>
Signature:
Adds a new value after the last element in the array.
-### <a id="array-clear"></a> Array#clear
+### Array#clear <a id="array-clear"></a>
Signature:
Removes all elements from the array.
-### <a id="array-shallow-clone"></a> Array#shallow_clone
+### Array#shallow_clone <a id="array-shallow-clone"></a>
function shallow_clone();
Returns a copy of the array. Note that for elements which are reference values (e.g. objects such
as arrays and dictionaries) only the references are copied.
-### <a id="array-contains"></a> Array#contains
+### Array#contains <a id="array-contains"></a>
Signature:
Returns true if the array contains the specified value, false otherwise.
-### <a id="array-len"></a> Array#len
+### Array#len <a id="array-len"></a>
Signature:
Returns the number of elements contained in the array.
-### <a id="array-remove"></a> Array#remove
+### Array#remove <a id="array-remove"></a>
Signature:
Removes the element at the specified zero-based index.
-### <a id="array-set"></a> Array#set
+### Array#set <a id="array-set"></a>
Signature:
Sets the element at the zero-based index to the specified value. The `index` must refer to an element
which already exists in the array.
-### <a id="array-get"></a> Array#get
+### Array#get <a id="array-get"></a>
Signature:
Retrieves the element at the specified zero-based index.
-### <a id="array-sort"></a> Array#sort
+### Array#sort <a id="array-sort"></a>
Signature:
compared using the `<` (less-than) operator. A custom comparator function
can be specified with the `less_cmp` argument.
-### <a id="array-join"></a> Array#join
+### Array#join <a id="array-join"></a>
Signature:
Joins all elements of the array using the specified separator.
-### <a id="array-reverse"></a> Array#reverse
+### Array#reverse <a id="array-reverse"></a>
Signature:
Returns a new array with all elements of the current array in reverse order.
-### <a id="array-map"></a> Array#map
+### Array#map <a id="array-map"></a>
Signature:
Calls `func(element)` for each of the elements in the array and returns
a new array containing the return values of these function calls.
-### <a id="array-reduce"></a> Array#reduce
+### Array#reduce <a id="array-reduce"></a>
Signature:
function `func` as `func(a, b)` repeatedly where `a` and `b` are elements of the array
or results from previous function calls.
-### <a id="array-filter"></a> Array#filter
+### Array#filter <a id="array-filter"></a>
Signature:
Returns a copy of the array containing only the elements for which `func(element)`
is true.
-### <a id="array-any"></a> Array#any
+### Array#any <a id="array-any"></a>
Signature:
Returns true if the array contains at least one element for which `func(element)`
is true, false otherwise.
-### <a id="array-all"></a> Array#all
+### Array#all <a id="array-all"></a>
Signature:
Returns true if the array contains only elements for which `func(element)`
is true, false otherwise.
-### <a id="array-unique"></a> Array#unique
+### Array#unique <a id="array-unique"></a>
Signature:
Returns a copy of the array with all duplicate elements removed. The original order
of the array is not preserved.
-## <a id="dictionary-type"></a> Dictionary type
+## Dictionary type <a id="dictionary-type"></a>
Inherits methods from the [Object type](18-library-reference.md#object-type).
-### <a id="dictionary-shallow-clone"></a> Dictionary#shallow_clone
+### Dictionary#shallow_clone <a id="dictionary-shallow-clone"></a>
Signature:
Returns a copy of the dictionary. Note that for elements which are reference values (e.g. objects such
as arrays and dictionaries) only the references are copied.
-### <a id="dictionary-contains"></a> Dictionary#contains
+### Dictionary#contains <a id="dictionary-contains"></a>
Signature:
Returns true if a dictionary item with the specified `key` exists, false otherwise.
-### <a id="dictionary-len"></a> Dictionary#len
+### Dictionary#len <a id="dictionary-len"></a>
Signature:
Returns the number of items contained in the dictionary.
-### <a id="dictionary-remove"></a> Dictionary#remove
+### Dictionary#remove <a id="dictionary-remove"></a>
Signature:
Removes the item with the specified `key`. Trying to remove an item which does not exist
is a no-op.
-### <a id="dictionary-set"></a> Dictionary#set
+### Dictionary#set <a id="dictionary-set"></a>
Signature:
Creates or updates an item with the specified `key` and `value`.
-### <a id="dictionary-get"></a> Dictionary#get
+### Dictionary#get <a id="dictionary-get"></a>
Signature:
Retrieves the value for the specified `key`. Returns `null` if they `key` does not exist
in the dictionary.
-### <a id="dictionary-keys"></a> Dictionary#keys
+### Dictionary#keys <a id="dictionary-keys"></a>
Signature:
Returns a list of keys for all items that are currently in the dictionary.
-### <a id="dictionary-values"></a> Dictionary#values
+### Dictionary#values <a id="dictionary-values"></a>
Signature:
Returns a list of values for all items that are currently in the dictionary.
-## <a id="scriptfunction-type"></a> Function type
+## Function type <a id="scriptfunction-type"></a>
Inherits methods from the [Object type](18-library-reference.md#object-type).
-### <a id="scriptfunction-call"></a> Function#call
+### Function#call <a id="scriptfunction-call"></a>
Signature:
set_x.call(dict, 7) /* Invokes set_x using `dict` as `this` */
-### <a id="scriptfunction-callv"></a> Function#callv
+### Function#callv <a id="scriptfunction-callv"></a>
Signature:
set_x.callv(dict, args) /* Invokes set_x using `dict` as `this` */
-## <a id="datetime-type"></a> DateTime type
+## DateTime type <a id="datetime-type"></a>
Inherits methods from the [Object type](18-library-reference.md#object-type).
-### <a id="datetime-ctor"></a> DateTime constructor
+### DateTime constructor <a id="datetime-ctor"></a>
Signature:
var d1 = DateTime() /* current time */
var d2 = DateTime(2016, 5, 21) /* midnight April 21st, 2016 (local time) */
-### <a id="datetime-arithmetic"></a> DateTime arithmetic
+### DateTime arithmetic <a id="datetime-arithmetic"></a>
Subtracting two DateTime objects yields the interval between them, in seconds.
var dt = DateTime() + 24 * 60 60 /* Current time plus 24 hours */
-### <a id="datetime-format"></a> DateTime#format
+### DateTime#format <a id="datetime-format"></a>
Signature:
var s = DateTime(2016, 4, 21).format("%A") /* Sets s to "Thursday". */
-### <a id="datetime-tostring"></a> DateTime#to_string
+### DateTime#to_string <a id="datetime-tostring"></a>
Signature: