# Wazuh agent groups and agent.conf: agent_groups, API, filters and merged.mg

> Wazuh agent groups: agent_groups and API endpoints, multi-group order, name, os and profile filters in agent.conf, verify-agent-conf, merged.mg and sync checks.

Published: 2026-10-30. Updated: 2026-11-12. Category: Configuration. Tags: Wazuh 4. URL: https://wazuh.blog/en/blog/wazuh-agent-groups/ Polish original: https://wazuh.blog/blog/wazuh-agent-groups/

An agent group defines a set of files and the central configuration (`agent.conf`) that the manager sends to the agents assigned to it. This post covers creating groups and assigning agents with `agent_groups` and the API, the order with multiple groups, filters in `agent.conf` and checking synchronization. The examples are synthetic: `example-*` groups, the agent `agent-01`.

## The default group and group directories

Every newly connected agent belongs to the `default` group unless it is assigned otherwise. The group is created at installation, and its files live on the server in `/var/ossec/etc/shared/default/`. Each group has a directory `/var/ossec/etc/shared/<GROUP_NAME>/` with an `agent.conf` file, empty by default.

The manager sends the agent all files from the directories of its groups. `ar.conf` (Active Response state) always reaches the agent, even when it is not in the group directory. The agent saves the received files in `/var/ossec/etc/shared`, without a subdirectory named after the group. The files must be readable by the `wazuh` user.

Among other things, you can configure `syscheck`, `rootcheck`, `localfile`, `wodle name="command"`, `labels`, `sca`, `syscollector`, `client_buffer` and `wodle name="osquery"` remotely. The agent buffer limits are covered in the [client_buffer post](/en/blog/wazuh-client-buffer/). Remote commands need an extra option on the agent in `/var/ossec/etc/local_internal_options.conf`:

```text
# Allow remote commands from shared configuration (wodle command)
wazuh_command.remote_commands=1
# Allow command, full_command and socket sources in logcollector
logcollector.remote_commands=1
```

## Creating groups

There are three methods: the dashboard (Agents management > Groups > Add new group), the `agent_groups` tool and the API. The tool and the API example need root privileges. A group name can contain upper and lower case letters, digits, dots, underscores and hyphens, and the group must exist before an agent is assigned.

```bash
# Create groups quietly (no confirmation prompt)
/var/ossec/bin/agent_groups -a -g example-linux -q
/var/ossec/bin/agent_groups -a -g example-web -q

# List all groups with agent counts
/var/ossec/bin/agent_groups -l
```

The documentation shows the listing output as `Groups (5):`, then the group names with the agent count in parentheses (for example `default (2)`), and a line `Unassigned agents: 0.`. The same through the API:

```bash
# Get a token, then create a group (use the master node address in a cluster)
TOKEN=$(curl -u <API_USER>:<API_PASSWORD> -k -X POST 'https://<WAZUH_MANAGER_IP>:55000/security/user/authenticate?raw=true')
curl -k -X POST "https://<WAZUH_MANAGER_IP>:55000/groups?pretty=true" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"group_id": "example-linux"}'
```

The response looks like `{"message": "Group 'example-linux' created.", "error": 0}`.

## agent_groups tool options

| Option | Action |
|---|---|
| `-l` | List all groups |
| `-l -g group_id` | Agents in a group |
| `-c -g group_id` | Group configuration files |
| `-a -g group_id [-q]` | Create a group |
| `-r -g group_id [-q]` | Delete a group, affects all assigned agents |
| `-a -i agent_id -g group_id [-q]` | Add a group to the agent's group list |
| `-a -f -i agent_id -g group_id [-q]` | Replace the agent's groups with a single group |
| `-r -i agent_id [-q]` | Remove the agent from all groups, the agent returns to `default` |
| `-r -i agent_id -g group_id [-q]` | Remove the agent from one group |
| `-s -i agent_id` | Groups of the agent |
| `-S -i agent_id` | Shared file synchronization status of the agent |
| `-q`, `-d`, `-h` | Quiet mode, debug, help |

## Assigning agents

For the agent with ID `001` and the group `example-web`, assignment with the tool and with the API looks like this (`-f` in the tool and the `force_single_group` parameter in the API replace the existing groups with a single one):

```bash
# Add the group to the agent's group list
/var/ossec/bin/agent_groups -a -i 001 -g example-web

# Same through the Wazuh server API
curl -k -X PUT "https://<WAZUH_MANAGER_IP>:55000/agents/001/group/example-web?pretty=true" \
  -H "Authorization: Bearer $TOKEN"
```

