Alert fingerprint and time window: deduplicating correlation in Wazuh
Merge repeating alerts into one incident: frequency and ignore in rules, a fingerprint with a time bucket, an OpenSearch upsert write, and collapse for review.
Rules with frequency and timeframe limit the number of alerts, but they give no stable identifier under which an analyst sees one incident with a counter. The fingerprint fills that role: a hash of the key alert fields and a time window number, used as the _id of a document in OpenSearch.
What Wazuh does on its own
The rules engine has three mechanisms that suppress repeats before an alert is written. The rule syntax documentation describes them.
| Attribute or option | Meaning according to the documentation | Range |
|---|---|---|
frequency | number of rule matches needed to generate an alert | 2 to 9999 |
timeframe | window in seconds, used together with frequency | 1 to 99999 |
ignore | time in seconds during which the rule is ignored after it fires, to avoid a flood | 1 to 999999 |
if_matched_sid | matches only if the given rule fired in the given period | rule identifier |
same_srcip, same_id, same_field | events must have the same value of the field | no value or a field name |
global_frequency | counts events from all agents, by default only the same agent | works at the manager level, not the cluster |
An example built the same way as the one in the documentation (rule 50180 with frequency="8" timeframe="120" ignore="60"), with my own identifiers:
<group name="local,example,">
<rule id="100010" level="3">
<decoded_as>json</decoded_as>
<field name="event">login_failed</field>
<description>Example App: failed login</description>
</rule>
<rule id="100020" level="10" frequency="8" timeframe="120" ignore="60">
<if_matched_sid>100010</if_matched_sid>
<same_srcip />
<description>Example App: repeated failed logins from one source</description>
</rule>
</group>
Rule 100020 fires a level 10 alert when rule 100010 matches 8 times within 120 seconds from the same source address, and after firing it stays silent for 60 seconds. The syntax details, evaluation order and testing are covered in the post event correlation in Wazuh.
For same_field the documentation notes two things. The counter covers events with the same field value, and the alert is generated by the event that sees this value in the previous events. The same_field and not_same_field filters do not work for static fields (user, srcip, dstip), which have their own options.
What this mechanism does not give
ignoreis a setting of a single rule. When the time passes, the rule fires another alert, and the earlier firings are not counted together anywhere.- An alert carries no incident key. The example alert in the documentation has the fields
rule.id,rule.firedtimes,agent.id,data.*,id,previous_outputandfull_log, but none of them identifies a series of repeats. - The alert
idfield (1583319628.14426in the example) is unique per event, so it is no good for grouping.
Fingerprint: a hash of fields and a window number
The recommended key is a SHA-256 hash of the fields that define the same problem, plus the number of the time bucket:
fingerprint = sha256( rule.id | agent.id | data.srcip | data.dstuser | floor(time / window) )
The choice of fields is a decision about granularity. The typical alert fields behave like this:
| Field | In the key? | Reason |
|---|---|---|
rule.id | yes | tells different detections apart |
agent.id | usually yes | the same problem on two hosts is two incidents |
data.srcip, data.dstuser | depends on the rule | dynamic fields, they exist only for the decoder that fills them |
alert id | no | changes with every event |
timestamp | no, only as a bucket | the full time would split every alert into a separate incident |
full_log, previous_output | no | contain variable text and numbers |
rule.firedtimes | no | the counter grows with every alert |
Text fields must be normalized before hashing (lowercase, trimmed whitespace), so that the values Example-User and example-user do not produce two keys. Replace a missing field with an empty string, so that the order and the number of separators stay constant.
Script
The script reads an alert in JSON format and prints the fingerprint. The data is synthetic, and the timestamp is written in UTC.
#!/usr/bin/env bash
# Fingerprint = sha256 of normalized key fields plus the time bucket.
# Usage: fp.sh alert.json [window_seconds]
set -euo pipefail
window="${2:-900}"
jq -r --argjson w "$window" '
(.timestamp | sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601) as $t
| [ .rule.id,
.agent.id,
(.data.srcip // ""),
(.data.dstuser // "" | ascii_downcase),
($t / $w | floor | tostring)
] | join("|")' "$1" | tr -d '\n' | shasum -a 256 | cut -d' ' -f1
Example alert (alert.json):
{"timestamp":"2026-11-12T20:14:31.973Z","rule":{"id":"100010","level":10,"description":"Example App: failed login"},"agent":{"id":"001","name":"agent-01"},"data":{"srcip":"203.0.113.7","dstuser":"example-user"}}
The script run with a 900-second window on this alert and on a copy with the time 20:14:59 returns the same hash. A copy with the time 20:15:01 gives a different hash, even though it is about 30 seconds from the first alert. The bucket numbers are 1993904 and 1993905 respectively. On Linux use sha256sum instead of shasum -a 256.
Time window: why the fingerprint needs it
A fingerprint without a time bucket never closes. The same rule, host and source give the same key today and in a month, so a new event lands in an old incident, and the analyst does not see that the attack came back after a break. The bucket forces a new document once the window ends.
A fixed bucket has an edge flaw, visible in the example above: two events a few dozen seconds apart can fall into different windows if a bucket boundary separates them. A sliding window, like the timeframe of Wazuh rules, does not have this effect, but it needs state on the processing side.
| Goal | Solution |
|---|---|
| simple write and report with no extra state | fixed bucket, time rounded down |
| no artificial split of a series | sliding window in the rule (frequency and timeframe), fingerprint from the last bucket |
| review after the fact | date_histogram aggregation with fixed_interval |
The OpenSearch documentation says that fixed_interval buckets are aligned to the start of the Unix epoch, not to the start of the day. A 900-second window and a fixed_interval of 15m therefore define the same boundaries as the formula floor(time / window).
Writing the incident in OpenSearch
The fingerprint goes into the document _id in a separate incidents index.
First write
The Index Document API offers the path PUT {index}/_create/{id}. The documentation describes it as adding a document only if no document with that identifier exists, and otherwise the operation fails. A plain PUT {index}/_doc/{id} behaves differently: an existing document is updated, and its version grows. The op_type parameter accepts create and index, and when an identifier is given, index is the default.
_create lets you tell the first alert of a series from the later ones. On every following alert the client gets an error and moves on to an update.
Counter update
The Update API (POST /{index}/_update/{id}) has the scripted_upsert option, which runs the script whether or not the document exists. In this mode the documentation requires the script and upsert fields. The script operates on the ctx._source object. On this basis one call can create the incident and bump the counter:
POST /example-correlation-incidents/_update/3a42337915f61caa4237c53da068d92b8b7abc6c4294ffea9d1496b6236f4fde
{
"scripted_upsert": true,
"script": {
"source": "if (ctx._source.count == null) { ctx._source.count = 0; ctx._source.first_seen = params.ts; ctx._source.rule_id = params.rule_id; } ctx._source.count += 1; ctx._source.last_seen = params.ts;",
"params": { "ts": "2026-11-12T20:14:31Z", "rule_id": "100010" }
},
"upsert": {}
}
The script is a recommendation based on the scripted_upsert example in the documentation.
Two parallel updates of the same document can collide. The documentation describes a version conflict error (HTTP 409, version_conflict_engine_exception) for requests with if_seq_no and if_primary_term, and the retry_on_conflict parameter, whose default value is 0. Recommendation: when several processes write to one index, set it to a value above zero.
The variant without a counter is doc_as_upsert: true: the content of the doc field serves both for the update and for the insert. It is enough when you care only about last_seen and read the number of repeats from the alerts index.
Review: collapse and date_histogram
When alerts with a fingerprint field (type keyword) land in the index, the collapse parameter returns one, the best, document per group:
GET /example-alerts/_search
{
"query": { "range": { "@timestamp": { "gte": "now-24h" } } },
"collapse": { "field": "fingerprint" },
"sort": [ { "@timestamp": "desc" } ]
}
The documentation sets conditions: the field must be of type keyword or numeric, have doc values enabled and a single value per document, and a query with collapse cannot be combined with scroll or rescore. Use search_after for pagination. The number of documents in a group comes from a separate terms aggregation on the same field, because collapse shows only the top of the group.
Trend over time, with the same boundaries as the bucket in the script:
GET /example-alerts/_search
{
"size": 0,
"aggs": {
"per_window": {
"date_histogram": { "field": "@timestamp", "fixed_interval": "15m", "min_doc_count": 1 },
"aggs": { "rules": { "terms": { "field": "rule.id", "size": 5 } } }
}
}
}
The default min_doc_count in date_histogram is 0, so empty buckets appear in the response. Setting it to 1 skips them.
The incidents index grows more slowly than the alerts index, but it still needs its own policy. An ISM policy that covers only indices matching its own name pattern is described in the post data retention in OpenSearch, so the incidents index name must match the chosen policy. Notifications from the integrator, including limiting their number, are covered in the post integrator notifications. Binding a notification to the fingerprint, that is one message per incident, is a recommendation, not a Wazuh feature.
How to read the result in triage
The counter and the first_seen, last_seen pair answer the analyst’s first questions: since when, how often and whether the series is still going. The alert fields the key is built from are described in the post Wazuh alert triage. An example of reading a document:
curl -s -k -u "$WAZUH_INDEXER_USER:$WAZUH_INDEXER_PASS" \
"https://indexer.example.com:9200/example-correlation-incidents/_search" \
-H "Content-Type: application/json" \
-d '{"size":5,"sort":[{"last_seen":"desc"}]}' \
| jq -r '.hits.hits[] | [._id[0:12], ._source.count, ._source.first_seen, ._source.last_seen] | @tsv'
The -k option skips verification of the indexer certificate and is only suitable for a lab. In production use --cacert with the indexer CA certificate.
Recommended rules
- Match the window to your team’s response time. Too short splits a series, too long hides the return of an attack.
- Store the fields used for the key in the document, so the result can be verified without hashing again.
- Treat
frequencyandignoreas noise reduction in the engine, and the fingerprint as a way of reporting. The two mechanisms do not exclude each other. - Do not cut out the source alerts. The incident is a view over the data, and the original alerts stay in the index.
What the documentation does not specify
- Wazuh does not compute or store an alert fingerprint. The rules documentation and the example alert contain no such field.
- The OpenSearch pages say that
_createfails for an existing identifier, but they give the HTTP code of that error only for theif_seq_noandif_primary_termconflict (409). - There are no recommendations on window size or on choosing the fields for the key. Both decisions depend on the nature of the detection.
- The counter-increment script relies on the
scripted_upsertpattern from the documentation, but it was not run against an index. - The example alert in the Wazuh documentation has a timestamp with a zone offset (
-0800), while the script requires UTC with the letterZ. Normalization to UTC must be ensured before bucketing.
Sources
- https://documentation.wazuh.com/current/user-manual/ruleset/ruleset-xml-syntax/rules.html
- https://docs.opensearch.org/latest/api-reference/document-apis/index-document/
- https://docs.opensearch.org/latest/api-reference/document-apis/update-document/
- https://docs.opensearch.org/latest/search-plugins/collapse-search/
- https://docs.opensearch.org/latest/aggregations/bucket/date-histogram/
- https://docs.opensearch.org/latest/aggregations/bucket/terms/