# A custom decoder in Wazuh 5: YAML, KVDB, testing and promotion in Content Manager

> A decoder for your own application in Wazuh 5: YAML instead of XML, KVDB instead of CDB lists, Content Manager API, log test and draft, test, custom promotion.

Published: 2026-12-03. Updated: 2026-12-04. Category: Configuration. Tags: Wazuh 5. URL: https://wazuh.blog/en/blog/wazuh-5-decoders-kvdb/ Polish original: https://wazuh.blog/blog/wazuh-5-dekodery-kvdb/

Your Wazuh 4 custom decoders won't carry over to Wazuh 5 as files. The XML file on the manager becomes a YAML resource inside an integration, and that resource reaches live events through three Content Manager spaces: you create it in draft, run the log test in test, and it starts processing events only after promotion to custom. I'll walk that path with one `key=value` log line from a made-up application, `example-app`, starting with the 4.x decoder that used to handle it.

Wazuh 5.0 is still a release candidate, so details may change before GA. I ran the API calls, both decoders, the KVDB and the log test on the 5.0.0-rc2 Docker image, in the draft and test spaces. Everything else, promotion to custom included, comes from the 5.0-rc documentation and the indexer plugin code at tag `v5.0.0-rc2`.

## The 4.x decoder and its 5.x equivalent

The migration guide is explicit: copying files into the manager installation won't bring back custom rules, decoders or CDB lists. CDB lists become KVDB databases, and a decoder can write only Wazuh Common Schema (WCS) fields and temporary fields, so the field names change as well. The schema itself is covered in [Wazuh Common Schema and the wazuh-events-v5 indices](/en/blog/wazuh-5-wcs-indices/).

The sample line is `example-app: login result=failed user=alice src=192.0.2.15`, with an address from the 192.0.2.0/24 documentation range. In 4.x a pair of decoders handled it: the parent recognizes the program, the child extracts three fields with a regular expression (the syntax of `prematch`, `regex` and `order` is covered in the [post on 4.x decoders](/en/blog/wazuh-custom-decoders/)):

```xml
<decoder name="example-app">
  <program_name>^example-app</program_name>
</decoder>

<decoder name="example-app-login">
  <parent>example-app</parent>
  <prematch>^login </prematch>
  <regex>^login result=(\w+) user=(\S+) src=(\S+)</regex>
  <order>status, dstuser, srcip</order>
</decoder>
```

| 4.x element | 5.x equivalent |
|---|---|
| `program_name`, `prematch` | `check` on a field, most often `event.original`, with `starts_with` or `contains` filters |
| `regex` with groups and `order` | a `parse` expression with fields in angle brackets, or `parse_key_value` for `k=v` |
| `parent` | a `parents` list with the name of the parent decoder |
| static fields `srcip`, `dstuser`, `status` | WCS fields: `source.ip`, `user.name`, `event.outcome` |
| CDB list checked in a rule | KVDB called in the decoder with the `kvdb_get` helper or in `check` with the `kvdb_match` helper |

## Why the root decoder stays generic

Decoders in 5.x form a tree. An event enters the space through the root decoder and works its way down. A decoder whose conditions fail hands the event to its next sibling; the one that accepts it applies its transformations and passes the event on to its own children.

Each space has its own policy and its own root decoder, and the orchestrator sends an independent copy of every event to every active policy. That is why the documentation example indexes the same Apache log line twice: once through the custom integration and once through the standard `apache-http`. The custom space's root decoder is also unrelated to the decoder of the same name in the standard space—it is a separate copy. Keep the root generic and pick out your source's events in the child decoder's `check`.

## Decoder format

A decoder is a YAML resource, and the engine runs its stages in order. The key question for each stage is whether it can reject the event or, at worst, leave a field empty:

- `check`: conditions that decide whether the decoder applies to the event. It is a list of `field: helper(...)` entries or a single text expression, for example `"$dns.response_code == NOERROR"`. If a top-level condition fails, the decoder rejects the event.
- `parse|<field>`: a list of patterns that the engine tries in order against the field value. The first one that matches the whole value wins. If none matches, the stage fails and the decoder rejects the event; inside a `normalize` block, the engine skips only the rest of that block.
- `normalize`: blocks with their own `check`, `parse|` and `map`, executed in order. `map` operations set fields to a literal, a `$field` reference or a helper result. A failed operation leaves the field unchanged and never causes the event to be rejected.
- `parents` links the decoder to its parent, `enabled` turns it on, and `metadata` holds descriptions that do not affect behavior. A resource can also have a `definitions` section with named values.

A decoder can write only WCS fields and temporary fields, meaning fields whose first segment starts with `_`. Temporary fields carry values between decoders and are removed in the pre-enrichment step, so only WCS-compliant fields reach the index. Any other name makes the decoder fail to load: the API rejects such a resource with code 400 and the message `Field 'example_custom_field' is not defined in WCS schema and is not a temporary field (root must start with '_')`.