The API returns `affected_items` with the agent identifier and the message `All selected agents were assigned to example-web`. You can also set the group during registration with `agent-auth -G`; registration details are covered in the [enrollment post](/en/blog/wazuh-agent-enrollment/).

Group-related API endpoints (API spec for version 4.14.0):

| Method and path | Action |
|---|---|
| `GET /groups` | Information about groups |
| `POST /groups` | Create a group, body `{"group_id": "..."}` |
| `DELETE /groups` | Delete groups |
| `GET /groups/{group_id}/agents` | Agents in a group, e.g. `select=id,name` |
| `PUT /agents/{agent_id}/group/{group_id}` | Assign an agent to a group |
| `DELETE /agents/{agent_id}/group/{group_id}` | Remove an agent from a group |
| `DELETE /agents/{agent_id}/group` | Remove an agent from groups |
| `PUT /agents/group` | Assign several agents (`agents_list`) to a group |
| `DELETE /agents/group` | Remove several agents from a group |
| `GET /groups/{group_id}/configuration` | Group configuration |
| `PUT /groups/{group_id}/configuration` | Update the configuration, expects complete, valid XML |
| `GET /groups/{group_id}/files` | Files in the group directory |
| `GET /groups/{group_id}/files/{file_name}` | One group file |

You check membership with the query `GET /agents?agents_list=001&select=group`, which returns a list, for example `["default", "example-web", "example-linux"]`.

## Multiple groups, order and shared files

An agent can belong to many groups and gets files from each of them. Priority rises from left to right: the group assigned last has the highest priority. When any parameter conflicts, its configuration wins. The order is set by the moment of assignment.

The manager merges the agent's group files by these rules:

- shared files (e.g. rootcheck lists) go to a common directory, and for duplicates the last one added overwrites the earlier ones,
- the `agent.conf` of the next group is appended to the previous one, and on a conflict the last assigned group applies,
- the groups' own shared files are combined and sent together.

Example: an agent belongs to `default`, `example-base` and `example-linux` (in that order), and both `agent.conf` files set the same thing. The value from `example-linux` applies. The command `agent_groups -a -f -i 001 -g example-base` would leave the agent with only `example-base`, and `-r -i 001 -g example-linux` removes just one group.

## merged.mg

At the agent's first registration the manager creates the `merged.mg` file from the configuration and group membership, and on every change it updates the file and sends it to the agent. On the server it lives in `/var/ossec/etc/shared/merged.mg`, on the agent in `/var/ossec/etc/shared/merged.mg` (Linux) or `C:\Program Files (x86)\ossec-agent\shared\merged.mg` (Windows). The option `remoted.guess_agent_group=1` uses the checksum of this file: after re-registration the agent lands in `default` by default, and once you add this option to `/var/ossec/etc/local_internal_options.conf`, the manager compares the agent's `merged.mg` checksum with the checksums of other agents to restore the group. The group's `merged.mg` file shows up in the listing from `agent_groups -c -g <group>`.

## Filters in agent.conf

The `agent.conf` file (the `<agent_config>` section) is valid only on the server. Blocks are filtered with the attributes `name`, `os` and `profile`. The value is an sregex (OS_Match) pattern: matching is case-insensitive and not anchored unless the pattern uses `^` or `$`.

| Filter | Matches |
|---|---|
| `name` | The agent name |
| `os` | The agent's operating system information |
| `profile` | The profile list from `<config-profile>` in the agent's `<client>` section |

You read the agent's name and system with `agent_control -i <AGENT_ID>` (the fields `Agent Name` and `Operating system`). The agent sets profiles locally, with values separated by a comma and a space:

```xml
<!-- ossec.conf on the agent -->
<client>
  <config-profile>example-web, debian12</config-profile>
</client>
```

```xml
<!-- /var/ossec/etc/shared/example-web/agent.conf -->
<agent_config name="^agent-01$">
  <localfile>
    <location>/var/log/example-agent-01.log</location>
    <log_format>syslog</log_format>
  </localfile>
</agent_config>

<agent_config os="^Linux">
  <localfile>
    <location>/var/log/example-linux.log</location>
    <log_format>syslog</log_format>
  </localfile>
</agent_config>

<agent_config profile="example-web">
  <localfile>
    <location>/var/log/example-web.log</location>
    <log_format>syslog</log_format>
  </localfile>
</agent_config>
```

