You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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`.
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`.
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.
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.
> 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 <aid="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
0 commit comments