# Event correlation in Wazuh rules: frequency, timeframe and same_*

> Correlation in Wazuh rules: frequency and timeframe, if_matched_sid, same_* and different_* grouping, ignore, and testing event series in wazuh-logtest.

Published: 2026-11-12. Category: Detection. Tags: Wazuh 4. MITRE ATT&CK: T1110, T1499. Wazuh rules: 5712, 30202, 40113, 50180, 61642, 61643. URL: https://wazuh.blog/en/blog/wazuh-event-correlation/ Polish original: https://wazuh.blog/blog/wazuh-korelacja-zdarzen/

A Wazuh correlation rule evaluates repeated matches of other rules within a set time. You can also require that a chosen field is the same or different across successive events, and then decide whether the result should create an alert.

This description covers Wazuh 4.x. According to the Wazuh 5 migration guide (5.0-rc), frequency and threshold rules are not supported, and XML rules must be recreated: [migration from 4.x to Wazuh 5](/en/blog/wazuh-5-installation/#upgrade-to-wazuh-5-and-migration-from-4x).

## When a match becomes correlation

`frequency` sets how many times a rule must match before it generates an alert. `timeframe` sets the time window in seconds and is meant to be used with `frequency`. Allowed values are 2 to 9999 for `frequency` and 1 to 99999 for `timeframe`. A correlation rule usually refers to an earlier rule through `if_matched_sid`, or to a group through `if_matched_group`.

`if_matched_sid` checks whether an alert with the given ID fired within the given number of seconds. It is used together with `frequency` and `timeframe`. `if_matched_group` works the same way for an alert that belongs to the given group. The documentation gives an example where rule 30202 fires when rule 30201 matches 10 times in 120 seconds, and an example where rule 40113 fires on eight matches of the `virus` group in 360 seconds.

Child conditions differ from history correlation. `if_sid` requires that the current log previously matched the given rule. Likewise, `if_group` requires an earlier match of a rule from the given group, and `if_level` matches when the given level from 1 to 16 was matched earlier. `if_matched_sid` refers to an alert triggered earlier, in terms of match count and time window. Both conditions also appear in the article on [rule levels and thresholds](/en/blog/wazuh-rule-levels-and-thresholds/).

Level 0 rules are discarded immediately and are not used with `if_matched_sid`. The source rule must have a level of at least 1. The documentation says that to keep such a rule from being logged, you add the `no_log` option to it, written in the documentation examples as `<options>no_log</options>`.

## Grouping by value

The `same_*` and `different_*` options tie correlation to a value decoded in the events. The first family requires the given value to stay the same; the second requires it to differ. They are used with `frequency` and `timeframe`.

| Compared value | Same value | Different value |
| --- | --- | --- |
| Decoded ID | `same_id` | `different_id` |
| Decoded source IP address | `same_srcip` | `different_srcip` |
| Decoded destination IP address | `same_dstip` | `different_dstip` |
| Decoded source port | `same_srcport` | `different_srcport` |
| Decoded destination port | `same_dstport` | `different_dstport` |
| Location | `same_location` | `different_location` |
| Decoded source user | `same_srcuser` | `different_srcuser` |
| Decoded user | `same_user` | `different_user` |
| Decoded protocol | `same_protocol` | `different_protocol` |
| Decoded action | `same_action` | `different_action` |
| Decoded data | `same_data` | `different_data` |
| Extra decoded data | `same_extra_data` | `different_extra_data` |
| Decoded status | `same_status` | `different_status` |
| Decoded system name | `same_system_name` | `different_system_name` |
| Decoded URL | `same_url` | `different_url` |
| Source GeoIP location | `same_srcgeoip` | `different_srcgeoip` |
| Destination GeoIP location | `same_dstgeoip` | `different_dstgeoip` |

The deprecated aliases are `same_source_ip` for `same_srcip` and `not_same_source_ip` for `different_srcip`.

The dynamic options `same_field` and `different_field` compare the dynamic field named in the rule body. The documentation describes `same_field` as a condition that the value of the dynamic field from the current event must occur the required number of times in earlier events matched by the source rule, within a set time window. `different_field` is the opposite: the field value must differ from the values in earlier events the required number of times. Dynamic filters do not work on static fields such as `user`, `srcip` and `dstip`; for those, use the specific options from the table above.

The example syntax shows a base rule that recognizes the dynamic field `key`, and a correlation rule that compares `key2`:

```xml
<rule id="100001" level="3">
  <decoded_as>json</decoded_as>
  <field name="key">value</field>
  <description>Illustrative base match</description>
</rule>
<rule id="100002" level="10" frequency="4" timeframe="300">
  <if_matched_sid>100001</if_matched_sid>
  <same_field>key2</same_field>
  <description>Illustrative repeated field match</description>
</rule>
```

In this example, rule 100002 fires if `key2` in the current event has the same value in four events matched to 100001 within 300 seconds. The numbers, values and descriptions are illustrative.

The matching syntax for the variant that requires a different value uses the `different_field` element:

```xml
<different_field>key2</different_field>
```

## Limiting alerts and the shared counter

`ignore` sets the time in seconds during which a rule is ignored after it fires, to limit alert floods. Allowed values are 1 to 999999. The documented example combines `if_matched_sid`, `frequency`, `timeframe` and `ignore` in one rule:

```xml
<rule id="50180" level="10" frequency="8" timeframe="120" ignore="60">
  <if_matched_sid>50125</if_matched_sid>
  <description>MySQL: Multiple errors.</description>
  <mitre>
    <id>T1499</id>
  </mitre>
  <group>service_availability,pci_dss_10.6.1,gpg13_4.3,gdpr_IV_35.7.d,hipaa_164.312.b,nist_800_53_AU.6,tsc_CC7.2,tsc_CC7.3,</group>
</rule>
```

Rule 50180 creates a level 10 alert when rule 50125 matches 8 times within 120 seconds. After that, it is ignored for 60 seconds.

The `noalert` option sets whether a rule match triggers an alert. The value `0` means an alert and is the default, and `1` means no alert. With `noalert` set to `1`, event analysis continues through further rules despite the current rule matching.

By default, the `frequency` counter includes events from the same agent. `global_frequency` extends the counted events to all agents. Despite the name, the option works at the manager level, not the cluster level.

## Example: repeated failed logins

The fragment below covers a series of failed logins recorded as JSON events. The base rule recognizes the event by a dynamic field, and the correlation rule requires the same value of the `src_ip` field in successive matches.

```xml
<group name="authentication,">
  <!-- {"event":"login_failed", "src_ip":"192.0.2.10"} -->
  <rule id="100101" level="3">
    <decoded_as>json</decoded_as>
    <field name="event">login_failed</field>
    <description>Example: failed login event</description>
    <options>no_log</options>
  </rule>

  <rule id="100102" level="10" frequency="5" timeframe="120">
    <if_matched_sid>100101</if_matched_sid>
    <same_field>src_ip</same_field>
    <description>Example: repeated failed logins from one source</description>
  </rule>
</group>
```

Rule 100102 requires five matches of rule 100101 within 120 seconds with the same `src_ip` value. Here `src_ip` is a dynamic field of the JSON event, so `same_field` compares it, like `key2` in the documentation example. When a decoder extracts the address as the static field `srcip`, use `<same_srcip />` instead of `same_field`.

In the `wazuh-logtest` documentation, the same mechanism shows up in the SSH rules: eight matches of rule 5710 within two minutes trigger rule 5712 at level 10. The built-in ruleset also contains simpler correlation rules, without grouping by field. Rules 61642 and 61643 from the Sysmon rules file count only matches of rules 61601 and 61602, with the `MS_FREQ` variable equal to 8:

```xml
<rule id="61642" level="10" frequency="$MS_FREQ" timeframe="120">
  <if_matched_sid>61601</if_matched_sid>
  <description>Multiple Sysmon warning events </description>
  <options>no_full_log</options>
</rule>

<rule id="61643" level="10" frequency="$MS_FREQ" timeframe="240">
  <if_matched_sid>61602</if_matched_sid>
  <description>Multiple Sysmon error events</description>
  <options>no_full_log</options>
</rule>
```

## Testing in wazuh-logtest

`wazuh-logtest` uses the same rules as the analysis engine and works in separate sessions. Each session loads its own set of rules and decoders. The `firedtimes` counter tracks matches within a session.

To check correlation, keep the session token returned after the first request and pass it with subsequent events. The token preserves the loaded event history, rules and decoders. Without it, a new session is created with rules and decoders loaded again. The example in the documentation sends the same event again within the session, observes `firedtimes` grow, and at the eighth match shows the correlation rule alert.

After the test you can close the session, which frees the event history and the loaded rules and decoders. The default `<rule_test>` section in `ossec.conf` sets `session_timeout` to `15m` and `max_sessions` to 64. An idle session is closed after `session_timeout`, and when `max_sessions` is reached, the session inactive for the longest time is closed. In the CLI, the `-v` switch is marked as key when diagnosing a rule or decoder problem. A detailed description of the tool is in the article [wazuh-logtest](/en/blog/wazuh-logtest/).

## Rule design checklist

- Choose one source rule or a group that `if_matched_sid` or `if_matched_group` will point to.
- Make sure the source rule used by `if_matched_sid` has a level of at least 1.
- Set the number of matches and the time window with `frequency` and `timeframe`.
- Choose whether the comparison should cover a specific field, using `same_*`, `different_*`, `same_field` or `different_field`.
- Decide whether the counter covers the events of one agent or uses `global_frequency` on the manager.
- Check whether the result should create an alert and whether `ignore` is needed after it fires.
- Test successive events in the same `wazuh-logtest` session and keep the session token.

## What the documentation does not specify

The documentation does not state whether `frequency` and `timeframe` use a sliding window or fixed intervals, nor the memory limits and cleanup of counter state. It does not describe whether correlation state survives a manager restart. It does not explain the cluster scope of `if_matched_sid` and `if_matched_group`. The rules documentation excludes level 0 from `if_matched_sid`, but rule 61642 in the Sysmon file points to 61601, which has level 0. The documentation does not explain this discrepancy.

## Sources

- https://documentation.wazuh.com/current/user-manual/ruleset/ruleset-xml-syntax/rules.html
- https://documentation.wazuh.com/current/user-manual/ruleset/testing.html
- https://documentation.wazuh.com/current/user-manual/reference/tools/wazuh-logtest.html
- https://github.com/wazuh/wazuh/blob/v4.14.10/ruleset/rules/0595-win-sysmon_rules.xml
