Why teams test Wazuh rules in CI with the logtest API
A security engineering team adds a custom rule by editing a file directly on the live Wazuh server, restarts the service, and checks that the alert appears. Weeks later a teammate changes a decoder for a different log source, an upgrade lands, and the original rule stops matching. Nobody notices until an incident goes unalerted. Detection content that is changed by hand and never replayed against known logs fails silently, and the failure often shows up only when someone needs the alert. Treating rules and decoders as code, with sample logs in a repository and an automated check on every change, turns that silent failure into a failed build.
The logtest API gives a pipeline a way to do that check. A job sends each sample log to the Wazuh server and reads back which decoder matched and which rule fired, so the build can assert that a known-bad sample still produces the expected rule ID and level. The check runs against the same decoding and rule logic the server uses, which is why it is more reliable than comparing file text. The exact request format, session behavior and output fields should be confirmed against the Wazuh documentation for your release line before you write the job, since those details change between versions.
This approach fits best when several people write rules, when changes must pass a documented review under regulated change control, or when rule edits are frequent enough that manual checks cannot keep up. A small team making one change a quarter may get by with the dashboard ruleset test. Before committing to the pipeline, confirm with your own platform owner who can reach the Wazuh server from CI, how the test server is provisioned and which Wazuh version the test environment must match to keep results meaningful.
Setting up a logtest test pipeline step by step
This sequence turns Wazuh detection content into a tested repository, where every sample log must produce the expected rule and level before a change reaches the manager. The result is a pipeline job that fails loudly when a decoder or rule drifts.
Lay out the detection content repository
The detection engineer creates a repository with separate folders for decoders, rules and samples, and keeps one sample log file per rule, named after the rule ID it should trigger. A small expectations file records the rule ID and level each sample should produce, so the test script reads its expectations from version control rather than from memory. Done means the repository holds every custom decoder and rule file, the samples and the expectations file, and a reviewer can trace each rule to at least one sample. Confirm the rule ID ranges you use against your own local rules before you start.
Create a dedicated least-privilege API account
The platform engineer creates a separate account on the Wazuh API for the pipeline, assigns it only the permissions needed to authenticate and call the logtest endpoint, and stores its credentials in the CI system's secret store rather than in the repository. Check the Wazuh API user and role documentation for your release to confirm the exact permission names, because they change between versions. Done means the account can run a logtest request and is refused for administrative calls such as changing configuration.
Write the logtest submission script
The engineer writes a script that authenticates to the Wazuh API, opens a logtest session, and posts each sample log in order. The script keeps the session identifier for the whole run so that frequency and timeframe rules can see earlier events, and it closes the session at the end. Run it locally against a non-production manager first and confirm that a known sample returns a decoder, a rule ID and a level in the response. Done means the script prints one result line per sample.
Compare results with expected values
The script reads the expectations file and compares each returned rule ID and level with the expected values, recording any sample that matches no rule, matches a different rule or returns a different level. The script exits with a non-zero status when any comparison fails and prints a table that names the sample, the expected rule and the actual rule. Done means a clean run exits with status zero and a deliberately wrong expectation produces a readable failure message.
Wire the test job into the pipeline
The platform engineer adds a job to the pipeline that runs on every merge request touching decoders, rules or samples, installs the script dependencies, injects the API credentials from the secret store and runs the comparison. The job should use the same Wazuh release as the production manager so that decoder behavior matches. Confirm the job runs on your runner type and that the secret is masked in the logs. Done means a change to a rule file triggers the job automatically.
Make the pipeline fail on mismatch
The engineer confirms that a failed comparison fails the job and blocks the merge, and that the job cannot be bypassed by the change author. The test is verified by changing a rule ID on purpose in a branch, pushing it and checking that the job fails at the comparison step and names the affected sample. Repeat the check with a level change and with a sample that matches no rule. Done means all three intentional breaks fail the pipeline and the original branch passes again after the revert.
Keep expectations current with each change
The detection team treats the expectations file as part of every rule change, so a new rule ships with its sample and expected values in the same merge request. Review the job after each Wazuh upgrade, because decoder and rule behavior can change between releases and the sample set should be rerun against the new version before production. Done means the pipeline passes on the new release in a staging manager and any differences are either fixed or recorded in the expectations file with a reason.
Choosing how to run logtest checks in the pipeline
This table compares three places a pipeline can run logtest checks: a disposable test server, a staging server that mirrors production rules, and the dashboard ruleset test used by hand. Read each row against your change process, since the right option depends on how often rules change and how closely a test must match production. The main takeaway is that fidelity to production costs a running server, so most teams combine a fast pipeline check with a periodic check against a closer copy.
| Option | What it tests well | Main trade-off | When it fits |
|---|---|---|---|
| Disposable test server | Decoders and rules from the repository, loaded fresh on each run | Must be rebuilt with the same Wazuh version and custom content as production | Teams that change rules often and want every merge request checked |
| Staging server mirroring production | Rules, CDB lists and configuration as they run in production | Keeping a second server running and synchronized costs ongoing effort | Regulated teams whose change process needs evidence from a close copy |
| Dashboard ruleset test | Single log samples checked by a person during authoring | Manual, not repeatable, and leaves no record in the pipeline | Small rule sets or quick checks while writing a new decoder |
| Version pinning across environments | Whether the test and production Wazuh versions decode the same way | Upgrades must be applied to test first, which adds a step to change planning | Any team that upgrades Wazuh in stages |
| Production configuration drift | Mismatches between test and production CDB lists or decoder order | Drift can hide failures that only appear in the live setup | Teams that cannot yet promote content from one environment to the next |
Session handling and expected-match patterns in pipelines
Single-event rules are the simplest case because each log line is evaluated on its own. A test sends one sample line, reads the decoded fields and the matched rule ID, and asserts that the expected rule fired. Because no state carries between lines, the main risk is a shared session that still holds leftover context from an earlier test, so each test should open its own session or start from a clean one before sending its line.
- Isolate per test: Open a fresh logtest session for each sample or test case so a previous line cannot influence the result.
- Assert the rule ID: Check the exact rule ID and level in the output, not only that some alert appeared.
- Assert absence: For each sample, also confirm that unrelated rules did not fire, which catches overly broad regular expressions.
- Keep one sample per expectation: Map each sample file to a single expected outcome so failures point to one rule.
- Store samples with the rule: Keep the sample log, expected rule ID and expected level in the same repository path as the rule file.
Before relying on these tests, confirm the logtest request and response format for your Wazuh release in the documentation for that version.
Multi-line and stateful decoding is where session handling matters most. Some decoders depend on context from earlier lines, and a session that already processed a previous sample can change how the next one decodes. Tests for these cases should replay the lines in their original order inside one dedicated session, and every test case should start from a known state so results do not depend on what ran before.
- Use one session per sequence: Send all lines of one logical sequence through the same session, in order, and close it before the next case starts.
- Reset between cases: Never reuse a session across unrelated sequences, even when the decoder looks stateless, because the cost of a shared session is a confusing failure.
- Assert field extraction: Check the extracted fields from each line, not only the final rule, since a decoder can match while extracting the wrong value.
- Test partial input: Include a truncated or out-of-order sample to confirm the decoder does not produce a false match.
- Name sequences clearly: Use file names that show the sequence and its expected outcome so reviewers can follow the test.
Confirm with your own samples which decoder behaviors depend on earlier lines in your release.
Frequency and timeframe correlation rules fire only after a number of matching events arrives within a window. A single logtest call with one line can never trigger them, so the test must send an ordered sequence of events that crosses the threshold. The order and spacing of the events matter, and a test that mixes sequences from several cases in one session will produce counts that belong to other tests.
- Send ordered sequences: Replay the events in the timestamp order the rule expects, and keep the count one above or below the threshold in separate cases.
- Assert the threshold boundary: Test that the rule fires at the threshold and does not fire one event short.
- Isolate counts: Use a separate session for each correlation test so events from one case do not add to another case's count.
- Check the same-field grouping: Use sample sources that differ in the field the rule groups by, to confirm events from different sources do not combine.
- Verify the parent alert: Assert the correlated rule ID on the final event, and confirm that the earlier events matched only their child rules.
Confirm how the logtest session tracks frequency state in your release, since timeframe behavior depends on it.
Security considerations for a logtest pipeline
A logtest pipeline calls a live Wazuh server, holds credentials and stores sample data, so it becomes an access path in its own right. The cards below cover the controls that keep it from weakening the detection stack it is meant to protect.
Keep API credentials in the CI secret store
The pipeline needs a Wazuh API username and password to open logtest sessions. Store them as masked, protected secrets in your CI platform and never commit them to the repository, a sample file or a job log. Check that the secret is not echoed by debug output and that forked or untrusted branches cannot read it. Rotate the credential on a schedule you set and after any staff change on the pipeline.
Use a least-privilege API account
Create a dedicated Wazuh user for the pipeline that can call only the logtest endpoints it needs, rather than reusing an administrator account. Confirm the role and its permissions in your own deployment, since role names and API scopes depend on your version. Review the account whenever the pipeline's calls change, and disable it when the pipeline is retired.
Keep sample logs free of personal and customer data
Sample logs are copied into a repository, so they are often read by far more people than production logs are. Replace usernames, IP addresses, email addresses, hostnames and tokens with synthetic values before committing, and say in the test file header that the data is synthetic. Add a pre-commit or pipeline check that flags common patterns, and treat any real sample found in history as an incident to review.
Restrict who can change expected rule IDs
The expected rule IDs in test files define what the pipeline considers a passing detection, so changing them can silently weaken coverage. Require code owners from the security team to approve changes to expectations and to rule files together. Make the protected branch rules and approval settings part of your review, and flag any PR that removes an assertion without adding a replacement.
Limit network exposure of the test environment
The Wazuh API that logtest uses should not be reachable from the internet or from general user networks. Place the test manager on a segment that the CI runners can reach, restrict the source addresses allowed to connect, and confirm that TLS verification is on rather than disabled for convenience. If your runners are shared or hosted, decide whether they can reach that segment at all.
Record an audit trail for rule changes
Every change to a decoder, rule, CDB list or expectation should be traceable to a commit, a reviewer and a pipeline run. Keep pipeline logs for the period your change process requires, and record which build tested which rule version. Confirm with your compliance team how long these records must be kept, and whether the Wazuh manager's own logs need to be retained alongside them.
How a commit flows from rule change to pass or fail
The flow starts when a developer pushes changes to decoders, rules and sample logs. The CI job loads each sample and sends it to the Wazuh logtest API running in a test environment that is separate from production. The job then compares the rule IDs returned for each sample with the IDs the sample file expects. A mismatch blocks the merge, and the reviewer should check that every expected rule still fires after a change.
Commit-to-verdict path, with the test Wazuh environment isolated from production.
Limits to confirm in your environment
A CI job that calls logtest is only as reliable as its assumptions about the Wazuh build, the rule set and the agent pipeline. The cards below cover the points where a passing build can still hide a broken detection, so each one should be confirmed against your own installation before the pipeline gates a deployment.
Logtest behavior on your patch level
Confirm that the logtest endpoint, its request format and its session handling behave the way your pipeline expects on the exact 4.14 patch level you run. The release line is 4.14, and patch releases have been shipped roughly every one to two months, so a test harness written against one patch may need adjustment after an update. Pin the version in your test environment and re-run the suite after every server patch.
Wazuh release notesKeeping the test server in sync
A logtest result only reflects the rules and CDB lists loaded on the server that answers it. Decide how the test server receives the same decoders, rules and lists as production, and who owns that copy. Compare loaded content, not just repository content, because a file that was committed but never deployed will pass tests that production never runs.
Agent-side pre-decoding fidelity
Logtest receives a log line, but in production part of the parsing happens on the agent before the server sees the event, including fields added by the agent and the log source configuration. Sample logs copied from a ticket or a console may not carry that context. Capture samples from the agent or the source as the server receives them, and record which localfile settings produced each sample.
Upgrade-related rule changes
Wazuh ships updated default rules and decoders with its releases, and local rules can interact with changed defaults, for example through level overrides or changed decoder names. Decide how the pipeline reports a rule that fires differently after an upgrade, and who reviews the diff before the upgrade reaches production. Treat expected-match tests as a regression signal for upgrades, not only for your own edits.
Secure API reachability from CI
The pipeline needs network access to the Wazuh API and a credential with rights to run logtest, so confirm which runner types can reach the endpoint and whether that path crosses a network boundary you must document. Store the API credential in your CI secret store, scope it to test use, and rotate it on a schedule your security team sets. Runners hosted outside your network need an explicit, reviewed route.
Wazuh release notesQuestions teams ask before testing Wazuh rules in CI
How much effort does a first Wazuh rule test pipeline take?
The effort for a first pipeline depends mostly on how much detection content it must cover and how much usable test data already exists. A team with a small set of custom rules, one Wazuh environment and existing sample logs can usually wire up a first pipeline quickly. A team with many decoders, several environments (for example, lab, staging and production) and no recorded logs spends most of its time collecting and labeling samples before any pipeline code is written. Ask any partner to split the quote into sample collection, pipeline build, expected-rule test design and documentation, since those components scale differently. No figure is given here because effort depends on the size of your ruleset.
Can our own team build a Wazuh rule test pipeline without a partner?
Yes, if the team already runs Wazuh and has working CI skills in the platform it uses. The work is less about the pipeline mechanics and more about sample logs and test design: each test needs a real log line from the source, a clear expectation of which decoder and rule should match, and a negative case that should not fire. Teams that lack someone who knows the log sources well usually find that the bottleneck is getting representative samples from application or device owners, not writing the API calls. A partner is useful when the team needs that work done alongside its own staff or when it wants a reviewed design.
What does the work need from our team?
The work needs four inputs from your side:
- Sample logs from each source, including both normal and malicious events, with any sensitive values removed.
- A test Wazuh instance that matches the production server version closely enough for logtest results to be meaningful.
- CI access to the repository and runners where the pipeline will run, along with a way to store a service credential for the API.
- Rule owners who confirm which alerts must keep firing and what each should show an analyst.
If rule owners are unavailable, the pipeline will test what the authors believe is correct, which is a weaker control than an agreed expectation.
How long does it take to get a Wazuh rule test pipeline running?
Duration is driven by the same factors as effort: the number of rule files, how many sources need sample logs, and how quickly your owners can review expected results. Sample collection is often the longest step because it depends on other teams. Wiring the pipeline into an existing CI system is usually a shorter step. Treat any duration you are given as a plan to confirm, and ask the provider to name the dependencies, such as access approvals or change windows, that could move it. DeployOpen plans these engagements as fixed-scope work, with scope, deliverables and timelines agreed in writing before the work starts.
How does an automated rule test fit into our change control?
Automated tests work best as evidence attached to a change request rather than as a replacement for approval. A typical flow opens a merge request with the new or changed rule, runs the logtest-based checks against the sample logs, and records the result in the pipeline history that reviewers can read. Your change board can then decide whether the expected alerts, levels and descriptions are acceptable. Ask how failing builds are handled, who may override a failure, and whether the test results are retained for the period your audit or change policy requires.
What should we ask for in a written quote for this work?
A quote should follow from a written scope, so ask for a scope that lists the log sources covered, the number of decoders and rules in scope, the CI platform, the Wazuh versions tested and the environments the pipeline must reach. Also ask for the deliverables: the repository layout, the test harness, the documented expectations for each sample, the session handling approach and the handover to your team. Confirm which tasks are one-time, such as the first build, and which recur, such as updating samples after a Wazuh upgrade or adding sources. DeployOpen does not publish a price list; a quote follows from the scope you agree.
Does this testing replace the Wazuh rule review by our security team?
No. An automated test checks that a rule behaves as the expectations you wrote, so it catches regressions such as a changed decoder that stops a rule from matching. It does not decide whether the expectation itself is correct or whether a detection is worth its alert volume. Security engineers still need to review new detections, ATT&CK mappings and alert levels. Keep the review step in the merge process, and treat the pipeline as a way to make the reviewed behavior repeatable across changes and Wazuh upgrades.
How DeployOpen scopes and delivers logtest-based rule testing
DeployOpen treats Wazuh detection content as code for teams that want rule tests to run in their own pipeline. We scope the sample log set, the logtest calls and the failure criteria in writing, then build and document the test suite inside infrastructure you control. Engagements are fixed-scope, and ongoing support is available as a retainer.
How we scope
- Inventory the custom decoders and rules that need regression coverage, and the log sources each one reads.
- Agree which expected rule IDs and decoded fields each sample log must produce before any pipeline work starts.
- Confirm the Wazuh version in use and the CI platform, self-hosted or hosted, so the test runner matches your environment.
How we build
- Create a repository layout that stores sample logs next to expected outcomes for each decoder and rule file.
- Write a runner that calls the logtest API, opens and closes sessions cleanly, and compares results to the expected outcomes.
- Configure the pipeline to fail the build when an expected rule stops matching, and test that failure path on purpose.
How we hand over
- Deliver the repository, runner scripts, pipeline definition and a short guide for adding new sample logs.
- Document how to run the suite locally and how credentials for the logtest API are stored and rotated.
- Walk your engineers through a sample change, from a new rule to a failing test to a passing build.
How we support
- Update the test suite when you upgrade Wazuh, so expected outcomes are checked against the new release.
- Add sample logs and test cases as new detections are written, using the same review process as the rules.
- Offer ongoing support and continuous testing as a retainer, with scope agreed in writing.