The `localfile` options in such blocks are covered in the [multiline logs post](/en/blog/wazuh-localfile-multiline/). Linux agent packages add `<config-profile>` themselves with system profiles (for example `amzn`, `amzn2023`), and the `profile` filter is matched against the whole list.

## Changing agent.conf safely

The manager does not distribute files whose name starts with a dot, so agents will not get an unfinished configuration. Edit the file under a dotted name, validate it and only then rename it:

```bash
GROUP_DIR=/var/ossec/etc/shared/example-web
touch "$GROUP_DIR/.agent.conf.tmp"
chown wazuh:wazuh "$GROUP_DIR/.agent.conf.tmp"
chmod 660 "$GROUP_DIR/.agent.conf.tmp"
# ... edit the temporary file ...
/var/ossec/bin/verify-agent-conf -f "$GROUP_DIR/.agent.conf.tmp"
mv "$GROUP_DIR/.agent.conf.tmp" "$GROUP_DIR/agent.conf"
```

Without `-f`, `verify-agent-conf` scans the group folders in `/var/ossec/etc/shared` and checks every `agent.conf`. A correct result looks like this:

```text
verify-agent-conf: Verifying [etc/shared/default/agent.conf]
verify-agent-conf: OK
```

The manager detects the new configuration on its own and sends it to the group's agents; restarting the manager speeds up distribution. Delivery time depends on file size, the number of agents and the protocol. The documentation gives an example of about 8 minutes for a 10 MB folder (without `merged.mg`) on 100 agents over UDP, and with TCP the time can be shorter.

## Distribution and confirmation

On every keepalive (`notify_time`, 20 seconds by default) the agent sends the checksum of its `merged.mg`. When the checksum differs from the manager's, the manager sends the updated file and the agent applies it right away. No agent restart is needed, regardless of `auto_restart`. On Linux `wazuh-agentd` keeps the connection, while on Windows the whole service restarts and the agent is briefly disconnected. The agent log shows the entry `wazuh-agentd: INFO: Agent is reloading due to shared configuration changes.`

You can check group synchronization in two ways:

```bash
# Tool: expected output "Agent '001' is synchronized."
/var/ossec/bin/agent_groups -S -i 001

# API: "group_config_status": "synced" means the agent has the current configuration
curl -k -X GET "https://localhost:55000/agents?agents_list=001&select=group_config_status&pretty=true" \
  -H "Authorization: Bearer $TOKEN"
```

## Precedence, disabling and limits

The agent's `ossec.conf` is read before the shared `agent.conf`, and for the same setting the last value applies, which is the one from `agent.conf`. If a file path for a given setting is given in both files, both go into the final configuration. In the documentation example, `sca` with `<enabled>no</enabled>` in `ossec.conf` and `<enabled>yes</enabled>` in `agent.conf` gives an enabled module, with the policy from `agent.conf` added.

An agent can ignore the shared configuration after you add `agent.remote_conf=0` to `/var/ossec/etc/local_internal_options.conf`.

Limits described for group files: the manager ignores a file whose path under `/var/ossec/etc/shared/` is longer than 224 characters (200 before version 4.14.10), the API rejects a group configuration file larger than 10 MiB with HTTP code 413, and `merged.mg` is built in memory, so very large files need about twice as much free memory.

## Fetching files from an external address

The manager can fetch `agent.conf`, `merged.mg` and other group files from a URL. This is defined by the file `/var/ossec/etc/shared/files.yml`, read at startup and reloaded on the fly:

```yaml
groups:
    example-web:
        files:
            agent.conf: https://example.com/agent.conf
            rootcheck.txt: https://example.com/rootcheck.txt
        poll: 15
```

A nonexistent group is created. If a file is named `merged.mg`, only it is fetched and then validated. `poll` is the fetch frequency in seconds. Parsing results and fetch errors go to `/var/ossec/logs/ossec.log`.

## What the documentation does not specify

The documentation does not describe the behavior when no `agent_config` filter matches, or the default value of `poll` in `files.yml`. It also gives neither a maximum number of groups per agent nor a way to change the group order other than the order of assignment.

## Sources

- https://documentation.wazuh.com/current/user-manual/reference/centralized-configuration.html
- https://documentation.wazuh.com/current/user-manual/agent/agent-management/grouping-agents.html
- https://documentation.wazuh.com/current/user-manual/reference/tools/agent-groups.html
- https://documentation.wazuh.com/current/user-manual/reference/tools/verify-agent-conf.html
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/client.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/api/api/spec/spec.yaml