The functions in `check` and `map` values are helpers, and they come in three kinds: filters go in `check`, mapping and transformation helpers go in `map`. A helper in the wrong stage stops the resource from building. An argument can be a literal in single quotes, a reference starting with `$`, a JSON value or raw text. All 128 helpers are described in the [helper reference](https://documentation.wazuh.com/5.0-rc/user-manual/reference/helper-functions.html).

## A decoder for example-app

The root decoder comes first. The documentation shows a root that tries to parse `event.original` as JSON into a temporary field, and that pattern does not get in the way of text logs. On plain text `parse_json` fails, but it is an operation in `normalize`, so the event moves on, and in the log test trace the root reports success.

```yaml
name: "decoder/example-root/0"
enabled: true
metadata:
  title: "example root decoder"
  description: "Root decoder of the custom space, parses the raw event as JSON into a temporary field"
  author: "Security Team"
normalize:
  - map:
      - _tmp_json: "parse_json($event.original)"
```

The application decoder has the same shape as the `custom-fw-kv` example in the documentation. `check` lets in only `example-app` login events, `parse|event.original` moves the `k=v` part into a temporary field, `parse_key_value` splits it into pairs, and the last two `normalize` blocks set the result depending on `result`. Events also carry a `wazuh.protocol.location` field, but no decoder in the documentation checks it, so I base the condition on `event.original`.

```yaml
name: "decoder/example-app/0"
enabled: true
metadata:
  title: "example-app login events"
  description: "Key=value login events of example-app"
  author: "Security Team"
parents:
  - "decoder/example-root/0"
check:
  - event.original: 'starts_with("example-app: login ")'
parse|event.original:
  - "example-app: login <_kv_text>"
normalize:
  - map:
      - _kv: parse_key_value($_kv_text, '=', ' ', "'", '\\')
      - event.kind: "event"
      - event.category: "array_append(authentication)"
      - event.dataset: "example-app"
      - user.name: $_kv.user
      - source.ip: $_kv.src
      - threat.feed.description: kvdb_get('example_blocklist', $source.ip)
  - check:
      - _kv.result: string_equal("ok")
    map:
      - event.outcome: "success"
  - check:
      - _kv.result: string_equal("failed")
    map:
      - event.outcome: "failure"
```

Two things in this example depend on the source, so do not copy them without checking: choose the `event.category` values for your application's events, and check whether `event.original` starts with a syslog header.

`parse` patterns support five constructs: `<field>` (capture into a WCS field, the parser picks the field type), `<_name>` (a temporary field, text by default), `<?field>` (an optional field), `(?...)` (an optional group) and `<~>` (text to discard). Escape the characters `<`, `?`, `(`, `)` and `\` in literal text with a backslash. If a pattern is a YAML string split across lines with `\`, edit it in the YAML editor; the visual editor rejects it.

## KVDB instead of a CDB list

A KVDB is a named dictionary: the key is text and the value is any JSON. The KVDB title is its name in helpers and cannot contain spaces or the characters `\ / : * ? " < > |`. Helpers work in the `map` and `check` stages:

| Helper | Stage | Behavior |
|---|---|---|
| `kvdb_get(db_name, key)` | map | copies the value of the key into the target field |
| `kvdb_get_array(db_name, array_key)` | map | looks up each key from the array and appends the values to the target array |
| `kvdb_get_merge(db_name, key)` | map | merges the value of the key into the target field, objects one level deep |
| `kvdb_get_merge_recursive(db_name, key)` | map | merges recursively |
| `kvdb_decode_bitmask(db_name, table_name, mask)` | map | decodes a hexadecimal mask using a bit table from the KVDB |
| `kvdb_match(db_name)` | check | passes when the field value is a key in the KVDB |
| `kvdb_not_match(db_name)` | check | passes when the value is not among the keys |

In the `example-app` decoder, `kvdb_get('example_blocklist', $source.ip)` writes the address description into `threat.feed.description` when the address is a key in the database. For other addresses the call fails and the field is absent from the result. How CDB lists did the same job in 4.x is covered in [CDB lists in Wazuh](/en/blog/wazuh-cdb-lists/).

This is where the documentation and rc2 part ways. The documentation examples nest the pairs under the database name; the API accepts that without an error, but in the log test `kvdb_get` then returns `Key not found in DB`, because the database name becomes the key. Write the KVDB content as a flat key-value object, as in the API example below.

`kvdb_match` in `check` has a different catch: the helper works on a field that already exists. In the `example-app` decoder the condition `source.ip: kvdb_match(...)` fails with `Target field 'source.ip' not found`, because `check` runs before the `parse` and `normalize` of the same decoder. Match addresses from the database in a child decoder, which receives the event with `source.ip` already set:

```yaml
name: "decoder/example-app-blocklisted/0"
enabled: true
metadata:
  title: "example-app events from blocklisted addresses"
  author: "Security Team"
parents:
  - "decoder/example-app/0"
check:
  - source.ip: kvdb_match('example_blocklist')
normalize:
  - map:
      - event.type: "array_append(indicator)"
```

## Integration and categories

Each decoder belongs to exactly one integration, which groups the decoders, KVDBs and rules of one source. Two of its fields reach well beyond the integration. The category decides where events go: it is written to `wazuh.integration.category` and determines the `wazuh-events-v5-<category>` stream. The API accepts `access-management`, `applications`, `cloud-services`, `network-activity`, `other`, `security`, `system-activity` and `unclassified`, case-sensitive, so `Applications` ends with code 400 and the message `Integration category is not valid`. The title is the integration's name in the engine and must be unique in the draft space. Choose it with care: rules attach to the integration by that title, in the `logsource.product` field; how to write them is shown in the [post on Sigma rules in Wazuh 5](/en/blog/wazuh-5-sigma-rules/).

Standard integrations can be disabled, and a disabled integration neither decodes events nor applies its rules. Before you start collecting logs, enable it in the standard space: Ruleset Management, Actions > Enable. The documentation only shows this as a dashboard action, with no API call. An example is in the post on [Suricata from OPNsense in Wazuh 5](/en/blog/wazuh-5-suricata-opnsense/).

## From draft to test through the API

You create and change everything in the draft space. Test and custom are read-only, and they change through promotion, which copies the content one step further and removes from the target whatever is no longer in the source. The Content Manager API calls on the indexer below create the integration, both decoders and the KVDB in the draft space. Keep the password in `WAZUH_INDEXER_ADMIN_PASSWORD` out of your shell history. The `-k` flag in these `curl` calls turns off certificate verification; it is there only because the Docker lab uses self-signed certificates. Outside the lab, point `--cacert` at the indexer CA and drop `-k`.

```bash
BASE="https://127.0.0.1:9200/_plugins/_content_manager"
AUTH="admin:${WAZUH_INDEXER_ADMIN_PASSWORD}"

# 1. Integration in the draft space; the response message is its UUID
INTEGRATION_ID=$(curl -sk -u "$AUTH" -X POST "$BASE/integrations" \
  -H 'Content-Type: application/json' \
  -d '{"resource":{"metadata":{"title":"example-app","author":"Security Team"},
       "category":"applications","enabled":true}}' | jq -r .message)

# 2. Decoders: wrap the YAML asset in the integration/resource envelope
for f in root.yml example-app.yml; do
  { echo "integration: ${INTEGRATION_ID}"; echo "resource:"; sed 's/^/  /' "$f"; } |
    curl -sk -u "$AUTH" -X POST "$BASE/decoders" \
      -H 'Content-Type: application/yaml' --data-binary @-
done

# 3. KVDB with one entry; content is a flat key/value object
curl -sk -u "$AUTH" -X POST "$BASE/kvdbs" -H 'Content-Type: application/json' \
  -d "{\"integration\":\"${INTEGRATION_ID}\",
       \"resource\":{\"metadata\":{\"title\":\"example_blocklist\",\"author\":\"Security Team\"},
       \"enabled\":true,
       \"content\":{\"192.0.2.15\":\"known scanner\"}}}"
```

Each call returns `{"message":"<uuid>","status":201}`, decoders included; on rc2 a decoder UUID has no prefix at all. Save it, because the policy refers to the root decoder by that UUID. The integration goes straight onto the `integrations` list of the draft policy, and a decoder can point to a KVDB that does not exist yet. The draft space limits, on the other hand, are hard caps: according to the documentation, the call returns 400 when you exceed 100 integrations, 200 decoders or 100 KVDBs (the `max_integrations`, `max_decoders` and `max_kvdbs` settings in `opensearch.yml`).

You set the root decoder in the draft policy: in the dashboard through Ruleset Management > Overview > Actions > Edit, in the API with the `root_decoder` field in `PUT /policy/draft`. The API enforces several rules on that call:

- The value must be the decoder UUID, although the documentation examples show names with a `d_` prefix. On rc2 the API accepts the name `decoder/example-root/0` without an error, but the next promotion ends with code 400 `Resource with UUID ... does not exist` and leaves the test space unchanged.
- A request to the draft requires the fields `author`, `description`, `documentation` and `references` in `resource.metadata`, and the values `enabled`, `index_unclassified_events` and `index_discarded_events`.
- The `integrations` and `filters` lists in the policy can only be reordered; an attempt to add or remove an element ends with code 400. An integration is removed through its own endpoint, which also takes it off the list in the policy.
- You cannot remove the root decoder while it is set: the API answers 400 `Cannot remove decoder [...] as it is set as root decoder.`

Updating an integration (`PUT /integrations/{id}`) is just as strict: it requires all the fields, including `rules`, `decoders` and `kvdbs`, and you pass empty lists as `[]`. Without the `decoders` list the API answers 400 `Content of 'decoders' cannot be added or removed via update`. Even when you change only the title, rewrite the full lists of the current elements.

### Promotion and the log test

Promotion is a two-step operation. The preview is a dry run, and its result goes into the executing request as `changes`. A failed promotion changes nothing in the target space. A preview called right after a resource is deleted can still show the state from before the change, so in that case wait a moment and call it again before executing the promotion:

```bash
# Preview the draft -> test promotion, then execute it with the same changes
curl -sk -u "$AUTH" "$BASE/promote?space=draft" |
  jq '{space: "draft", changes: .changes}' |
  curl -sk -u "$AUTH" -X POST "$BASE/promote" \
    -H 'Content-Type: application/json' -d @-

# Normalization-only log test in the test space
curl -sk -u "$AUTH" -X POST "$BASE/logtest/normalization" \
  -H 'Content-Type: application/json' \
  -d '{"space":"test","queue":1,"location":"/var/log/example-app/app.log",
       "event":"example-app: login result=failed user=alice src=192.0.2.15",
       "trace_level":"NONE"}'
```

On rc2 the log test response has two parts that matter: the normalized event in `message.output` and the validation result in `message.validation`. With `trace_level` set to `NONE` the `asset_traces` list is empty, but the chain of decoders the event passed through is visible in `wazuh.integration.decoders`. When a decoder does not catch the event and you want to see why, set `ALL`: the trace shows every resource that was checked, including decoders that did not accept the event. A shortened result for the sample line:

```json
{
  "message": {
    "output": {
      "event": {
        "category": ["authentication"],
        "dataset": "example-app",
        "kind": "event",
        "outcome": "failure"
      },
      "source": { "ip": "192.0.2.15" },
      "user": { "name": "alice" },
      "threat": { "feed": { "description": "known scanner" } },
      "wazuh": {
        "integration": {
          "category": "applications",
          "decoders": ["decoder/example-root/0", "decoder/example-app/0"],
          "name": "example-app"
        },
        "space": { "name": "test" }
      }
    },
    "validation": { "valid": true }
  },
  "status": 200
}
```

For `result=ok`, `event.outcome` would be `success`. A 200 doesn't mean the test passed: the response carries it even on an engine error, so check the `status` fields inside the response. The test works only when the test policy is loaded in the engine. You can do the same in the dashboard under Ruleset Management > Log test: switch the space to Test (Standard opens by default) and choose the integration.

When the result is right, repeat the preview and the promotion with `space=test` and `"space":"test"`. The preview itself marks resources that already exist in the target with the `update` operation; a hand-written `add` for such a resource ends with code 409 asking you to use `UPDATE`. I did not run this promotion on the lab, so this part relies on the documentation: the manager loads the custom space periodically, and for about 2 minutes after a promotion only the standard policy processes events. The documentation gives neither the exact load time nor what happens after that window. Don't treat the first events after a promotion as a test of the new decoder.

## Before you write a rule, and before you promote

Write rules only once the raw log passes `logtest/normalization` in the test space with the right result; a rule built on a badly normalized event will look for fields that are not there. Before each promotion, read the change preview and look for resources you did not touch. A promotion removes from the target everything that is no longer in the source, so it can carry more than your own changes.

## Sources

- https://documentation.wazuh.com/5.0-rc/user-manual/manager/wazuh-normalization-engine.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/detection-workflow.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/key-concepts.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/decoders.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/helper-functions.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/key-value-databases.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/integration.html
- https://documentation.wazuh.com/5.0-rc/user-manual/data-analysis/space.html
- https://documentation.wazuh.com/5.0-rc/user-manual/reference/helper-functions.html
- https://documentation.wazuh.com/5.0-rc/user-manual/wazuh-indexer/modules/content-manager.html
- https://documentation.wazuh.com/5.0-rc/migration-to-5x/wazuh-manager.html
- https://documentation.wazuh.com/4.14/user-manual/ruleset/ruleset-xml-syntax/decoders.html
- https://raw.githubusercontent.com/wazuh/wazuh-indexer-plugins/v5.0.0-rc2/docs/ref/modules/content-manager/api.md
- https://raw.githubusercontent.com/wazuh/wazuh-indexer-plugins/v5.0.0-rc2/docs/ref/modules/content-manager/troubleshooting.md
- https://raw.githubusercontent.com/wazuh/wazuh-indexer-plugins/v5.0.0-rc2/plugins/content-manager/openapi.yml
