2 Passive and active agent checks

Overview

This section provides details on passive and active checks performed by Zabbix agent.

Zabbix uses a JSON based communication protocol for communicating with Zabbix agent.

See also: Zabbix agent 2 protocol details.

Passive checks

A passive check is a simple data request. Zabbix server or proxy asks for some data (for example, CPU load) and Zabbix agent sends back the result to the server.

Server request

For definition of header and data length please refer to protocol details.

  1. <item key>

Agent response

  1. <DATA>[\0<ERROR>]

Above, the part in square brackets is optional and is only sent for not supported items.

For example, for supported items:

  1. Server opens a TCP connection
  2. Server sends <HEADER><DATALEN>agent.ping
  3. Agent reads the request and responds with <HEADER><DATALEN>1
  4. Server processes data to get the value, ‘1’ in our case
  5. TCP connection is closed

For not supported items:

  1. Server opens a TCP connection
  2. Server sends <HEADER><DATALEN>vfs.fs.size[/nono]
  3. Agent reads the request and responds with <HEADER><DATALEN>ZBX_NOTSUPPORTED\0Cannot obtain filesystem information: [2] No such file or directory
  4. Server processes data, changes item state to not supported with the specified error message
  5. TCP connection is closed

Active checks

Active checks require more complex processing. The agent must first retrieve from the server(s) a list of items for independent processing.

The servers to get the active checks from are listed in the ‘ServerActive’ parameter of the agent configuration file. The frequency of asking for these checks is set by the ‘RefreshActiveChecks’ parameter in the same configuration file. However, if refreshing active checks fails, it is retried after hardcoded 60 seconds.

In order to decrease network traffic and resources usage Zabbix server or Zabbix proxy will provide configuration only if Zabbix agent still hasn’t received configuration or if something has changed in host configuration, global macros or global regular expressions.

The agent then periodically sends the new values to the server(s).

If an agent is behind the firewall you might consider using only Active checks because in this case you wouldn’t need to modify the firewall to allow initial incoming connections.

Getting the list of items

Agent request

The active checks request is used to obtain the active checks to be processed by agent. This request is sent by the agent upon start and then with RefreshActiveChecks intervals.

  1. {
  2. "request": "active checks",
  3. "host": "Zabbix server",
  4. "host_metadata": "mysql,nginx",
  5. "hostinterface": "zabbix.server.lan",
  6. "ip": "159.168.1.1",
  7. "port": 12050,
  8. "config_revision": 1,
  9. "session": "e3dcbd9ace2c9694e1d7bbd030eeef6e"
  10. }
FieldTypeMandatoryValue
requeststringyesactive checks
hoststringyesHost name.
host_metadatastringnoThe configuration parameter HostMetadata or HostMetadataItem metric value.
hostinterfacestringnoThe configuration parameter HostInterface or HostInterfaceItem metric value.
ipstringnoThe configuration parameter ListenIP first IP if set.
portnumbernoThe configuration parameter ListenPort value if set and not default agent listening port.
config_revisionnumbernoConfiguration identifier for incremental configuration sync.
sessionstringnoSession identifier for incremental configuration sync.

Server response

The active checks response is sent by the server back to agent after processing the active checks request.

  1. {
  2. "response": "success",
  3. "data": [
  4. {
  5. "key": "log[/home/zabbix/logs/zabbix_agentd.log]",
  6. "key_orig": "log[/home/zabbix/logs/zabbix_agentd.log]",
  7. "itemid": 1234,
  8. "delay": "30s",
  9. "lastlogsize": 0,
  10. "mtime": 0
  11. },
  12. {
  13. "key": "agent.version",
  14. "key_orig": "agent.version",
  15. "itemid": 5678,
  16. "delay": "10m",
  17. "lastlogsize": 0,
  18. "mtime": 0
  19. }
  20. ],
  21. "config_revision": 2
  22. }
