Custom Wazuh decoders and rules for in-house application logs
Bring in-house app logs into Wazuh: JSON log design, custom decoders, rules for failed-login bursts and privilege changes, and testing with wazuh-logtest.
By UNIXDEV Team · 20 min read
Original published · English edition
The least maintenance comes from having the application write one JSON object per line, letting the Wazuh agent read the file with log_format set to json, and relying on the json decoder that ships with Wazuh to extract the fields. All that is left is writing rules on those fields. If the application can only write plain text, you need a custom parent/child decoder that extracts fields with a regex first. Either way, test every change with wazuh-logtest before it goes live.
In Wazuh, a decoder turns a log line into fields such as a user name or source IP address, and a rule is a condition on those fields that sets a severity level and decides whether an alert is raised. This guide is for developers and administrators of in-house systems who already run Wazuh; if you are new to it, start with what Wazuh is.
Where local_decoder.xml and local_rules.xml live, the rule ID range reserved for your own rules (100000–120000) and how to change stock rules are covered in the alert-noise section of our Wazuh deployment planning guide. Technical details here follow the Wazuh 4.14 documentation (4.14.11, released 25 November 2026). Every log line, decoder and rule below is our own illustrative example, not taken from a client system.
json decoder; no custom decoder needed. (3) Plain-text logs need a parent decoder that matches the program name and a child decoder with regex and order. (4) If you plan to use same_field, keep JSON keys clear of Wazuh's static field names such as srcip and user. (5) A level-0 parent rule catches every event from the application; child rules chain on it with if_sid, and a correlation rule counts matches with frequency and if_matched_sid. (6) Test phase by phase with wazuh-logtest, and keep sample lines in the repository so you can re-test after Wazuh upgrades.Designing application logs that Wazuh can decode easily
Most decoder work disappears if the application writes JSON with stable key names from the start. The OWASP Logging Cheat Sheet recommends that you "use structured log formats, such as JSON", and that every event records when, where, who and what. The checklist below combines OWASP's guidance with documented Wazuh behaviour.
- One event per line. The localfile reference says the
jsonlog format is for "single-line JSON files", so do not pretty-print JSON across lines in the log file. - An application key. A constant key such as
"app":"myapp"lets rules separate this application's events from any other JSON source Wazuh receives. - An event-type key. One key, for example
event_type, with an agreed vocabulary:login_success,login_failed,access_denied,role_changed,bulk_export. OWASP lists authentication successes and failures, authorization failures and higher-risk functions such as adding or deleting users, privilege changes and data import or export as events to log. - Avoid key combinations stock rules use. In the 4.14.11 ruleset, Suricata rule 86600 (
0475-suricata_rules.xml) matches any event decoded by thejsondecoder that has bothtimestampandevent_typekeys, which is why the example usestime. If you choose other names, confirm in wazuh-logtest phase 3 that your own rule matches. - Who and from where. Separate keys for the user name and source IP. We suggest
usernameandsrc_ip; the JSON section explains why. - Timestamps with an offset. Use RFC 3339, for example
2026-11-28T09:15:02+07:00(Thailand is UTC+7) orZfor UTC. RFC 3339 defines the offset as "local time minus UTC", and OWASP recommends synchronising time across servers. - No arrays of objects. The JSON decoder page states: "An array of objects is not supported." Nested objects are fine, and anything after a complete JSON object is ignored.
- No secrets. OWASP excludes passwords, access tokens, session identifiers (hash them if you need them), database connection strings and encryption keys from logs. Keep personal data to what an investigation needs. For Thai organisations this matches Section 22 of the Personal Data Protection Act B.E. 2562 (2019), which in the regulator's unofficial English translation reads: "The collection of Personal Data shall be limited to the extent necessary in relation to the lawful purpose of the Data Controller." This is not legal advice.
- No injected lines. OWASP asks you to sanitise event data against log injection, such as carriage return, line feed and delimiter characters. Building the JSON with a library rather than string concatenation escapes user input as JSON requires.
The sample line used throughout (one line in the real file; wrapped here for narrow screens):
{"app":"myapp","event_type":"login_failed","username":"alice","src_ip":"203.0.113.24","time":"2026-11-28T09:15:02+07:00"}
Other event types add the keys their rules need. In the rules below, login_success carries role, and role_changed carries target_user (the account whose rights changed) and new_role, with username being the person who made the change.
The address is from a range RFC 5737 reserves for documentation, and the key names are ours. What matters more than the names is never renaming a key once rules depend on it: the rule simply stops matching, with no error.
Shipping application logs to Wazuh: agent or syslog
If you can install the Wazuh agent on the application host, let it read the log file directly with <localfile>. If you cannot, have the application or rsyslog on that host forward syslog to the Wazuh server.
Agent reading a JSON file
Adapted from the localfile reference. Add it to the agent's ossec.conf and restart the agent with systemctl restart wazuh-agent.
<localfile>
<location>/var/log/myapp/log.json</location>
<log_format>json</log_format>
<label key="@source">myapp</label>
</localfile>
<label>adds a field to JSON events. If the key already exists in the log data, the configured value is not added, which is why the documentation suggests a prefix such as@source.<only-future-events>defaults toyes; set it tonoto read entries written while wazuh-logcollector was stopped.- Plain-text logs with one entry per line use
<log_format>syslog</log_format>, described as "plain text files in syslog-like format". - With centralised configuration, the documentation says settings in
agent.conftake precedence overossec.conf.
Receiving syslog on the Wazuh server
The log data collection guide adds a <remote> block to the server's ossec.conf, limits senders with <allowed-ips>, and restarts the manager. On the application host, rsyslog forwards with @@ for TCP or @ for UDP.
<remote>
<connection>syslog</connection>
<port>514</port>
<protocol>tcp</protocol>
<allowed-ips>192.0.2.0/24</allowed-ips>
</remote>
Syslog puts a header in front of the message. If you send JSON this way, check in wazuh-logtest whether phase 2 reports the json decoder; if it does not, use a decoder for JSON that follows a text prefix, covered in the plain-text section.
This guide is about sending an application's security events to Wazuh. General application logs, such as debug or performance output, belong in a log management system like the one in our Graylog guide, which parses fields in Graylog pipelines instead.
JSON logs: the json decoder that ships with Wazuh
Logs that start with a JSON object need no custom decoder. The JSON decoder page says "Wazuh incorporates a default decoder for JSON logs", and the extracted values are stored as dynamic fields (fields named after the keys in the data) that rules can reference.
In the 4.14.11 ruleset source, 0006-json_decoders.xml defines a decoder named json with <prematch>^{\s*"</prematch> and JSON_Decoder. A log that begins with {" is therefore decoded by it, and rules can select it with <decoded_as>json</decoded_as>. A log with other text before the JSON, such as player_information: {...}, does not match that prematch.
Field names follow the JSON keys. The documentation's Suricata example shows keys inside the alert object becoming alert.action and alert.signature_id, joined with a dot, and stock rules use dotted names too, for example the Windows rule that checks win.system.channel.
Keep key names clear of static fields
Wazuh has a set of static fields: srcuser, dstuser, user, srcip, dstip, srcport, dstport, protocol, system_name, id, url, action, status, data and extra_data, per the decoders syntax reference. Any other name is a dynamic field.
This matters for correlation rules. The rules syntax reference says "The dynamic filters same_field or not_same_field will not work with the static fields", so options such as same_srcip or same_user are needed instead. In the 4.14.11 JSON decoder source, a key named like a static field, such as srcip, is stored as that static field. That comes from the source code, not the documentation.
The simplest way around it is to name keys outside that list, such as src_ip and username, and use same_field as normal.
Plain-text logs: writing a parent and child decoder
If the application cannot write JSON, for example a legacy system whose code you cannot change, keep a syslog-style header (time, host, program name) and write two decoder levels: the parent matches the program name and the child extracts fields with a regex. The decoders overview says pre-decoding extracts the timestamp, hostname and program name "when a syslog-like header is present".
The same event as a text line:
Nov 28 09:15:02 app01 myapp[2210]: login_failed user=alice src=203.0.113.24
The decoders follow the structure of the example in Custom decoders, which gives the child the same name as the parent.
<decoder name="myapp">
<program_name>^myapp</program_name>
</decoder>
<decoder name="myapp">
<parent>myapp</parent>
<regex>user=(\S+) src=(\d+.\d+.\d+.\d+)</regex>
<order>user, srcip</order>
</decoder>
- Parent and child.
<parent>links a child to its parent. A parent can have many children, but a child cannot be a parent. Events decoded by a child carry the parent's name unless the child sets<use_own_name>true</use_own_name>, sodecoded_asin rules uses the parent name,myapp. - Pre-filter.
<prematch>is a regex the log must match before the decoder applies. It can replace or accompany<program_name>, and separate children can use prematch to handle different message shapes. - regex and order. Each parenthesised group in
<regex>is one field, and the reference says "it is mandatory to define an order label as well". Names in<order>follow the groups. Hereuserandsrcipare static fields; the reference notes that user is an alias for dstuser. - Event type. This example does not extract
login_failedas a field; the rule matches the word with<match>instead.
Wazuh regex is not the regex you know
The regex reference lists three types: "regex (OS_Regex), sregex (OS_Match) and PCRE2". A decoder's <prematch> and <regex> default to OS_Regex and switch to PCRE2 with type="pcre2". Common OS_Regex surprises:
.matches a literal dot and\.matches any character, the reverse of most regex engines. In the example,\d+.\d+.\d+.\d+really means digits separated by dots.+and*only apply to backslash expressions:\d+works,0+does not.- No alternation inside a group such as
(foo|bar), and no complex backtracking. \wcovers letters, digits and-,@,_.
JSON after a text prefix
For a log with text in front of a JSON body, for example JSON arriving over syslog, call JSON_Decoder from your own decoder. The JSON decoder page gives this example:
<decoder name="raw_json">
<program_name>nba_program</program_name>
<prematch>player_information: "</prematch>
<plugin_decoder offset="after_prematch">JSON_Decoder</plugin_decoder>
</decoder>
offset="after_prematch" starts JSON parsing after the part matched by prematch. The same page also shows one child that parses JSON and a second child with the same name that extracts an extra field with a regex. When you adapt either example to your application, test it in wazuh-logtest first.
A decoder that calls JSON_Decoder itself can also control how null values and arrays are stored, with json_null_field and json_array_structure, as described in the decoders syntax reference.
JSON or a custom decoder: which to choose
If you can change the application, switching to single-line JSON is almost always the better choice: no regex to maintain, and new fields need no decoder change. A custom decoder suits logs whose format you cannot change.
| Situation | Approach | What to watch |
|---|---|---|
| The application can write single-line JSON | Agent with log_format json and the stock json decoder | No arrays of objects; key names clear of static fields if you use same_field |
| A text log whose format cannot change | Parent decoder (program_name or prematch) and child (regex + order) | OS_Regex rules, or type="pcre2" |
| Text prefix followed by JSON | plugin_decoder set to JSON_Decoder with offset="after_prematch" | The stock json decoder will not match, because the log does not start with { |
| A field JSON does not provide directly | A second same-named child with a regex, as in the JSON decoder page's example | Check you get both the JSON fields and the extra field |
Writing rules on application fields
Layer the rules. A level-0 parent rule catches every event from the application without raising an alert, and child rules chain on it with <if_sid>, each checking one event type. The stock Suricata rules follow the same pattern: a level-0 parent with decoded_as json and children that check event_type.
Rules for the application's JSON log; IDs and levels are ours.
<group name="myapp,">
<rule id="100700" level="0">
<decoded_as>json</decoded_as>
<field name="app">^myapp$</field>
<description>myapp: event</description>
</rule>
<rule id="100701" level="5">
<if_sid>100700</if_sid>
<field name="event_type">^login_failed$</field>
<description>myapp: login failed for $(username)</description>
<mitre><id>T1110</id></mitre>
</rule>
<rule id="100703" level="3">
<if_sid>100700</if_sid>
<field name="event_type">^login_success$</field>
<field name="role">^admin$</field>
<description>myapp: admin login by $(username)</description>
<mitre><id>T1078</id></mitre>
</rule>
<rule id="100704" level="10">
<if_sid>100700</if_sid>
<field name="event_type">^role_changed$</field>
<field name="new_role">^admin$</field>
<description>myapp: $(target_user) granted admin</description>
<mitre><id>T1098</id></mitre>
</rule>
<rule id="100705" level="8">
<if_sid>100700</if_sid>
<field name="event_type">^bulk_export$</field>
<description>myapp: bulk export by $(username)</description>
<mitre><id>T1213</id></mitre>
</rule>
</group>
field: the name is "the name of the field extracted by the decoder", and the value is an OS_Regex by default; anchor it with^and$for an exact match. With several<field>conditions, "Wazuh evaluates them as logical AND conditions".matchandregexcheck the whole log line rather than a field.matchdefaults to OS_Match andregexto OS_Regex; both can switch to PCRE2.description: "Always use this field when creating custom rules." Field values can be substituted with$(field name).group: every rule must belong to at least one group; an application group makes alerts easy to search and filter later.mitreholds MITRE ATT&CK technique IDs in<id>elements. The examples use T1110 Brute Force, T1078 Valid Accounts, T1098 Account Manipulation and T1213 Data from Information Repositories.
Let the application decide which export counts as bulk_export and write it as an event type. OS_Regex cannot compare numbers as greater or less than, and a threshold in application code is easier to test and review.
Choosing levels
Levels run from 0 to 16. What each band means, and which settings decide what is logged or emailed, is covered in our deployment planning guide. The reasoning in our example: the parent rule is level 0 so that not every event becomes an alert; a single failed login and an admin login get a low level so they can be searched later; granting admin rights and repeated failed logins get a high level because someone should look. Tune the numbers to the alert volume you actually see after go-live.
Catching repeated failed logins with frequency and same_field
A correlation rule uses the frequency and timeframe attributes together with <if_matched_sid>, which names the rule to count. The rules syntax reference gives rule 50180 as an example, which "triggers a level 10 alert if rule 50125 matches 8 times within 120 seconds".
For the JSON log, src_ip is a dynamic field, so <same_field> counts only events from the same address.
<rule id="100702" level="10" frequency="5" timeframe="120">
<if_matched_sid>100701</if_matched_sid>
<same_field>src_ip</same_field>
<description>myapp: repeated login failures from $(src_ip)</description>
<mitre><id>T1110</id></mitre>
</rule>
Put it inside the same <group name="myapp,"> as before. Five failures in 120 seconds is an example value; set it from how your users actually behave. To count per account rather than per address, use <same_field>username</same_field>.
Two cautions from the documentation:
- "Rules at level 0 are discarded immediately and will not be used with if_matched_sid." The counted rule (100701) must be level 1 or higher; if you do not want each match logged as an alert, the documentation suggests adding the
no_logoption. same_fielddoes not work with static fields. If the JSON uses a key namedsrcip, or a decoder's<order>produces srcip, use<same_srcip />or<same_user />instead.
Rules for the plain-text log
The myapp text decoder produces the static fields user and srcip, so the correlation rule uses <same_srcip />.
<group name="myapp,">
<rule id="100707" level="0">
<decoded_as>myapp</decoded_as>
<description>myapp (text): event</description>
</rule>
<rule id="100708" level="5">
<if_sid>100707</if_sid>
<match>login_failed</match>
<description>myapp (text): login failed</description>
<mitre><id>T1110</id></mitre>
</rule>
<rule id="100709" level="10" frequency="5" timeframe="120">
<if_matched_sid>100708</if_matched_sid>
<same_srcip />
<description>myapp (text): repeated login failures from $(srcip)</description>
<mitre><id>T1110</id></mitre>
</rule>
</group>
Choosing thresholds for frequency rules, and the ignore attribute, which the rules syntax reference defines as the time in seconds to ignore a rule after it triggers to avoid floods, are covered with examples in our Wazuh ransomware detection guide, and rules that check a field against an indicator list with <list> are in our Wazuh threat intelligence guide.
Testing decoders and rules phase by phase with wazuh-logtest
wazuh-logtest lives at /var/ossec/bin/wazuh-logtest on the Wazuh server and tests rules and decoders against sample lines in a wazuh-analysisd sandbox. The Custom decoders page says you can test as soon as the decoder and rule files are saved, but the manager must be restarted before the change produces real alerts.
Run it and paste one line at a time. The output has three phases, per Testing decoders and rules:
- Phase 1: Completed pre-decoding shows the full line and the timestamp, hostname and program_name taken from a syslog-style header. For the
myapptext line, check that program_name ismyapp; if not, a parent decoder keyed onprogram_namewill not match. A JSON line from a file has no such header, so go straight to phase 2. - Phase 2: Completed decoding shows the decoder name and the extracted fields. The JSON line should report
jsonwithapp,event_type,usernameandsrc_ip; the text line should reportmyapp. The Custom decoders example shows the user value underdstuser, because user is an alias for dstuser. - Phase 3: Completed filtering (rules) shows the rule ID, level, description, groups and firedtimes, followed by Alert to be generated. when an alert would be raised. The failed-login line should give rule 100701 at level 5.
Reading the output when it is not what you expect
| Symptom | Where to look |
|---|---|
| Phase 2 lacks the expected decoder | JSON: does the log really start with {", or is there text in front? Text: program_name in phase 1 and the program_name or prematch value |
| Phase 2 shows a different decoder | A decoder in the ruleset matched this log first. Note its name and make your program name or prematch more specific |
| Right decoder, but fields missing or wrong | The regex and the order in order, especially the OS_Regex rules for ., \. and + |
| Phase 3 shows another rule or no alert | Field names in <field name> must match phase 2 exactly, as must the decoded_as name and the if_sid IDs |
If you are still stuck, run with -v, which the documentation calls "the key option to troubleshoot a rule or decoder problem".
Testing a frequency rule in one session
The testing page says wazuh-logtest "operates based on unique sessions, each loading its own set of rules and decoders", with a firedtimes counter that accumulates within the session. Its example repeats an sshd line until rule 5710 escalates to rule 5712 (brute force).
Do the same for rule 100702: paste the login_failed line from one address repeatedly in the same session and note when phase 3 changes from 100701 to 100702. Record the count you observe as the expected result, then paste a line with a different address to confirm same_field keeps it out of the count.
Testing from the dashboard or the API
The testing page says the same test is available from the Ruleset test tool in the Wazuh dashboard and through the Wazuh server API with PUT /logtest, where you send the session token with later requests to keep the event history, and close the session with DELETE /logtest/sessions/{token}.
Re-testing after rule changes and Wazuh upgrades
Keep a sample line for every event type in the application's repository, together with the expected result, and re-run them whenever a decoder or rule changes and whenever Wazuh is upgraded.
The reason: the Custom rules page says modifications to any rule file in /var/ossec/ruleset/rules are overwritten during upgrades. Stock decoders and rules can change with any release and may start catching your application's logs first.
- One case per line, paired with the expected result as
rule-id:level:decoder, for example100701:5:jsonand100708:5:myapp. - The
-Uoption makes wazuh-logtest "return a zero exit status if the test results for the provided log line match the criteria", for a single line. A non-zero exit means the result changed. The documentation does not show how to feed the line to-U, so try it on a test server before scripting it. - Cases that need several lines, such as frequency rules, belong in an interactive session or an API session that reuses its token.
- Test on a staging server running the new release before upgrading production. If you copied a stock decoder file and excluded the original with
decoder_exclude, the Custom decoders page warns that the copy no longer receives upstream fixes, so compare it by hand at every upgrade.
When developers add an event type or rename a key, add the sample line in the same commit as the code change, so whoever maintains Wazuh sees which rule needs updating before it breaks.
Status as of 2026-11-28
These facts change with releases; check the source pages before relying on them.
| Item | Status per the source page | Source |
|---|---|---|
| Wazuh | 4.14.11 released 25 November 2026 (4.14.10 on 5 November 2026); this guide cites the 4.14 documentation | Wazuh release notes |
| Regex types | OS_Regex (default for prematch, regex and field), OS_Match (default for match and program_name) and PCRE2 via type="pcre2" | Regular expression syntax (4.14) |
| JSON decoder | numbers, strings, booleans, null, arrays and objects; arrays of objects not supported | JSON decoder (4.14) |
| logtest defaults | <rule_test> in ossec.conf: enabled yes, threads 1, max_sessions 64, session_timeout 15m | Testing decoders and rules (4.14) |
| Where to test | CLI, Wazuh dashboard (Tools > Ruleset test) and API PUT /logtest | Testing decoders and rules (4.14) |
| Wazuh 5.0 | documentation is a release-candidate set marked "still under development"; it says custom 4.x rules and decoders in XML format cannot be migrated to 5.x | Wazuh 5.0-rc — Transition plan |
This guide applies to Wazuh 4.x. The 5.0-rc migration pages say custom rules and decoders are managed through a content management system in 5.x rather than by copying files, so treat your sample lines and expected results as the specification for rebuilding detections there.
How UNIXDEV can help
UNIXDEV installs Wazuh, deploys agents and syslog intake, tunes rules to reduce false positives and maintains the system within the agreed maintenance (MA) scope. Our rule tuning covers writing decoders and rules for your application's logs and testing them with wazuh-logtest before they go live.
On the application side, changing code to write logs in an agreed format falls under our custom software development and legacy application maintenance work. Baseline operations sit in our DevOps & SRE Managed Services.
Sources and further reading
- Wazuh 4.14 — Custom decoders · JSON decoder · Decoders · Decoders syntax
- Wazuh 4.14 — Custom rules · Rules syntax · Regular expression syntax
- Wazuh 4.14 — wazuh-logtest · Testing decoders and rules
- Wazuh 4.14 — localfile · Monitoring log files · Log data collection configuration
- Wazuh v4.14.11 — 0006-json_decoders.xml · json_decoder.c · 0475-suricata_rules.xml · 0575-win-base_rules.xml
- Wazuh release notes · Wazuh 5.0-rc — Transition plan · Migrating the Wazuh manager
- OWASP Logging Cheat Sheet · RFC 3339 — Date and Time on the Internet: Timestamps · RFC 5737
- Personal Data Protection Act B.E. 2562 (2019), PDPC unofficial translation
- MITRE ATT&CK — T1110 · T1078 · T1098 · T1213
- Related: what Wazuh is
- Related: planning a Wazuh deployment
- Related: Wazuh threat intelligence, matching MISP IoCs with CDB lists
- Related: detecting ransomware with Wazuh, what to configure
- Related: what Graylog is and how to plan central log management
- All articles on Wazuh and security monitoring
Sources checked on 2026-11-28
How we checked: based on the primary sources above, reviewed by the UNIXDEV team