PL EN
WB-5E368C1ETLP:CLEARWazuh 4

Disconnected Wazuh agents: keepalive and agents_disconnection_time

When the Wazuh manager marks an agent as disconnected: keepalive, agents_disconnection_time and its alert, notify_time, the agent state file, API and wazuh-db.

The Disconnected status in Wazuh means the manager did not receive a keepalive message from the agent within the configured time. That moment depends on settings on both sides: the threshold in <global> on the manager and the check-in interval in <client> on the agent. You can read the status in the dashboard, through agent_control, through the API and in the local agent state file.

Four connection states

The agent life cycle covers installation and enrollment, connection states and removal. After enrollment, the manager keeps information about the agent and its connection status until the user deletes it. Deletion happens through the Wazuh server API or from the command line.

StateDescription in the documentation
Never connectedThe agent is registered but has not connected to the manager yet
PendingThe manager received a connection request but nothing more, authentication has not finished
ActiveThe agent is connected and can communicate with the manager
DisconnectedThe manager did not receive a keepalive within agents_disconnection_time, 15 minutes by default

The agent passes through the Pending state once in each cycle after startup. According to the documentation, staying in this state can point to a connectivity problem.

Threshold on the manager side

agents_disconnection_time in the <global> block of the manager ossec.conf sets the time since the last keepalive after which the manager treats the agent as disconnected. The default is 15m, the minimum is 1s. A positive number with the unit s, m, h or d is allowed. The documentation notes that the value should always be greater than notify_time configured on the agents.

agents_disconnection_alert_time sets the time after which an alert is raised, counted from the moment the agent is treated as disconnected. The default and minimum is 0s, which means an alert right after the agent is treated as disconnected.

The documentation example contains both settings with default values:

<global>
  <agents_disconnection_time>15m</agents_disconnection_time>
  <agents_disconnection_alert_time>0</agents_disconnection_alert_time>
</global>

The documentation also shows single-value examples: <agents_disconnection_time>1m</agents_disconnection_time> and <agents_disconnection_alert_time>1h</agents_disconnection_alert_time>. The second value means an alert one hour after the agent is treated as disconnected.

Intervals on the agent side

notify_time in the agent <client> block is the number of seconds between agent check-ins with the manager. The default is 20. More frequent check-ins speed up the distribution of an updated agent.conf, but with many agents they can overload the manager.

time-reconnect is the number of seconds before a reconnection attempt. The default is 60. The documentation gives an example: with notify_time equal to 60 and time-reconnect equal to 300, the agent checks in once a minute. After a failed check-in it waits five minutes before the next attempt, and after a successful connection it returns to the one-minute interval.

<client>
  <!-- Values from the documentation example: check in every minute, retry after five minutes -->
  <notify_time>60</notify_time>
  <time-reconnect>300</time-reconnect>
</client>

Default values on a timeline

StepParameterSideDefault value
Agent check-innotify_timeAgent20 s
Retry after a failed check-intime-reconnectAgent60 s
Agent treated as disconnected since the last keepaliveagents_disconnection_timeManager15m
Alert from the moment of being treated as disconnectedagents_disconnection_alert_timeManager0s
Minimum window to an alert with default valuesValue given in the documentationManager15m

Relations required by the documentation: notify_time smaller than agents_disconnection_time, and time-reconnect greater than notify_time.

Status in the dashboard, CLI and API

In the Wazuh dashboard, the Agents management > Summary view shows the Endpoints list with each agent status and the counters Active, Disconnected, Pending and Never connected.

On the Wazuh server, /var/ossec/bin/agent_control -i shows the status of one agent, and /var/ossec/bin/agent_control -l lists all agents:

# Status of one agent, for example "Status:     Active"
/var/ossec/bin/agent_control -i <WAZUH_AGENT_ID> | grep Status

# All agents with their status
/var/ossec/bin/agent_control -l

The Wazuh server API returns agent statistics:

GET /agents/<WAZUH_AGENT_ID>/stats/agent
Response fieldExample in the documentation
statusconnected
last_keepaliveTimestamp
last_ackTimestamp
msg_countNumber
msg_sentNumber
msg_bufferNumber
buffer_enabledtrue

The agent event buffer and the anti-flooding mechanism are covered in the article on the agent buffer.

Local agent state file