FieldTypeMandatoryValue
responsestringyessuccess | failed
infostringnoError information in the case of failure.
dataarray of objectsnoActive check items. Omitted if host configuration is unchanged.
keystringnoItem key with expanded macros.
key_origstringnoItem key without expanded macros.
itemidnumbernoItem identifier.
delaystringnoItem update interval.
lastlogsizenumbernoItem lastlogsize.
mtimenumbernoItem mtime.
refresh_unsupportednumbernoUnsupported item refresh interval.
regexparray of objectsnoGlobal regular expressions.
namestringnoGlobal regular expression name.
expressionstringnoGlobal regular expression.
expression_typenumbernoGlobal regular expression type.
exp_delimiterstringnoGlobal regular expression delimiter.
case_sensitivenumbernoGlobal regular expression case sensitiviness setting.
config_revisionnumbernoConfiguration identifier for incremental configuration sync. Omitted if host configuration is unchanged. Incremented if host configuration is changed.

The server must respond with success.

For example:

  1. Agent opens a TCP connection
  2. Agent asks for the list of checks
  3. Server responds with a list of items (item key, delay)
  4. Agent parses the response
  5. TCP connection is closed
  6. Agent starts periodical collection of data

Note that (sensitive) configuration data may become available to parties having access to the Zabbix server trapper port when using an active check. This is possible because anyone may pretend to be an active agent and request item configuration data; authentication does not take place unless you use encryption options.

Sending in collected data

Agent sends

The agent data request contains the gathered item values.

  1. {
  2. "request": "agent data",
  3. "data": [
  4. {
  5. "host": "Zabbix server",
  6. "key": "agent.version",
  7. "value": "2.4.0",
  8. "clock": 1400675595,
  9. "ns": 76808644
  10. },
  11. {
  12. "host": "Zabbix server",
  13. "key": "log[/home/zabbix/logs/zabbix_agentd.log]",
  14. "lastlogsize": 112,
  15. "value": " 19845:20140621:141708.521 Starting Zabbix Agent [<hostname>]. Zabbix 2.4.0 (revision 50000).",
  16. "clock": 1400675595,
  17. "ns": 77053975
  18. }
  19. ],
  20. "session": "1234456akdsjhfoui"
  21. }
FieldTypeMandatoryValue
requeststringyesagent data
sessionstringyesUnique session identifier generated each time when agent is started.
dataarray of objectsyesItem values.
idnumberyesThe value identifier (incremental counter used for checking duplicated values in the case of network problems).
hoststringyesHost name.
keystringyesThe item key.
valuestringnoThe item value.
lastlogsizenumbernoThe item lastlogsize.
mtimenumbernoThe item mtime.
statenumbernoThe item state.
sourcestringnoThe value event log source.
eventidnumbernoThe value event log eventid.
severitynumbernoThe value event log severity.
timestampnumbernoThe value event log timestamp.
clocknumberyesThe value timestamp (seconds since Epoch).
nsnumberyesThe value timestamp nanoseconds.

A virtual ID is assigned to each value. Value ID is a simple ascending counter, unique within one data session (identified by the session token). This ID is used to discard duplicate values that might be sent in poor connectivity environments.

Server response

The agent data response is sent by the server back to agent after processing the agent data request.

  1. {
  2. "response": "success",
  3. "info": "processed: 2; failed: 0; total: 2; seconds spent: 0.003534"
  4. }
FieldTypeMandatoryValue
responsestringyessuccess | failed
infostringyesItem processing results.

If sending of some values fails on the server (for example, because host or item has been disabled or deleted), agent will not retry sending of those values.

For example:

  1. Agent opens a TCP connection
  2. Agent sends a list of values
  3. Server processes the data and sends the status back
  4. TCP connection is closed

Note how in the example above the not supported status for vfs.fs.size[/nono] is indicated by the “state” value of 1 and the error message in “value” property.

Error message will be trimmed to 2048 symbols on server side.

Heartbeat message

The heartbeat message is sent by an active agent to Zabbix server/proxy every HeartbeatFrequency seconds (configured in the Zabbix agent configuration file).

It is used to monitor the availability of active checks.

  1. {
  2. "request": "active check heartbeat",
  3. "host": "Zabbix server",
  4. "heartbeat_freq": 60
  5. }
FieldTypeMandatoryValue
requeststringyesactive check heartbeat
hoststringyesThe host name.
heartbeat_freqnumberyesThe agent heartbeat frequency (HeartbeatFrequency configuration parameter).

Older XML protocol

Zabbix will take up to 16 MB of XML Base64-encoded data, but a single decoded value should be no longer than 64 KB otherwise it will be truncated to 64 KB while decoding.