"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "doc/17-language-reference.md" between
icinga2-2.11.5.tar.gz and icinga2-2.12.0.tar.gz

About: Icinga 2 is an enterprise grade monitoring system which keeps watch over networks and any conceivable network resource.

17-language-reference.md  (icinga2-2.11.5):17-language-reference.md  (icinga2-2.12.0)
skipping to change at line 211 skipping to change at line 211
`!in` | 7 | "foo" !in [ "bar", "baz" ] (true) | Elemen t not contained in array `!in` | 7 | "foo" !in [ "bar", "baz" ] (true) | Elemen t not contained in array
`==` | 8 | "hello" == "hello" (true), 3 == 5 (false) | Equal t o `==` | 8 | "hello" == "hello" (true), 3 == 5 (false) | Equal t o
`!=` | 8 | "hello" != "world" (true), 3 != 3 (false) | Not equ al to `!=` | 8 | "hello" != "world" (true), 3 != 3 (false) | Not equ al to
`&` | 9 | 7 & 3 (3) | Binary AND `&` | 9 | 7 & 3 (3) | Binary AND
`^` | 10 | 17 ^ 12 (29) | Bitwi se XOR `^` | 10 | 17 ^ 12 (29) | Bitwi se XOR
<code>&#124;</code> | 11 | 2 &#124; 3 (3) | Binary OR <code>&#124;</code> | 11 | 2 &#124; 3 (3) | Binary OR
<code>&#124;&#124;</code> | 12 | true &#124;&#124; false (true), 0 &#124;&# 124; 7 (7)| Logical OR <code>&#124;&#124;</code> | 12 | true &#124;&#124; false (true), 0 &#124;&# 124; 7 (7)| Logical OR
`&&` | 13 | true && false (false), 3 && 7 (7), 0 && 7 (0) | Logica l AND `&&` | 13 | true && false (false), 3 && 7 (7), 0 && 7 (0) | Logica l AND
`=` | 14 | a = 3 | Assign ment `=` | 14 | a = 3 | Assign ment
`=>` | 15 | x => x * x (function with arg x) | Lambda , for loop `=>` | 15 | x => x * x (function with arg x) | Lambda , for loop
`?` | 16 | (2 * 3 > 5) ? 1 : 0 (1) | [Terna ry operator](17-language-reference.md#conditional-statements-ternary)
### References <a id="references"></a> ### References <a id="references"></a>
A reference to a value can be obtained using the `&` operator. The `*` operator can be used A reference to a value can be obtained using the `&` operator. The `*` operator can be used
to dereference a reference: to dereference a reference:
``` ```
var value = "Hello!" var value = "Hello!"
var p = &value /* p refers to value */ var p = &value /* p refers to value */
*p = "Hi!" *p = "Hi!"
skipping to change at line 568 skipping to change at line 569
AttachDebugger |**Read-write.** Whether to attach a debugger when Ic inga 2 crashes. Defaults to `false`. AttachDebugger |**Read-write.** Whether to attach a debugger when Ic inga 2 crashes. Defaults to `false`.
Advanced sysconfig environment variables, defined in `/etc/sysconfig/icinga2` (R HEL/SLES) or `/etc/default/icinga2` (Debian/Ubuntu). Advanced sysconfig environment variables, defined in `/etc/sysconfig/icinga2` (R HEL/SLES) or `/etc/default/icinga2` (Debian/Ubuntu).
Variable | Description Variable | Description
---------------------------|------------------- ---------------------------|-------------------
ICINGA2\_RLIMIT\_FILES |**Read-write.** Defines the resource limit for `RLIM IT_NOFILE` that should be set at start-up. Value cannot be set lower than the de fault `16 * 1024`. 0 disables the setting. Set in Icinga 2 sysconfig. ICINGA2\_RLIMIT\_FILES |**Read-write.** Defines the resource limit for `RLIM IT_NOFILE` that should be set at start-up. Value cannot be set lower than the de fault `16 * 1024`. 0 disables the setting. Set in Icinga 2 sysconfig.
ICINGA2\_RLIMIT\_PROCESSES |**Read-write.** Defines the resource limit for `RLIM IT_NPROC` that should be set at start-up. Value cannot be set lower than the def ault `16 * 1024`. 0 disables the setting. Set in Icinga 2 sysconfig. ICINGA2\_RLIMIT\_PROCESSES |**Read-write.** Defines the resource limit for `RLIM IT_NPROC` that should be set at start-up. Value cannot be set lower than the def ault `16 * 1024`. 0 disables the setting. Set in Icinga 2 sysconfig.
ICINGA2\_RLIMIT\_STACK |**Read-write.** Defines the resource limit for `RLIM IT_STACK` that should be set at start-up. Value cannot be set lower than the def ault `256 * 1024`. 0 disables the setting. Set in Icinga 2 sysconfig. ICINGA2\_RLIMIT\_STACK |**Read-write.** Defines the resource limit for `RLIM IT_STACK` that should be set at start-up. Value cannot be set lower than the def ault `256 * 1024`. 0 disables the setting. Set in Icinga 2 sysconfig.
#### Debug Constants and Variables <a id="icinga-constants-debug"></a>
These constants are only available in debug builds for developers and help with
tracing messages and attaching to debuggers.
Variable | Description
---------------------------|-------------------
Internal.DebugJsonRpc | **Read-write.** Setting this to `1` prints the raw
JSON-RPC message to STDOUT.
Internal.DebugWorkerDelay | **Read-write.** Delays the main worker process by X
seconds after forked from the umbrella process. This helps with attaching LLDB
which cannot follow child forks like GDB.
Example:
```
$ icinga2 daemon -DInternal.DebugWorkerDelay=120
Closed FD 6 which we inherited from our parent process.
[2020-01-29 12:22:33 +0100] information/cli: Icinga application loader (version:
v2.11.0-477-gfe8701d77; debug)
[2020-01-29 12:22:33 +0100] information/RunWorker: DEBUG: Current PID: 85253. Sl
eeping for 120 seconds to allow lldb/gdb -p <PID> attachment.
$ lldb -p 85253
(lldb) b icinga::Checkable::ProcessCheckResult
(lldb) c
```
## Apply <a id="apply"></a> ## Apply <a id="apply"></a>
The `apply` keyword can be used to create new objects which are associated with The `apply` keyword can be used to create new objects which are associated with
another group of objects. another group of objects.
``` ```
apply Service "ping" to Host { apply Service "ping" to Host {
import "generic-service" import "generic-service"
check_command = "ping4" check_command = "ping4"
skipping to change at line 865 skipping to change at line 888
``` ```
Just like with ordinary functions the return value is the value of the last stat ement. Just like with ordinary functions the return value is the value of the last stat ement.
For lambdas which take exactly one argument the braces around the arguments can be omitted: For lambdas which take exactly one argument the braces around the arguments can be omitted:
``` ```
f = x => x * x f = x => x * x
``` ```
### Lambda Expressions with Closures <a id="lambdas-closures"></a>
Lambda expressions which take a given number of arguments may need additional
variable values from the outer scope. When the lambda expression does not allow
to change the interface, [closures](17-language-reference.md#closures) come into
play.
```
var y
f = ((x) use(y) => x == y)
```
Note that the braces around arguments are always required when using closures.
A more concrete example:
Within the DSL, you want to [filter](18-library-reference.md#array-filter) an ar
ray of HostGroup objects by their name.
The filter function takes one argument being a function callback which either re
turns
`true` or `false`. Matching items are collected into the result set.
```
get_objects(HostGroup).filter((hg) => hg.name == "linux-servers")
```
Instead of hardcoding the matching hostgroup name into the lambda scope, you wan
t
to control the value from the outside configuration values, e.g. in a custom var
iable
or global constant.
```
var hg_filter_name = "linux-servers"
get_objects(HostGroup).filter((hg) use(hg_filter_name) => hg.name == hg_filter_n
ame)
```
You can also use this example vice versa and extract host object matching a spec
ific
host group name.
```
var hg_filter_name = "linux-servers"
get_objects(Host).filter((h) use (hg_search_name) => hg_search_name in h.groups)
.map(h => h.name)
```
Note that this example makes use of the [map](18-library-reference.md#array-map)
method for the Array type which
extracts the host name attribute from the full object into a new array.
## Abbreviated Lambda Syntax <a id="nullary-lambdas"></a> ## Abbreviated Lambda Syntax <a id="nullary-lambdas"></a>
Lambdas which take no arguments can also be written using the abbreviated lambda syntax. Lambdas which take no arguments can also be written using the abbreviated lambda syntax.
Example: Example:
``` ```
f = {{ 3 }} f = {{ 3 }}
``` ```
skipping to change at line 978 skipping to change at line 1047
``` ```
function MakeHelloFunction(name) { function MakeHelloFunction(name) {
return function() use (greeting = "Hello, " + name) { return function() use (greeting = "Hello, " + name) {
log(greeting) log(greeting)
} }
} }
``` ```
## Conditional Statements <a id="conditional-statements"></a> ## Conditional Statements <a id="conditional-statements"></a>
### Conditional Statements: if/else <a id="conditional-statements-if-else"></a>
Sometimes it can be desirable to only evaluate statements when certain condition s are met. The if/else Sometimes it can be desirable to only evaluate statements when certain condition s are met. The if/else
construct can be used to accomplish this. construct can be used to accomplish this.
Example: Example:
``` ```
a = 3 a = 3
if (a < 5) { if (a < 5) {
a *= 7 a *= 7
skipping to change at line 1012 skipping to change at line 1083
} else { } else {
log("Taking the 'false' branch") log("Taking the 'false' branch")
9 9
} }
``` ```
This example prints the log message "Taking the 'true' branch" and the `a` varia ble is set to 21 (7 * 3). This example prints the log message "Taking the 'true' branch" and the `a` varia ble is set to 21 (7 * 3).
The value of an if/else construct is null if the condition evaluates to false an d no else branch is given. The value of an if/else construct is null if the condition evaluates to false an d no else branch is given.
### Conditional Statements: Ternary Operator <a id="conditional-statements-terna
ry"></a>
Instead of if/else condition chains, you can also use the ternary operator `?`
with assignments. Values are separated with a colon `:` character.
```
cond ? cond_val_true : cond_val_false
```
Whether the first condition matches, the first value is returned, if not, the el
se and second
branch value is returned.
The following example evaluates a condition and either assigns `1` or `0`
to the local variable.
```
<1> => var x = (2 * 3 > 5) ? 1 : 0
null
<2> => x
1.000000
<3> => var x = (2 * 3 > 7) ? 1 : 0
null
<4> => x
0.000000
```
Additional examples with advanced condition chaining:
```
<1> => 1 ? 2 : 3 ? 4 : 5 ? 6 : 7
2.000000
<2> => 0 ? 2 : 3 ? 4 : 5 ? 6 : 7
4.000000
<3> => 0 ? 2 : 0 ? 4 : 5 ? 6 : 7
6.000000
<4> => 0 ? 2 : 0 ? 4 : 0 ? 6 : 7
7.000000
<5> => 1 + 0 ? 2 : 3 + 4
2.000000
<6> => 0 + 0 ? 2 : 3 + 4
7.000000
<7> => (()=>{ return 1 ? 2 : 3 })()
2.000000
<8> => var x = 1 ? 2 : 3
null
<9> => x
2.000000
```
## While Loops <a id="while-loops"></a> ## While Loops <a id="while-loops"></a>
The `while` statement checks a condition and executes the loop body when the con dition evaluates to `true`. The `while` statement checks a condition and executes the loop body when the con dition evaluates to `true`.
This is repeated until the condition is no longer true. This is repeated until the condition is no longer true.
Example: Example:
``` ```
var num = 5 var num = 5
 End of changes. 5 change blocks. 
0 lines changed or deleted 137 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)