The agent writes its own view of the connection to a state file. The file is created when the agent first connects to the manager and is updated every 5 seconds by default. The agent.state_interval value in the internal configuration file changes the interval.

SystemState fileAgent log
Linux/var/ossec/var/run/wazuh-agentd.state/var/ossec/logs/ossec.log
WindowsC:\Program Files (x86)\ossec-agent\wazuh-agent.stateC:\Program Files (x86)\ossec-agent\ossec.log
macOS/Library/Ossec/var/run/wazuh-agentd.state/Library/Ossec/logs/ossec.log

Field descriptions from the state file documentation:

FieldMeaning
statuspending, connected or disconnected
last_keepaliveLast keepalive sent
last_ackLast control message received
msg_countNumber of events generated
msg_sentNumber of messages (events and control messages) sent to the manager
msg_bufferNumber of events in the buffer, empty when anti-flooding is disabled

The agent connection page describes the status values like this: pending is waiting for connection confirmation from the manager, disconnected is no confirmation in the last 60 seconds or a lost connection, and connected is a received confirmation. A comment in the example state file describes connected as a connection to the manager established in the last 10 seconds. Reading it on Linux:

sudo grep ^status /var/ossec/var/run/wazuh-agentd.state
# status='connected'

Network connectivity and groups

The agent needs an outbound connection to the manager, by default on port 1514/TCP. The documentation gives a check command for each system:

# Linux
netstat -vatunp|grep wazuh-agentd

# macOS
lsof -i -P | grep ESTABLISHED | grep 1514
# Windows
Get-NetTCPConnection -RemotePort 1514

Group configuration synchronization is checked with agent_groups or the API. The documentation example for agent 001:

/var/ossec/bin/agent_groups -S -i 001
# Agent '001' is synchronized.
GET /agents?agents_list=001&select=group_config_status

The API response contains "group_config_status": "synced". The procedure for adding agents itself is covered in the article on agent enrollment.

Agent data in wazuh-db

According to the documentation, the Wazuh core uses list-based databases to store information about agent keys and FIM and Rootcheck event data. Each agent has a database named after the ID under which it is registered on the manager. The daemon accepts the options -d (debug), -dd (verbose debug), -f (run in the foreground), -h, -V and -t (configuration test).

The agent database tables are fim_entry, sync_info, scan_info, metadata, pm_event and the Syscollector tables. A separate tasks table stores tasks.

  • sync_info describes synchronization between the agent and manager databases. Fields: component (for example fim), last_attempt, last_completion, n_attempts, n_completions.
  • metadata stores key and value pairs, for example db_version. Keys can also be last_vacuum_time and last_vacuum_value, the fragmentation left after the last vacuum.
  • pm_event stores Rootcheck results, one row per distinct result. When a result repeats, date_last is updated, and date_first holds the time the result was first reported.
Syscollector tableContents according to the documentation
sys_hwinfoSystem hardware
sys_netifaceNetwork interfaces
sys_netaddrIPv4 and IPv6 addresses of interfaces
sys_netprotoRouting configuration for each interface
sys_osinfoOperating system
sys_portsOpen ports
sys_processesRunning processes
sys_programsInstalled packages
sys_hotfixesWindows updates installed on the agent
sys_usersUser accounts
sys_groupsUser account groups
sys_servicesServices
sys_browser_extensionsBrowser extensions

The <wdb> block in ossec.conf configures the global database backup. The backup option takes a database attribute with the only allowed value global. enabled defaults to yes, interval to 1d (units s, m, h, d), and max_files to 3. After max_files is exceeded, the oldest file is deleted. The documentation example makes a copy of global.db once a day and keeps at most three files:

<wdb>
  <backup database='global'>
    <enabled>yes</enabled>
    <interval>1d</interval>
    <max_files>3</max_files>
  </backup>
</wdb>

What the documentation does not specify

The documentation gives no rule ID or alert text for the alert triggered by agents_disconnection_alert_time. It gives no paths for the global database, agent databases or backups. It does not describe what happens to agent data in wazuh-db while the agent is disconnected. Beyond the requirement that notify_time be smaller than agents_disconnection_time, it does not explain the exact relation between a check-in and a keepalive. It also does not link the 60 and 10 second thresholds from the local state file to the manager threshold, and it gives no rule that derives the cause of a disconnection from last_keepalive and last_ack.

Sources

↑↓ select Enter open Esc close