Export to Elasticsearch#
Index the keepalives, map snapshots and decoder metrics of your targets in Elasticsearch, through the OpenTelemetry Collector’s Elasticsearch exporter, and alert on them from Kibana or Elastic Security.
This is a do-it-yourself example to get started from, not an integration that shirudo ships or maintains. Adapt retention, access control and sizing to your deployment.
Before you begin#
Targets that export to a collector, as Monitor and export telemetry describes, with the collector’s
otlpreceiver set up there.The OpenTelemetry Collector Contrib distribution,
otelcol-contrib, built with Go 1.24 or later. The contrib distribution includes the Elasticsearch exporter; Go 1.24 offers the hybrid key exchange the targets require.Elasticsearch 9.4 or later, whose ES|QL has the
LASTfunction that the query of the last verdict uses, and Kibana.
The exporter’s log and metric support is beta.
Set up the exporter#
In Kibana’s Dev Tools console, create an API key that may only write to the data streams the exporter uses:
POST /_security/api_key { "name": "shirudo-otel", "role_descriptors": { "shirudo-otel": { "indices": [ { "names": ["logs-*.otel-*", "metrics-*.otel-*"], "privileges": ["auto_configure", "create_doc"] } ] } } }Keep the
encodedvalue of the answer for the collector.Add the exporter and the pipelines to the collector’s configuration, next to the
otlpreceiver:exporters: elasticsearch: endpoint: https://<elasticsearch-host>:9200 api_key: ${env:ELASTICSEARCH_API_KEY} tls: ca_file: /etc/otelcol/elasticsearch-ca.pem service: pipelines: logs: receivers: [otlp] exporters: [elasticsearch] metrics: receivers: [otlp] exporters: [elasticsearch]
ELASTICSEARCH_API_KEYholds the encoded key and comes from the collector’s environment, andca_filenames the CA that signed the Elasticsearch certificate.Restart the collector.
The exporter writes in its default otel mapping mode: log records go
to the data stream logs-generic.otel-default and metrics to
metrics-generic.otel-default. A document keeps the OTLP layout, with
the attributes under attributes, the resource attributes under
resource.attributes, a string body under body.text and a
structured body under body.structured. Elasticsearch’s OpenTelemetry
templates also offer each attribute under its own name, so host.name
works in queries.
A keepalive’s body is a string, the JSON object the target’s TPM quoted,
so it lands in body.text. The queries below take the keys they need
out of it with GROK; shirudo status lists the keys,
which always come in the same order.
Check the data#
In Discover, switch to ES|QL and list the latest keepalives:
FROM logs-generic.otel-default | WHERE event_name == "shirudo.keepalive" | GROK body.text "\"verdict\":\"%{DATA:verdict}\"" | SORT @timestamp DESC | KEEP @timestamp, host.name, verdict, body.text | LIMIT 10A target sends a keepalive every minute, so each target shows up within a minute or two of the restart.
Show the last verdict of every target and when it last reported:
FROM logs-generic.otel-default | WHERE event_name == "shirudo.keepalive" | GROK body.text "\"verdict\":\"%{DATA:verdict}\"" | STATS verdict = LAST(verdict, @timestamp), last_seen = MAX(@timestamp) BY host.name | SORT last_seenRead the map snapshots of one upatch:
FROM logs-generic.otel-default | WHERE shirudo.upatch.name == "<upatch>" | KEEP @timestamp, host.name, shirudo.map.name, body.structured
body.structuredholds what the map’s decoder returned, or the map’s entries when the upatch ships no decoder. ES|QL returns it whole and cannot select a field inside it. A decoder that emits metrics writes tometrics-generic.otel-default, with one field per metric.
Alert on the data#
Each query below returns one row for every target that needs a look.
In Kibana, create an Elasticsearch query rule for each, with ES|QL as
the query type, @timestamp as the time field and a time window at
least as long as the query’s; the rule alerts when the query returns
rows. In Elastic Security, use the query in a detection rule of type
ES|QL instead. Monitor and export telemetry explains each signal under
what to alert on.
Find targets that stopped sending keepalives. Ten minutes covers several keepalive intervals and a tree sync of a few minutes, which holds the config operation lock that a keepalive waits for; a target whose tree syncs run for longer needs a longer threshold:
FROM logs-generic.otel-default | WHERE event_name == "shirudo.keepalive" AND @timestamp > NOW() - 1 day | STATS last_seen = MAX(@timestamp) BY host.name | WHERE last_seen < NOW() - 10 minutes
A target silent for longer than a day drops out of the query.
Find targets that reported a verdict other than
okin the last five minutes:FROM logs-generic.otel-default | WHERE event_name == "shirudo.keepalive" AND @timestamp > NOW() - 5 minutes | GROK body.text "\"verdict\":\"%{DATA:verdict}\"" | WHERE verdict != "ok" | STATS reports = COUNT(*) BY host.name, verdictFind targets whose guards refused operations in the last ten minutes:
FROM logs-generic.otel-default | WHERE event_name == "shirudo.keepalive" AND @timestamp > NOW() - 10 minutes | GROK body.text "\"boot_id\":\"%{DATA:boot_id}\"" | GROK body.text "\"tamper\":%{DATA:tamper},\"integrity\"" | STATS counts = COUNT_DISTINCT(tamper) BY host.name, boot_id | WHERE counts > 1tamperlists every counter since boot. The counters only grow within a boot and start at zero at the next, so more than one list in the keepalives of oneboot_idmeans a counter rose, and a reboot in the window reports nothing.integritylists the integrity counters the same way; the query with"\"integrity\":%{DATA:integrity},\"tree_id\""finds targets that refused a change to their running kernel.
Next steps#
OTLP documents for every field a target sends
Write a Lua decoder to turn a map into log records or metrics
SIEM export for how the records reach a backend and what to build on them