Skip to content

Commit 3587463

Browse files
William CalliariWilliam Calliari
authored andcommitted
Document the ElastisearchDatastreamWriter
Explain the configuration options and goals for the writer in the documentation. Add support for the new config options and keywords to the syntax highlighting for nano and vim.
1 parent 15e2cc3 commit 3587463

File tree

4 files changed

+256
-1
lines changed

4 files changed

+256
-1
lines changed

doc/09-object-types.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,130 @@ for an example.
12411241
TLS for the HTTP proxy can be enabled with `enable_tls`. In addition to that
12421242
you can specify the certificates with the `ca_path`, `cert_path` and `cert_key` attributes.
12431243

1244+
### ElasticsearchDatastreamWriter <a id="objecttype-elasticsearchdatastreamwriter"></a>
1245+
1246+
Writes check result metrics and performance data to an Elasticsearch timeseries datastream.
1247+
This configuration object is available as the [elasticsearch datastream feature](14-features.md#elasticsearchdatastream-writer).
1248+
1249+
1250+
Example:
1251+
1252+
```
1253+
object ElasticsearchDatastreamWriter "datastreamwriter" {
1254+
host = "127.0.0.1"
1255+
port = 9200
1256+
datastream_namespace = "production"
1257+
1258+
enable_send_perfdata = true
1259+
1260+
host_tags_template = ["icinga-production"]
1261+
filter = {{ "datastream" in host.groups }}
1262+
1263+
flush_threshold = 1024
1264+
flush_interval = 10
1265+
}
1266+
```
1267+
1268+
Configuration Attributes:
1269+
1270+
Name | Type | Description
1271+
--------------------------|-----------------------|----------------------------------
1272+
host | String | **Required.** Elasticsearch host address. Defaults to `127.0.0.1`.
1273+
port | Number | **Required.** Elasticsearch port. Defaults to `9200`.
1274+
enable\_tls | Boolean | **Optional.** Whether to use a TLS stream. Defaults to `false`.
1275+
insecure\_noverify | Boolean | **Optional.** Disable TLS peer verification.
1276+
ca\_path | String | **Optional.** Path to CA certificate to validate the remote host. Requires `enable_tls` set to `true`.
1277+
enable\_ha | Boolean | **Optional.** Enable the high availability functionality. Only valid in a [cluster setup](06-distributed-monitoring.md#distributed-monitoring-high-availability-features). Defaults to `false`.
1278+
flush\_interval | Duration | **Optional.** How long to buffer data points before transferring to Elasticsearch. Defaults to `10s`.
1279+
flush\_threshold | Number | **Optional.** How many data points to buffer before forcing a transfer to Elasticsearch. Defaults to `1024`.
1280+
1281+
Auth:
1282+
1283+
Name | Type | Description
1284+
--------------------------|-----------------------|----------------------------------
1285+
username | String | **Optional.** Basic auth username for Elasticsearch
1286+
password | String | **Optional.** Basic auth password for Elasticsearch
1287+
api_token | String | **Optional.** Authorization token for Elasticsearch
1288+
cert\_path | String | **Optional.** Path to host certificate to present to the remote host for mutual verification. Requires `enable_tls` set to `true`.
1289+
key\_path | String | **Optional.** Path to host key to accompany the cert\_path. Requires `enable_tls` set to `true`.
1290+
1291+
Changing the behavior of the writer:
1292+
1293+
Name | Type | Description
1294+
--------------------------|-----------------------|----------------------------------
1295+
datastream_namespace | String | **Required.** Suffix for the datastream names. Defaults to `default`.
1296+
manage\_index\_template | Boolean | **Optional.** Whether to create and manage the index template in Elasticsearch. This requires the user to have `manage_index_templates` permission in Elasticsearch. Defaults to `true`.
1297+
enable\_send\_perfdata | Boolean | **Optional.** Send parsed performance data metrics for check results. Defaults to `false`.
1298+
enable\_send\_thresholds | Boolean | **Optional.** Whether to send warn, crit, min & max performance data.
1299+
host\_tags\_template | Array | **Optional.** Allows add [tags](https://www.elastic.co/docs/reference/ecs/ecs-base#field-tags) to the document for a Host check result.
1300+
service\_tags\_template | Array | **Optional.** Allows add [tags](https://www.elastic.co/docs/reference/ecs/ecs-base#field-tags) to the document for a Service check result.
1301+
host\_labels\_template | Dictionary | **Optional.** Allows add [labels](https://www.elastic.co/docs/reference/ecs/ecs-base#field-labels) to the document for a Host check result.
1302+
service\_labels\_template | Dictionary | **Optional.** Allows add [labels](https://www.elastic.co/docs/reference/ecs/ecs-base#field-labels) to the document for a Service check result.
1303+
filter | Function | **Optional.** An expression to filter which check results should be sent to Elasticsearch. Defaults to sending all check results.
1304+
1305+
#### Macro Usage (Tags, Labels & Namespace)
1306+
1307+
Macros can be used inside the following template attributes:
1308+
1309+
- host_tags_template (array of strings)
1310+
- service_tags_template (array of strings)
1311+
- host_labels_template (dictionary of key -> string value)
1312+
- service_labels_template (dictionary of key -> string value)
1313+
- datastream_namespace (string)
1314+
1315+
Behavior:
1316+
- Tags: Each array element may contain zero or more macros. If at least one macro is missing/unresolvable, the entire tag element is skipped and a debug log entry is written.
1317+
- Labels: Each dictionary value may contain macros. If at least one macro inside the value is missing, that label key/value pair is skipped and a debug log entry is written.
1318+
- Namespace: The datastream_namespace string may contain macros. If a macro is missing or resolves to an empty value, the writer falls back to the default namespace "default".
1319+
- Validation: A template string with an unterminated '$' (e.g. "$host.name") raises a configuration validation error referencing the original string.
1320+
- Macros never partially substitute: either all macros in the string resolve and the rendered value is used, or (for tags/labels) the entry is skipped.
1321+
- Normalization: Performance data metric labels and the resolved datastream namespace undergo normalization: any leading whitespace and leading special characters are trimmed; all remaining special (non-alphanumeric) characters are replaced with an underscore; consecutive underscores are collapsed; leading/trailing underscores are removed. This ensures stable, Elasticsearch-friendly field and namespace names.
1322+
1323+
Examples:
1324+
1325+
```
1326+
object ElasticsearchDatastreamWriter "example-datastream" {
1327+
datastream_namespace = "$host.vars.env$" // Falls back to "default" if $host.vars.env$ is missing
1328+
1329+
host_tags_template = [
1330+
"env-$host.vars.env$",
1331+
"$host.name$"
1332+
]
1333+
1334+
service_tags_template = [
1335+
"svc-$service.name$",
1336+
"$service.display_name$"
1337+
]
1338+
1339+
host_labels_template = {
1340+
os = "$host.vars.os$"
1341+
fqdn = "$host.name$"
1342+
}
1343+
1344+
service_labels_template = {
1345+
check_cmd = "$service.check_command$"
1346+
attempted_env = "$host.vars.missing_env$" // Skipped if missing_env not set
1347+
}
1348+
1349+
filter = {{ service && "production" in host.groups }}
1350+
}
1351+
```
1352+
1353+
A missing macro example for a host check result:
1354+
- service_tags_template element "svc-$service.name$" is skipped (service not in scope).
1355+
- service_labels_template value "$service.check_command$" is skipped for host check results.
1356+
1357+
#### Filter Expression
1358+
1359+
The filter accepts an expression (function literal) and only the variables host and service are available. (service is null / undefined for host check results.)
1360+
1361+
Examples:
1362+
```
1363+
filter = {{ "production" in host.groups }}
1364+
filter = {{ service && "linux" in host.groups }}
1365+
```
1366+
If the filter returns true, the check result is sent; otherwise it is skipped.
1367+
12441368
### ExternalCommandListener <a id="objecttype-externalcommandlistener"></a>
12451369

12461370
Implements the Icinga 1.x command pipe which can be used to send commands to Icinga.

doc/14-features.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,130 @@ The recommended way of running Elasticsearch in this scenario is a dedicated ser
439439
where you either have the Elasticsearch HTTP API, or a TLS secured HTTP proxy,
440440
or Logstash for additional filtering.
441441

442+
443+
#### Elasticsearch Datastream Writer <a id="elasticsearch-datastream-writer"></a>
444+
445+
> **Note**
446+
>
447+
> This is a newer alternative to the Elasticsearch Writer above. The Elasticsearch Datastream Writer uses
448+
> Elasticsearch's data stream feature and follows the Elastic Common Schema (ECS), providing better performance
449+
> and data organization. Use this writer for new installations. The original Elasticsearch Writer is still
450+
> available for backward compatibility.
451+
>
452+
> OpenSearch: The data stream mode and ECS component template usage differ slightly in OpenSearch. The
453+
> ElasticsearchDatastreamWriter focuses on Elasticsearch compatibility first. OpenSearch can ingest the data,
454+
> but you may need to adapt the installed index/component templates manually (e.g. remove time_series mode if
455+
> unsupported, adjust mappings). The option `manage_index_template` will not work with OpenSearch.
456+
457+
458+
This feature sends check results with performance data to an [Elasticsearch](https://www.elastic.co/products/elasticsearch) instance or cluster.
459+
460+
> **Note**
461+
>
462+
> This feature requires Elasticsearch to support time series data streams (Elasticsearch 8.x+), and to have the ECS
463+
> component template installed. It was tested successfully with Elasticsearch 8.12 and 9.0.8.
464+
465+
466+
Enable the feature and restart Icinga 2.
467+
468+
```bash
469+
icinga2 feature enable elasticsearchdatastream
470+
```
471+
472+
The default configuration expects an Elasticsearch instance running on `localhost` on port `9200`
473+
and writes to datastreams with the pattern `metrics-icinga2.<check>-<namespace>`.
474+
475+
More configuration details can be found [here](09-object-types.md#objecttype-elasticsearchdatastreamwriter).
476+
477+
#### Current Elasticsearch Schema <a id="elasticsearch-datastream-writer-schema"></a>
478+
479+
The documents for the ElasticsearchDatastreamWriter try to follow the [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/index.html)
480+
version `8.0` as close as possible, with some additional changes to fit the Icinga 2 data model.
481+
All documents are written to a data stream of the format `metrics-icinga.<check>-<datastream_namespace>`,
482+
where `<check>` is the name of the checkcommand being executed to keep the number of fields per index low
483+
and documents with the same performance data grouped together. `<datastream_namespace>` is an optional
484+
configuration parameter to further separate documents, e.g. by environment like `production` or `development`.
485+
The `datastream_namespace` can also be used to separate documents e.g. by hostgroups or zones, by using the
486+
`filter` function to filter the check results and use several writers with different namespaces.
487+
Time‑series dimensions are applied to `host.name` and (when present) `service.name`, aligning with ECS host and service
488+
definitions: [ECS host fields](https://www.elastic.co/guide/en/ecs/current/ecs-host.html),
489+
[ECS service fields](https://www.elastic.co/guide/en/ecs/current/ecs-service.html).
490+
491+
Icinga 2 automatically adds the following threshold metrics
492+
if existing:
493+
494+
```
495+
perfdata.<perfdata-label>.min
496+
perfdata.<perfdata-label>.max
497+
perfdata.<perfdata-label>.warn
498+
perfdata.<perfdata-label>.crit
499+
```
500+
501+
#### Adding additional tags and labels <a id="elasticsearch-datastream-writer-custom-tags-labels"></a>
502+
503+
Additionally it is possible to configure custom tags and labels that are applied to the metrics via
504+
`host_tags_template`/`service_tags_template` and `host_labels_template`/`service_labels_template`
505+
respectively. Depending on whether the write event was triggered on a service or host object,
506+
additional tags are added to the ElasticSearch entries.
507+
508+
A host metrics entry configured with the following `host_tags_template`:
509+
510+
```
511+
host_tags_template = ["production", "$host.groups"]
512+
host_labels_template = {
513+
os = "$host.vars.os$"
514+
}
515+
```
516+
517+
Will in addition to the above mentioned lines also contain:
518+
519+
```
520+
"tags": ["production", "linux-servers;group-A"],
521+
"labels": { "os": "Linux" }
522+
```
523+
524+
#### Filtering check results <a id="elasticsearch-datastream-writer-filtering"></a>
525+
526+
You can filter which check results are sent to Elasticsearch by using the `filter` parameter.
527+
It takes a function (expression) evaluated for every check result and must return a boolean.
528+
If the function returns `true`, the check result is sent; otherwise it is skipped.
529+
530+
Only the variables `host` and `service` are available inside this expression.
531+
For host check results `service` is not set (null/undefined). No other variables (such as
532+
the raw check result object) are exposed.
533+
534+
Example configuration that only sends service check results for hosts in the `linux-server` hostgroup:
535+
536+
537+
```
538+
object ElasticsearchDatastreamWriter "elasticsearchdatastream" {
539+
...
540+
datastream_namespace = "production"
541+
filter = {{ service && "linux-server" in host.groups }}
542+
}
543+
```
544+
545+
#### Elasticsearch Datastream Writer in Cluster HA Zones <a id="elasticsearch-datastream-writer-cluster-ha"></a>
546+
547+
The Elasticsearch Datastream Writer feature supports [high availability](06-distributed-monitoring.md#distributed-monitoring-high-availability-features)
548+
in cluster zones.
549+
550+
By default, all endpoints in a zone will activate the feature and start
551+
writing events to the Elasticsearch HTTP API. In HA enabled scenarios,
552+
it is possible to set `enable_ha = true` in all feature configuration
553+
files. This allows each endpoint to calculate the feature authority,
554+
and only one endpoint actively writes events, the other endpoints
555+
pause the feature.
556+
557+
When the cluster connection breaks at some point, the remaining endpoint(s)
558+
in that zone will automatically resume the feature. This built-in failover
559+
mechanism ensures that events are written even if the cluster fails.
560+
561+
The recommended way of running Elasticsearch in this scenario is a dedicated server
562+
where you either have the Elasticsearch HTTP API, or a TLS secured HTTP proxy,
563+
or Logstash for additional filtering.
564+
565+
442566
### Graylog Integration <a id="graylog-integration"></a>
443567

444568
#### GELF Writer <a id="gelfwriter"></a>

tools/syntax/nano/icinga2.nanorc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
### Nano synteax file
2-
### Icinga2 object configuration file
2+
### Icinga2 object configuration file
33

44
syntax "icinga2" "/etc/icinga2/.*\.conf$" "/usr/share/icinga2/include/(plugin|itl|.*\.conf$)"
55

66
## objects types
77
icolor brightgreen "object[ \t]+(host|hostgroup|service|servicegroup|user|usergroup)"
88
icolor brightgreen "object[ \t]+(checkcommand|notificationcommand|eventcommand|notification)"
99
icolor brightgreen "object[ \t]+(timeperiod|scheduleddowntime|dependency|perfdatawriter)"
10+
icolor brightgreen "object[ \t]+(elasticsearchwriter|elasticsearchdatastreamwriter)"
1011
icolor brightgreen "object[ \t]+(graphitewriter|idomysqlconnection|idomysqlconnection)"
1112
icolor brightgreen "object[ \t]+(livestatuslistener|externalcommandlistener)"
1213
icolor brightgreen "object[ \t]+(compatlogger|checkcomponent|notificationcomponent)"
@@ -32,6 +33,9 @@ icolor red "(^|^\s+)(port|ranges|retry_interval|rotation_interval|rotation_met
3233
icolor red "(^|^\s+)(service_format_template|service_name|service_name_template|service_perfdata_path|service_temp_path)"
3334
icolor red "(^|^\s+)(severity|socket_path|socket_type|spool_dir|states|status_path|table_prefix)"
3435
icolor red "(^|^\s+)(timeout|times|types|update_interval|user|user_groups|users|volatile|zone)"
36+
icolor red "(^|^\s+)(insecure_noverify|flush_interval|flush_threshold|filter|api_token|username|enable_tls)"
37+
icolor red "(^|^\s+)(enable_send_perfdata|datastream_namespace|enable_send_thresholds|manage_index_template)"
38+
icolor red "(^|^\s+)(host_labels_template|service_labels_template|host_tags_template|service_tags_template)"
3539
icolor red "(^|^\s+)(vars\.\w+)"
3640

3741

tools/syntax/vim/syntax/icinga2.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ syn match Lambda "{{}}"
5454
" Object types
5555
syn keyword icinga2ObjType ApiListener ApiUser CheckCommand CheckerComponent
5656
syn keyword icinga2ObjType Comment Dependency Downtime ElasticsearchWriter
57+
syn keyword icinga2ObjType ElasticsearchDatastreamWriter
5758
syn keyword icinga2ObjType Endpoint EventCommand ExternalCommandListener
5859
syn keyword icinga2ObjType FileLogger GelfWriter GraphiteWriter Host HostGroup
5960
syn keyword icinga2ObjType IcingaApplication IdoMysqlConnection IdoPgsqlConnection
@@ -95,6 +96,8 @@ syn keyword icinga2ObjAttr contained ssl_ca ssl_capath ssl_ca_cert ssl_cert ss
9596
syn keyword icinga2ObjAttr contained states status_path table_prefix ticket_salt
9697
syn keyword icinga2ObjAttr contained timeout times tls_handshake_timeout tls_protocolmin
9798
syn keyword icinga2ObjAttr contained types update_interval user user_groups username users volatile zone
99+
syn keyword icinga2ObjAttr contained api_token datastream_namespace manage_index_template insecure_noverify
100+
syn keyword icinga2ObjAttr contained host_tags_template service_tags_template host_labels_template service_labels_template
98101
syn match icinga2ObjAttr contained "\(vars.\w\+\)"
99102

100103
" keywords: https://icinga.com/docs/icinga2/latest/doc/17-language-reference/#reserved-keywords

0 commit comments

Comments
 (0)