2014-02-05 14:27:06 +01:00
## <a id="configuration-syntax"></a> Configuration Syntax
2013-09-26 08:59:29 +02:00
2014-02-05 14:27:06 +01:00
### <a id="object-definition"></a> Object Definition
2013-09-26 08:59:29 +02:00
2014-03-30 10:28:44 +02:00
Icinga 2 features an object-based configuration format. You can define new
objects using the `object` keyword:
2013-09-26 08:59:29 +02:00
object Host "host1.example.org" {
display_name = "host1",
macros = {
address = "192.168.0.1"
}
}
> **Note**
>
2013-10-10 16:55:59 +02:00
> The Icinga 2 configuration format is agnostic to white space characters and
2013-09-26 08:59:29 +02:00
> new-lines.
> **Note**
>
2013-12-12 11:48:43 +01:00
> Exclamation marks (!) are not permitted in object names.
2013-09-26 08:59:29 +02:00
2013-10-07 09:35:44 +02:00
Each object is uniquely identified by its type (`Host`) and name
(`host1.example.org`). Objects can contain a comma-separated list of
2014-03-24 12:01:56 +01:00
property declarations. Instead of commas semi-colons may also be used.
The following data types are available for property values:
2013-09-26 08:59:29 +02:00
2014-03-19 20:00:05 +01:00
### Expressions
The following expressions can be used in the right-hand side of dictionary
values.
2014-02-05 14:27:06 +01:00
#### <a id="numeric-literals"></a> Numeric Literals
2013-09-26 08:59:29 +02:00
A floating-point number.
Example:
-27.3
2014-02-05 14:27:06 +01:00
#### <a id="duration-literals"></a> Duration Literals
2013-09-26 08:59:29 +02:00
Similar to floating-point numbers except for the fact that they support
suffixes to help with specifying time durations.
Example:
2.5m
2013-09-27 16:39:35 +02:00
Supported suffixes include ms (milliseconds), s (seconds), m (minutes),
h (hours) and d (days).
2013-09-26 08:59:29 +02:00
2014-03-24 12:01:56 +01:00
Duration literals are converted to seconds by the config parser and
are treated like numeric literals.
2014-02-05 14:27:06 +01:00
#### <a id="string-literals"></a> String Literals
2013-09-26 08:59:29 +02:00
A string.
Example:
"Hello World!"
Certain characters need to be escaped. The following escape sequences
are supported:
2014-03-30 11:52:39 +02:00
Character | Escape sequence
--------------------------|------------------------------------
" | \\"
\\ | \\\\
< TAB> | \\t
< CARRIAGE-RETURN> | \\r
< LINE-FEED> | \\n
< BEL> | \\b
< FORM-FEED> | \\f
2013-09-26 08:59:29 +02:00
In addition to these pre-defined escape sequences you can specify
arbitrary ASCII characters using the backslash character (\\) followed
by an ASCII character in octal encoding.
2014-02-05 14:27:06 +01:00
#### <a id="multiline-string-literals"></a> Multi-line String Literals
2013-09-26 08:59:29 +02:00
Strings spanning multiple lines can be specified by enclosing them in
{{{ and }}}.
Example.
{{{This
is
a multi-line
string.}}}
2013-10-01 16:09:34 +02:00
> **Note**
>
2014-03-09 22:30:56 +01:00
> Unlike in ordinary strings special characters do not have to be escaped
2013-10-01 16:09:34 +02:00
> in multi-line string literals.
2014-02-05 14:27:06 +01:00
#### <a id="boolean-literals"></a> Boolean Literals
2013-09-26 08:59:29 +02:00
2013-10-07 09:35:44 +02:00
The keywords `true` and `false` are equivalent to 1 and 0 respectively.
2013-09-26 08:59:29 +02:00
2014-02-05 14:27:06 +01:00
#### <a id="null-value"></a> Null Value
2013-09-26 08:59:29 +02:00
2013-10-07 09:35:44 +02:00
The `null` keyword can be used to specify an empty value.
2013-09-26 08:59:29 +02:00
2014-02-05 14:27:06 +01:00
#### <a id="dictionary"></a> Dictionary
2013-09-26 08:59:29 +02:00
An unordered list of key-value pairs. Keys must be unique and are
compared in a case-insensitive manner.
Individual key-value pairs must be separated from each other with a
comma. The comma after the last key-value pair is optional.
Example:
{
address = "192.168.0.1",
port = 443
}
> **Note**
>
> Identifiers may not contain certain characters (e.g. space) or start
> with certain characters (e.g. digits). If you want to use a dictionary
> key that is not a valid identifier you can put the key in double
> quotes.
> **Note**
>
> Setting a dictionary key to null causes the key and its value to be
> removed from the dictionary.
2014-02-05 14:27:06 +01:00
#### <a id="array"></a> Array
2013-09-26 08:59:29 +02:00
An ordered list of values.
Individual array elements must be separated from each other with a
comma. The comma after the last element is optional.
Example:
2013-09-27 07:19:13 +02:00
[ "hello", 42 ]
2013-09-26 08:59:29 +02:00
> **Note**
>
2013-09-27 07:19:13 +02:00
> An array may simultaneously contain values of different types, such as
2013-09-26 08:59:29 +02:00
> strings and numbers.
2014-04-01 09:15:51 +02:00
#### <a id="expression-operators"></a> Operators
2014-03-19 20:00:05 +01:00
The following operators are supported in expressions:
Operator | Examples (Result) | Description
---------|-----------------------------------------------|--------------------------------
2014-03-30 12:38:59 +02:00
! | !"Hello" (false), !false (true) | Log<!-- ignore BLACKLIST --> ical negation of the operand
2014-03-30 11:52:39 +02:00
~ | ~true (false) | Bitwise negation of the operand
2014-03-19 20:00:05 +01:00
+ | 1 + 3 (4), "hello " + "world" ("hello world") | Adds two numbers; concatenates strings
- | 3 - 1 (2) | Subtracts two numbers
* | 5m * 10 (3000) | Multiplies two numbers
/ | 5m / 5 (60) | Divides two numbers
& | 7 & 3 (3) | Binary AND
2014-03-20 06:35:18 +01:00
| | 2 | 3 (3) | Binary OR
2014-03-19 20:00:05 +01:00
< | 3 < 5 ( true ) | Less than
> | 3 > 5 (false) | Greater than
< = | 3 < = 3 (true) | Less than or equal
>= | 3 >= 3 (true) | Greater than or equal
< < | 4 < < 8 ( 1024 ) | Left shift
>> | 1024 >> 4 (64) | Right shift
== | "hello" == "hello" (true), 3 == 5 (false) | Equal to
!= | "hello" != "world" (true), 3 != 3 (false) | Not equal to
in | "foo" in [ "foo", "bar" ] (true) | Element contained in array
!in | "foo" !in [ "bar", "baz" ] (true) | Element not contained in array
() | (3 + 3) * 5 | Groups sub-expressions
2014-03-24 12:01:56 +01:00
Constants may be used in expressions:
2014-03-19 20:00:05 +01:00
const MyCheckInterval = 10m
...
{
check_interval = MyCheckInterval / 2.5
}
#### Function Calls
Functions can be called using the `()` operator:
const MyGroups = [ "test1", "test" ]
{
check_interval = len(MyGroups) * 1m
}
2014-03-20 14:25:40 +01:00
Function | Description
--------------------------------|-----------------------
regex(pattern, text) | Returns true if the regex pattern matches the text, false otherwise.
match(pattern, text) | Returns true if the wildcard pattern matches the text, false otherwise.
len(value) | Returns the length of the value, i.e. the number of elements for an array or dictionary, or the length of the string in bytes.
union(array, array, ...) | Returns an array containing all unique elements from the specified arrays.
intersection(array, array, ...) | Returns an array containing all unique elements which are common to all specified arrays.
string(value) | Converts the value to a string.
number(value) | Converts the value to a number.
bool(value) | Converts to value to a bool.
2014-03-24 12:01:56 +01:00
log(value) | Writes a message to the log. Non-string values are converted to a JSON string.
2014-04-01 09:33:54 +02:00
log(severity, facility, value) | Writes a message to the log. `severity` can be one of `LogDebug` , `LogInformation` , `LogWarning` and `LogCritical` . Non-string values are converted to a JSON string.
2014-03-24 13:51:58 +01:00
exit(integer) | Terminates the application.
2014-03-19 20:00:05 +01:00
### <a id="operators"></a> Dictionary Operators
2013-09-26 08:59:29 +02:00
2013-10-07 09:35:44 +02:00
In addition to the `=` operator shown above a number of other operators
2014-03-19 20:00:05 +01:00
to manipulate dictionary elements are supported. Here's a list of all
2013-09-26 08:59:29 +02:00
available operators:
2014-02-05 14:27:06 +01:00
#### <a id="operator-assignment"></a> Operator =
2013-09-26 08:59:29 +02:00
Sets a dictionary element to the specified value.
Example:
{
a = 5,
a = 7
}
In this example a has the value 7 after both instructions are executed.
2014-02-05 14:27:06 +01:00
#### <a id="operator-additive-assignment"></a> Operator +=
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
The += operator is a shortcut. The following expression:
2013-09-26 08:59:29 +02:00
{
a = [ "hello" ],
a += [ "world" ]
}
2014-03-24 09:06:16 +01:00
is equivalent to:
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
{
a = [ "hello" ],
a = a + [ "world" ]
}
2013-09-26 14:01:29 +02:00
2014-02-05 14:27:06 +01:00
#### <a id="operator-substractive-assignment"></a> Operator -=
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
The -= operator is a shortcut. The following expression:
2013-09-26 08:59:29 +02:00
{
2014-03-24 09:06:16 +01:00
a = 10,
a -= 5
2013-09-26 08:59:29 +02:00
}
2014-03-24 09:06:16 +01:00
is equivalent to:
{
a = 10,
a = a - 5
}
2013-09-26 08:59:29 +02:00
2014-02-05 14:27:06 +01:00
#### <a id="operator-multiply-assignment"></a> Operator \*=
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
The *= operator is a shortcut. The following expression:
2013-09-26 08:59:29 +02:00
{
a = 60,
a *= 5
}
2014-03-24 09:06:16 +01:00
is equivalent to:
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
{
a = 60,
a = a * 5
}
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
#### <a id="operator-dividing-assignment"></a> Operator /=
2013-09-26 08:59:29 +02:00
2014-03-24 09:06:16 +01:00
The /= operator is a shortcut. The following expression:
2013-09-26 08:59:29 +02:00
{
a = 300,
a /= 5
}
2014-03-24 09:06:16 +01:00
is equivalent to:
2013-09-26 14:01:29 +02:00
2014-03-24 09:06:16 +01:00
{
a = 300,
a = a / 5
}
2013-09-26 08:59:29 +02:00
2014-02-05 14:27:06 +01:00
### <a id="indexer"></a> Indexer
2013-09-26 08:59:29 +02:00
2013-09-27 07:19:13 +02:00
The indexer syntax provides a convenient way to set dictionary elements.
2013-09-26 08:59:29 +02:00
Example:
2014-03-30 11:52:39 +02:00
{
hello.key = "world"
}
Example (alternative syntax):
2013-09-26 08:59:29 +02:00
{
hello["key"] = "world"
}
This is equivalent to writing:
{
hello += {
key = "world"
}
}
2014-03-30 11:52:39 +02:00
### <a id="template-imports"></a> Template Imports
2013-09-26 08:59:29 +02:00
2014-03-30 11:52:39 +02:00
Objects can import attributes from other objects.
2013-09-26 08:59:29 +02:00
Example:
template Host "default-host" {
2014-03-30 11:52:39 +02:00
macros.color = "red"
2013-09-26 08:59:29 +02:00
}
2014-03-27 12:30:24 +01:00
template Host "test-host" {
import "default-host",
2014-03-30 11:52:39 +02:00
macros.color = "blue"
2013-09-26 08:59:29 +02:00
}
2014-03-27 12:30:24 +01:00
object Host "localhost" {
import "test-host",
2014-03-30 11:52:39 +02:00
macros.address = "127.0.0.1",
macros.address6 = "::1"
2013-09-26 08:59:29 +02:00
}
2013-10-07 09:35:44 +02:00
The `default-host` and `test-host` objects are marked as templates
using the `template` keyword. Unlike ordinary objects templates are not
2013-10-10 16:55:59 +02:00
instantiated at run-time. Parent objects do not necessarily have to be
2014-03-30 11:52:39 +02:00
templates, however in general they are.
2013-09-26 08:59:29 +02:00
> **Note**
>
2014-03-30 11:52:39 +02:00
> The macros dictionary for the `localhost` object contains all three
> macros and the macro `color` has the value `"blue"`.
2013-09-26 08:59:29 +02:00
2013-09-26 14:01:29 +02:00
Parent objects are resolved in the order they're specified using the
2014-03-27 12:30:24 +01:00
`import` keyword.
2013-09-26 08:59:29 +02:00
2014-02-12 11:49:38 +01:00
### <a id="constants"></a> Constants
2013-09-26 08:59:29 +02:00
2014-02-12 11:49:38 +01:00
Global constants can be set using the `const` keyword:
2013-09-26 08:59:29 +02:00
2014-02-12 11:49:38 +01:00
const VarName = "some value"
2013-09-26 08:59:29 +02:00
2014-03-30 10:28:44 +02:00
Once defined a constant can be access from any file. Constants cannot be changed
once they are set.
2013-12-04 11:04:36 +01:00
2014-03-18 11:44:09 +01:00
### <a id="apply"></a> Apply
2014-03-30 11:52:39 +02:00
The `apply` keyword can be used to create new objects which are associated with
another group of objects.
2014-03-29 01:13:28 +01:00
apply Service "ping" {
import "generic-service",
check_command = "ping4",
assign where host.name == "localhost"
2014-03-18 11:44:09 +01:00
}
2014-03-30 11:52:39 +02:00
In this example the `assign where` condition is a boolean expression which is
evaluated for all objects of type `Host` and a new service with name "ping"
2014-03-29 01:13:28 +01:00
is created for each matching host.
2014-03-18 11:44:09 +01:00
2014-03-29 01:13:28 +01:00
Depending on the object type used in the `apply` expression additional local
variables may be available for use in the `where` condition:
2014-03-18 11:44:09 +01:00
2014-03-30 11:52:39 +02:00
Source Type | Target Type | Variables
-----------------|-------------|--------------
Service | Host | host
Dependency | Service | host, service
Notification | Service | host, service
ScheduledDowntime| Service | host, service
> **Note**
>
> Any valid config attribute can be accessed using the `host` and `service`
> variables. For example, `host.macros.address` would return the host's
> "address" macro - or null if it doesn't have that macro.
### <a id="boolean-values"></a> Boolean Values
2014-03-30 17:43:59 +02:00
The `assign where` and `ignore where` statements, the `!` , `&&` and `||`
2014-03-30 11:52:39 +02:00
operators as well as the `bool()` function convert their arguments to a
boolean value based on the following rules:
Description | Example Value | Boolean Value
---------------------|-------------------|--------------
Empty value | null | false
Zero | 0 | false
Non-zero integer | -23945 | true
Empty string | "" | false
Non-empty string | "Hello" | true
Empty array | [] | false
Non-empty array | [ "Hello" ] | true
Empty dictionary | {} | false
Non-empty dictionary | { key = "value" } | true
2013-09-26 08:59:29 +02:00
2013-09-27 10:44:24 +02:00
### <a id="comments"></a> Comments
2013-09-26 08:59:29 +02:00
The Icinga 2 configuration format supports C/C++-style comments.
Example:
/*
This is a comment.
*/
object Host "localhost" {
check_interval = 30, // this is also a comment.
retry_interval = 15
}
2014-02-05 14:27:06 +01:00
### <a id="includes"></a> Includes
2013-09-26 08:59:29 +02:00
2013-10-07 09:35:44 +02:00
Other configuration files can be included using the `include` directive.
2013-09-26 08:59:29 +02:00
Paths must be relative to the configuration file that contains the
2013-10-07 09:35:44 +02:00
`include` directive.
2013-09-26 08:59:29 +02:00
Example:
include "some/other/file.conf"
include "conf.d/*.conf"
> **Note**
>
> Wildcard includes are not recursive.
Icinga also supports include search paths similar to how they work in a
C/C++ compiler:
include < itl / itl . conf >
Note the use of angle brackets instead of double quotes. This causes the
config compiler to search the include search paths for the specified
2014-03-30 11:52:39 +02:00
file. By default $PREFIX/share/icinga2 is included in the list of search
2013-09-27 13:56:11 +02:00
paths. Additional include search paths can be added using
[command-line options ](#cmdline ).
2013-09-26 08:59:29 +02:00
Wildcards are not permitted when using angle brackets.
2014-02-05 14:27:06 +01:00
### <a id="recursive-includes"></a> Recursive Includes
2013-11-29 10:39:48 +01:00
The `include_recursive` directive can be used to recursively include all
files in a directory which match a certain pattern.
Example:
include_recursive "conf.d" "*.conf"
include_recursive "templates"
The first parameter specifies the directory from which files should be
recursively included.
The file names need to match the pattern given in the second parameter.
When no pattern is specified the default pattern "*.conf" is used.
2013-09-27 13:56:11 +02:00
### <a id="library"></a> Library directive
2013-09-26 08:59:29 +02:00
2013-10-07 09:35:44 +02:00
The `library` directive can be used to manually load additional
2013-09-26 08:59:29 +02:00
libraries. Libraries can be used to provide additional object types and
2014-03-30 11:52:39 +02:00
functions.
2013-09-26 08:59:29 +02:00
Example:
library "snmphelper"
> **Note**
>
2014-03-30 11:52:39 +02:00
> The `icinga` and `methods` libraries is automatically loaded at startup.
> You don't need to load them manually.
2013-09-26 14:01:29 +02:00
2013-10-08 14:10:14 +02:00
<!--
2014-02-05 14:27:06 +01:00
### <a id="type-definition"></a> Type Definition
2013-09-26 08:59:29 +02:00
By default Icinga has no way of semantically verifying its configuration
objects. This is where type definitions come in. Using type definitions
you can specify which attributes are allowed in an object definition.
Example:
2014-03-29 01:13:28 +01:00
%type Pizza {
2013-09-26 08:59:29 +02:00
%require "radius",
2014-03-29 01:13:28 +01:00
%attribute %number "radius",
2013-09-26 08:59:29 +02:00
2014-03-29 01:13:28 +01:00
%attribute %dictionary "ingredients" {
2013-09-26 08:59:29 +02:00
%validator "ValidateIngredients",
2014-03-29 01:13:28 +01:00
%attribute %string "*",
2013-09-26 08:59:29 +02:00
2014-03-29 01:13:28 +01:00
%attribute %dictionary "*" {
%attribute %number "quantity",
%attribute %string "name"
2013-09-26 08:59:29 +02:00
}
},
%attribute any "custom::*"
}
The Pizza definition provides the following validation rules:
2013-10-07 09:35:44 +02:00
- Pizza objects must contain an attribute `radius` which has to be a
2013-09-26 08:59:29 +02:00
number.
2013-10-07 09:35:44 +02:00
- Pizza objects may contain an attribute `ingredients` which has to be
2013-09-26 08:59:29 +02:00
a dictionary.
- Elements in the ingredients dictionary can be either a string or a
dictionary.
2013-10-07 09:35:44 +02:00
- If they're a dictionary they may contain attributes `quantity` (of
type number) and `name` (of type string).
2013-09-26 08:59:29 +02:00
2014-03-30 11:52:39 +02:00
- The s
- cript function `ValidateIngredients` is run to perform further
2013-09-26 08:59:29 +02:00
validation of the ingredients dictionary.
- Pizza objects may contain attribute matching the pattern
2013-10-07 15:02:12 +02:00
`custom::*` of any type.
2013-09-26 08:59:29 +02:00
2013-10-07 15:02:12 +02:00
Valid types for type rules include:
2014-03-29 01:13:28 +01:00
* %any
* %number
* %string
* %scalar (an alias for string)
* %dictionary
* %array
2013-09-26 14:01:29 +02:00
2013-10-08 14:10:14 +02:00
-->