Automating Wazuh with the server API: when scripts beat the dashboard
Scripts beat the dashboard when the same operation has to run across many agents, repeatedly, and with a record of who ran it. A team managing hundreds of endpoints that needs to move agents between groups, check enrollment status, or validate a rule change before it reaches production is doing work the dashboard was not built to repeat reliably. The Wazuh server API is the interface for that work. It exposes the server's management functions over HTTP so that agent management, group configuration, cluster information and ruleset checks can be called from a pipeline, a runbook or a scheduled job. The API is part of the self-hosted open-source Wazuh deployment, which is distributed under the GNU General Public License version 2 with no license fee, so the automation layer adds engineering effort rather than a license cost.
Before you design anything, confirm the API behavior against your installed version. This page is written for the Wazuh 4.14 release line, and the current patch is 4.14.9, released on 14 October 2026. Patch releases in this line have arrived roughly every one to two months, and endpoint paths, response fields, token lifetimes and permission names can change between releases. Read the release notes for the version you run, then check the API reference that ships with that version on your own server. Treat any script that touches production as something to test on a staging manager first, and pin the version of the server and the scripts together so that an upgrade does not silently break your automation.
The decisions that matter most are who holds the automation credentials and what those credentials can do. A dedicated automation account with a role scoped to the exact operations the scripts need is safer than reusing an administrator login, and the role and permission set must be confirmed in your version's RBAC documentation before you rely on it. Ask your team to answer three questions in writing: which operations are read-only and which change state, where tokens are stored and how they are rotated, and what audit trail the API activity leaves in your indexer. Those answers determine whether the automation is repeatable and reviewable, which is the reason to write scripts in the first place.
Which API tasks teams script first
Every script starts with authentication. The Wazuh server API issues short-lived tokens in exchange for credentials, and automation should request a token at the start of a run, reuse it only while valid, and request a new one when a call is refused. Scripting this step once removes hard-coded passwords from cron jobs and makes it possible to rotate the automation credential without editing every script.
- Token lifecycle: Confirm the token lifetime and the renewal call for your version in the API reference, then build the refresh logic around those values.
- Credential storage: Keep the automation password in a secrets store, not in the script or shell history.
- Error handling: Treat an expired or rejected token as a normal event that triggers one re-authentication, not as a reason to retry in a loop.
- Least-privilege account: Create a dedicated user for automation so audit logs show which jobs made which changes.
- TLS verification: Confirm how the API certificate is validated in your environment before disabling any check.
Before relying on a script in production, confirm the authentication endpoint, token format and expiry behavior in the vendor API reference for the exact release you run, and test a forced expiry in a lab.
Agent inventory and group membership are the tasks teams script most often, because they change with every onboarding, decommission or reorganization. Scripts can list agents by status, move agents between groups, and check which group configuration applies, which replaces manual clicks in the dashboard and keeps changes repeatable across a large fleet.
- Inventory queries: Pull agent IDs, names, operating systems and connection status to reconcile against your asset source of truth.
- Group assignment: Add or remove agents from groups in batches, and log each change with a ticket reference.
- Stale agent review: Identify agents that have not connected recently so they can be investigated or removed.
- Group configuration: Confirm which calls can read or change group shared configuration, and whether changes take effect on agents without a restart on your version.
- Removal safeguards: Require a second check before deleting agents, since removal is hard to reverse for the affected endpoints.
Confirm the endpoint names, parameter names and pagination behavior in the vendor API reference for your installed version, and test batch changes against a small agent group first.
Wazuh Query Language (WQL) filters let scripts select agents, groups or other objects by attributes instead of pulling full lists and filtering them locally. Queries become the foundation for reports and bulk actions, so an incorrect filter can change far more agents than intended. Teams usually script WQL after they have confirmed how their version expresses operators and fields.
- Filter design: Write filters that match on stable attributes such as group name, operating system or version, and avoid matching on display names alone.
- Operator support: Confirm which comparison and logical operators the API accepts, and how string matching behaves for case and wildcards.
- Dry runs: Run each filter as a read-only call and review the count before attaching any write action to it.
- Pagination: Check how result limits and offsets apply, so scripts do not silently miss records on large fleets.
- Saved filters: Store tested filters in version control with a short description of their intent.
Confirm the supported fields and operators for your release in the vendor API reference, and treat any filter that drives a write action as code that needs review.
Ruleset testing is where automation protects detection quality. Scripts can send sample log lines through the logtest facility and check which decoder and rule matched, before a custom rule is deployed. A CI job that runs a fixed set of expected outcomes catches decoder regressions after a rule edit or a Wazuh upgrade, which manual testing often misses.
- Fixture library: Keep representative log samples for each custom decoder and rule, with the expected rule ID and level.
- Expected outcomes: Compare the matched decoder and rule to the expected result and fail the job when they differ.
- Upgrade regression runs: Replay the same fixtures against a test server after each version change.
- Session handling: Confirm how the logtest session is opened, used and closed through the API, so test runs do not leave stale sessions behind.
- Separation from production: Run tests on a non-production manager and promote rules only after the results pass.
Confirm the logtest endpoint, its request format and session behavior in the vendor API reference for the installed version, since these details change between releases.
Reporting scripts collect facts from the API on a schedule and write them to files or other systems. Typical outputs are agent inventory snapshots, group membership records and lists of disconnected endpoints, which auditors and operations teams use as evidence or as a work queue. The automation changes the process from ad hoc exports to dated, repeatable records.
- Scheduled snapshots: Export agent status and group membership on a fixed schedule, stored with a timestamp.
- Change records: Compare each snapshot with the previous one and report additions, removals and group moves.
- Evidence handling: Store exports with access controls, since agent inventories reveal host names and network details.
- Output format: Choose CSV or JSON deliberately, and document the fields so downstream readers can rely on them.
- Load impact: Schedule large exports outside peak alert handling and watch the effect on the server.
Report content depends on the fields each endpoint returns in your version, so confirm the available attributes and any pagination limits in the vendor API reference before promising a report layout to auditors.
Automation approaches and when each fits
This table compares direct REST calls, scripts, configuration management playbooks and scheduled API jobs against maintenance effort, auditability, secret handling and fleet size. Read each row as a trade-off, not a ranking, because the right choice depends on how often changes happen and who must review them. Most teams combine a small number of approaches rather than picking one for everything.
| Approach | Best fit | Auditability and secrets | Main maintenance cost |
|---|---|---|---|
| Direct REST calls (ad hoc) | One-off lookups, incident queries and checking a single agent or group | Calls leave no record unless you log them. Tokens are typed by hand, so keep them out of shell history | Low upkeep, but repeated manual work grows quickly as the fleet grows |
| Versioned scripts run by a person | Repeatable tasks such as bulk group moves, agent inventory exports and ruleset tests | Good if scripts are in source control and read the token from a vault or environment at run time | Someone must own the script, its error handling and its changes after Wazuh version updates |
| Configuration management playbooks | Agent configuration, group assignment and enrollment settings across many hosts | Changes are reviewed and stored with the playbook history. Credentials usually come from the tool's vault | Playbooks must track Wazuh API changes and the tool's own release cycle |
| Scheduled jobs calling the API | Recurring reports, inventory snapshots and checks that must run without an operator | Needs its own service account, scheduled run logs and a rotation process for its token | The job, its schedule, its failure alerts and its account all need ongoing ownership |
| Small fleets | A few dozen endpoints where one administrator knows every group and policy | Direct calls and a short script library are often enough, provided tokens are not shared | Overhead of a full pipeline may outweigh the work it removes |
| Large or multi-team fleets | Many groups, several administrators and change approval requirements | Pipeline runs, reviewed changes and scoped automation accounts give the evidence reviewers ask for | Needs a named owner, testing against a non-production server and a plan for API changes |
| Ruleset testing in automation | Checking decoders and rules before they reach production | Test inputs and expected outputs should be stored with the change record | Test cases must be kept current as rules change |
Setting up a scoped automation account
This sequence produces a dedicated Wazuh API user with only the permissions a script needs, a verified token, and a write path that is opened one operation at a time. Each step ends with a check you can record before moving on.
Confirm the automation scope in writing
Before touching the server, the platform owner and the script's author list every API call the automation will make, grouped as read or write and by resource, such as agents, groups, rules or manager settings. This list becomes the basis for the role assignment and for the audit review later. Confirm with your Wazuh administrator which endpoints your deployment exposes and how they are documented for your installed version, since permissions are checked against the version you run. The step is done when the list is approved and each call has a named owner.
Create a dedicated API user
A Wazuh administrator creates a separate user in the Wazuh API user management area, named for the script or team (for example, an illustrative name such as svc-inventory-sync) and never shared with a human account. The account gets a strong, unique password stored in your secrets manager, not in the script. Do not reuse the default admin credentials or an interactive SSO identity for automation. The step is done when the user appears in the user list, is not linked to a personal login, and its password is recorded in the vault.
Assign a read-only role first
Create or select a custom role that grants only the read permissions from your scope list, and bind it to the new user. Avoid the built-in administrator role, since it grants every permission. Check the role's permission set against the documented RBAC policies for your installed Wazuh version, because policy names and defaults can change between releases. The step is done when the role lists only read actions and the user is bound to that role alone.
Request a token and inspect its scope
Authenticate against the API's login endpoint with the automation account to receive a JSON Web Token, then store it only in memory or in the vault-backed runtime. Decode or inspect the token's claims and confirm that the policies it carries match the read-only role, not a broader set. Confirm the token lifetime in your version's documentation and build renewal into the script rather than hardcoding a long-lived value. The step is done when the token's policy list matches the role you assigned and the script can refresh it without manual input.
Test one read-only call and check the audit trail
Run a single, low-impact read request such as listing agents with a WQL filter that matches a small known set. Verify that the response contains the expected count and fields, and then check the API audit records for the request, confirming it shows the automation user and the correct endpoint. Keep the request and its result in your change record. The step is done when the call succeeds, returns the expected data, and appears in the audit log under the service account.
Confirm that out-of-scope calls are refused
Using the same token, attempt one write call that is not in your scope list, such as deleting an agent or changing a group configuration. The API should reject it with an authorization error, and the audit record should show the denial. This negative test proves the role is doing its job and catches over-broad grants before they reach production. The step is done when the denial is recorded and no change was made to the environment.
Add write operations one at a time
Grant one write permission at a time, starting with the lowest-risk action your scope list approved, such as adding an agent to a group in a test environment. After each grant, repeat the token request, run the write once against a test object, and confirm the change in the Wazuh interface and the audit log. Only then move to the next permission. The step is done when each write is verified in a non-production environment and the role change for it is documented.
Review permissions and audit records on a schedule
Set a recurring review, with an interval your team chooses, in which the owner compares the role's current permissions to the approved scope list and reviews the audit records for the automation account. Remove any permission no longer used and rotate the password and any stored credentials as your policy requires. Ask your Wazuh vendor or documentation which audit log locations apply to your version. The step is done when the review record shows no unexplained permissions or activity and the next review date is set.
How tokens and WQL filters shape each request
Every script that talks to the Wazuh server API follows the same loop. It first authenticates against the API with a dedicated automation account, receives a token with a limited lifetime, and attaches that token to each later request. When the token expires, the script must request a new one rather than assume the session is still valid. Design the script so that re-authentication is a normal branch, not an error path, and log each authentication attempt so failed logins from the automation account stand out. The exact token lifetime, how the token is passed in the request header, and the endpoint used to request it must be confirmed in the API reference for the installed release, because these details change between versions and should not be copied from older examples.
Filters go in the query string of each call. The Wazuh query language (WQL) lets a request select agents, alerts or other objects by field, for example by agent group, operating system or status, so the server returns only the records the script needs. Keep queries narrow and paginate with the limit and offset parameters the API documents, instead of pulling everything and filtering in the script. Field names, operators and the maximum page size are release-specific, so test each filter against a non-production server and confirm the syntax in the documentation for your version before it goes into a scheduled job.
Plan for errors at the request level. A call can fail because the token expired, because a WQL expression is malformed, because the account lacks permission for an object, or because the server is busy. Treat each case differently: retry only transient failures with a backoff, stop and alert on authorization failures, and write malformed-filter errors to the job log for correction. Pagination needs the same care, because a job that stops after the first page will silently miss agents. Confirm that the total count in the response matches the number of records the script collected before it reports success.
Request flow from an automation job to the Wazuh server
The flow starts in the automation runner, which reads its API credentials from a secret store and then requests a token from the Wazuh server API. Each later call carries that token, and the server checks the account's RBAC permissions before it runs the action. Reads and writes that touch agents, groups or rules pass to the Wazuh server, while alert queries go to the Wazuh indexer. Check that the runner never holds a password for the dashboard, and that every accepted and rejected call is recorded in the audit log on the Wazuh host.
How an automation job reaches the Wazuh server API across the trust boundary.
Securing the automation account and its secrets
A Wazuh API automation account can read inventory, change agent groups and push configuration, so it deserves the same care as a privileged administrator. The cards below cover the access, secret, network and audit controls that keep a script from becoming the weakest path into your monitoring platform.
Scope the account to least privilege
Create a dedicated API user and assign only the RBAC policies its job needs, such as reading agents or managing one agent group. Avoid reusing the default administrator or a person's dashboard login. Review the assigned policies after every change to the script's purpose, and confirm in your own environment which actions each policy permits before you grant it.
Keep secrets out of scripts
Store the API username and password in a secrets manager or a root-readable environment file, never in the script body or version control. Load them at runtime so a leaked repository does not expose the credentials. Confirm that job logs and shell history do not echo the values.
Rotate tokens and passwords
API tokens issued for automation expire, so the script must request a new token when the old one lapses instead of storing one long-lived value. Rotate the account password on a schedule your security policy sets, and test the rotation in a staging deployment first. Record who owns each rotation.
Validate TLS certificates
Scripts often disable certificate checks to get past a self-signed certificate on the API port. Instead, add your internal certificate authority to the trust store the script uses and keep verification on. A script that accepts any certificate can send its credentials to a host impersonating the Wazuh server.
Restrict API port exposure
Allow connections to the Wazuh API port only from the automation runner, administrator networks and the dashboard host. Enforce this with host firewalls or network policy, and confirm the port is not reachable from user networks or the internet. Document the allowed source addresses so reviewers can check them.
Separate read and write accounts
Run reporting and inventory jobs under a read-only account and keep change-making credentials, such as those that edit agent groups or push configuration, in a separate account used only by approved pipelines. This limits the damage a compromised reporting script can do. Review which account each job uses during access reviews.
Log every automated change
Record which account made each API call, when, and what it changed. Forward API audit records to your central log store so changes made by scripts can be traced during an investigation. Confirm in your own deployment where the API activity log is written and how long it is kept.
Questions teams ask before automating the Wazuh API
What drives the cost of automating the Wazuh API?
The cost depends mainly on how many operations the automation must cover, how many environments it must work across, and how much existing tooling it must connect to. A script that only lists agents costs far less to build than a pipeline that enrolls agents, assigns groups, pushes configuration, tests rules and reports results into a ticketing system. Ask any partner to break the quote into discovery, script build, testing against a non-production server, handover and any retainer for later changes. Self-built work costs internal engineering time, which recurs as the API and your needs change. Confirm with your own team how many environments and identity systems are involved before comparing quotes.
How long does it take to get a first working Wazuh API script?
The time to a first script depends on whether an engineer already knows the Wazuh server API and has a non-production Wazuh deployment to test against. A read-only script that authenticates and lists agents is the usual first step, and it can be verified quickly once a token request works and the automation account has the right permissions. Longer work includes WQL filtering across large agent sets, group changes, ruleset testing and error handling for token expiry. Ask for the expected duration in writing, tied to a named deliverable such as a tested script in your staging environment.
What does the internal team need to provide for API automation?
Your team needs to supply a non-production Wazuh environment, a named owner for the automation account, a clear list of operations the automation may perform, and access to the systems the script will read from or write to. Someone must also decide where secrets are stored and how tokens are rotated. Your Wazuh administrators should review the role-based access control settings with you, because an automation account should hold only the permissions its tasks need. Expect your security team to review the design before it touches production.
Can our own engineers automate the Wazuh API without a partner?
Yes, a team with experience in REST APIs, Linux administration and Wazuh operations can build simple automation in-house. The work is manageable for read-only reporting and routine group assignment. It becomes harder when scripts must handle authentication lifecycle, role boundaries, multi-node deployments, audit logging and tests for ruleset changes. Consider whether the people who would maintain the scripts have time to do so after the first release. A partner is useful when you want a scoped build, documented handover and an upgrade plan, rather than an open-ended internal project.
How do Wazuh upgrades affect existing API scripts?
Upgrades can change API endpoints, response fields, permissions and authentication behavior, so scripts should be treated as dependent software. Wazuh publishes release notes for each patch and minor release, and the 4.14 line has received patch releases roughly every one to two months, so a cadence of regular testing is sensible. Keep scripts in version control, pin the Wazuh version each one was tested against, and run a regression set in staging before production upgrades. Confirm the exact compatibility notes for your target version in the release notes before scheduling.
How does DeployOpen scope an API automation engagement?
DeployOpen agrees scope, deliverables and timelines in writing before work starts, so the automation has a defined list of operations, target environments and acceptance tests. A typical scope lists the tasks to automate, the account and role design, where secrets are kept, the test environment, documentation and handover sessions. Changes after kickoff are handled through the written scope. Ongoing support, upgrades and testing can be placed on a retainer. DeployOpen does not publish a price list, so a quote follows from the written scope and the environment details you provide.
Which permissions should an automation account for the Wazuh API have?
An automation account should hold only the permissions its specific tasks need, scoped to the agent groups or resources it manages. Start with read-only access for reporting, then add write permissions one operation at a time, each approved by the owner of the Wazuh environment. Avoid reusing administrator accounts for scripts, and avoid sharing one account across unrelated automations so that audit logs remain attributable. Review the role-based access control policies in your Wazuh version and confirm which actions each role allows before granting them.
Does automating the Wazuh API help with compliance evidence?
Automation can produce consistent, repeatable records such as agent inventories, group assignments and configuration checks, which compliance teams can review as technical evidence. It does not make an environment compliant by itself, and it does not replace an independent audit. Confirm with your auditor which records they will accept, how they should be retained and how the automation account's actions appear in logs. DeployOpen prepares systems, controls and evidence for compliance assessments, but independent auditors and certification bodies issue any audit report or attestation.
Keeping automation working through Wazuh upgrades
Automation written against the Wazuh server API breaks silently after upgrades more often than it breaks loudly, so plan for API behavior to change between versions even within the same release line. The 4.14 line has already shipped several patch releases in 2026: 17 March, 23 April, 1 July, 29 July, 23 September and 14 October. Each one may touch authentication, endpoint paths, response fields or the way filters and WQL queries are evaluated. Your scripts depend on exactly those details, including the token request, the q filter syntax and the field names in agent and group responses, so none of them can be assumed stable because a patch number looks minor.
Before any patch reaches production, run the full script set against a non-production Wazuh server at the same version you plan to deploy. Check the token request and refresh behavior, a read-only agent listing, a group membership change followed by its rollback, and a wazuh-logtest run against a sample event. Compare the output with the previous run and treat any change in status codes, field names or pagination as a failing test. Confirm with the Wazuh release notes which API changes each patch lists, and record that check as part of the change ticket. Keep the non-production environment close to production in version, cluster layout and the RBAC role assigned to the automation account, because a permission change can look like an API change.
Keep every script, its configuration template and its test cases in version control, and tag the Wazuh version each commit was validated against. Store the automation account's credentials outside the repository and rotate them under your normal secrets process. When a patch breaks a script, the tag tells you exactly which version last worked, and a diff between tags shows what you changed. Review the repository after each patch cycle so that pinned versions and test results stay current. Where your organization has a change board, ask it to approve the upgrade of the Wazuh server and the automation code together, since the two cannot be validated separately.
How DeployOpen works on this
DeployOpen treats Wazuh API automation as a defined piece of work inside your own Wazuh deployment. We agree which operations the scripts cover, which service account they run under, and how the results are tested and handed over before any code is written.
How we scope
- Inventory the API calls your team needs today, such as agent listing, group changes and ruleset tests.
- Define the automation account and the minimum RBAC permissions it needs, written into the scope.
- Agree in writing which Wazuh server and cluster nodes the scripts may reach, and which environments they touch.
- Engagements are fixed-scope, so deliverables and timelines are agreed before work starts.
How we build
- Build token handling, WQL filters and pagination into reusable scripts with clear inputs and outputs.
- Test read and write operations against a non-production Wazuh environment before production use.
- Check that group and agent changes produce the expected configuration, using your own rules and decoders.
- Keep credentials out of scripts and store them in your approved secrets handling process.
How we hand over
- Deliver the scripts, configuration notes and a permissions summary for the automation account.
- Document each API call the automation makes, its expected response and its failure behavior.
- Walk your operations team through running, updating and rotating credentials for the automation.
- Provide a written list of open items, such as Wazuh version dependencies, for your team to confirm.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after handover.
- Re-check automation scripts after each Wazuh upgrade you schedule, since API behavior can change between versions.
- Review permission changes and retest scripts when your team adds new automated operations.
- Confirm the retainer scope and response expectations in writing before the engagement starts.

