这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

3 Zabbix agent 2 protocol

概览

本节提供有关信息:

  • · Agent2 -> Server : 主动检查请求

  • · Server -> Agent2 : 主动检查响应

  • · Agent2 -> Server : 代理数据请求

  • · Server -> Agent2 : 代理数据响应

主动检查请求

主动检查请求用于获取agent要处理的主动检查。 此请求由agent在启动时发送,然后以 RefreshActiveChecks 间隔发送。

字段 类型 必填
request 字符串 主动检查
host 字符串 主机名。
version 字符串 agent版本:<major>.<minor>。
host_metadata 字符串 没有 配置参数 HostMetadata 或 HostMetadataItem 度量值。
interface 字符串 没有 配置参数 HostInterface 或 HostInterfaceItem 度量值。
ip 字符串 没有 如果设置了配置参数 ListenIP 第一个 IP。
port 编号 没有 配置参数 ListenPort 值(如果已设置)而不是默认监听端口。

示例:

{
        · "request": "active checks",
        · "host": "Zabbix server",
        · "version": "6.0",
        · "host_metadata": "mysql,nginx",
        · "hostinterface": "zabbix.server.lan",
        · "ip": "159.168.1.1",
        · "port": 12050
       }

主动检查响应

在处理主动检查请求后,主动检查响应由服务器发送回agent。

字段 类型 必填
response 字符串 成功| 失败
info 字符串 没有 失败时的错误信息。
data 对象数组 没有 活动检查监控项。
key 字符串 没有 带有扩展宏的监控项键。
itemid 数字 没有 监控项标识符。
delay 字符串 没有 监控项更新间隔。
lastlogsize 数字 没有 监控项 lastlogsize。
mtime 数字 没有 监控项mtime。
regexp 对象数组 没有 全局正则表达式。
name 字符串 没有 全局正则表达式名称。
expression 字符串 没有 全局正则表达式。
expression_type 数字 没有 全局正则表达式类型。
exp_delimiter 字符串 没有 全局正则表达式分隔符。
case_sensitive 编号 没有 全局正则表达式区分大小写设置。

例子:

{
        · "response": "success",
        · "data": [
        · {
        · "key": "log[/home/zabbix/logs/zabbix_agentd.log]",
        · "itemid": 1234,
        · "delay": "30s",
        · "lastlogsize": 0,
        · "mtime": 0
        · },
        · {
        · "key": "agent.version",
        · "itemid": 5678,
        · "delay": "10m",
        · "lastlogsize": 0,
        · "mtime": 0
        · }
        · ]
       }

Agent数据请求

Agent数据请求包含收集的监控项值。

字段 类型 必填
request 字符串 agent数据
host 字符串 主机名。
version 字符串 agent版本:<major>.<minor>。
session 字符串 每次启动agent时生成的唯一会话标识符。
data 对象数组 监控项值。
id 数字 值标识符(用于在出现网络问题时检查重复值的增量计数器)。
itemid 数字 监控项标识符。
value 字符串 物品价值。
lastlogsize 数字 该监控项最后日志大小。
mtime 数字 监控项时间。
state 数字 监控项状态。
source 字符串 事件日志源。
eventid 数字 事件日志eventid。
severity 数字 事件日志严重性。
timestamp 数字 事件日志时间戳。
clock 数字 时间戳(自纪元以来的秒数)。
ns 数字 时间戳纳秒。

示例:

{
        · "request": "agent data",
        · "data": [
        · {
        · "id": 1,
        · "itemid": 5678,
        · "value": "2.4.0",
        · "clock": 1400675595,
        · "ns": 76808644
        · },
        · {
        · "id": 2,
        · "itemid": 1234,
        · "lastlogsize": 112,
        · "value": " 19845:20140621:141708.521 Starting Zabbix Agent [<hostname>]. Zabbix 2.4.0 (revision 50000).",
        · "clock": 1400675595,
        · "ns": 77053975
        · }
        · ],
        · "host": "Zabbix server",
        · "version": "6.0",
        · "session": "1234456akdsjhfoui"
       }

Agent数据响应

agent数据响应在处理agent数据请求后由服务器发送回agent。

字段 类型 必填
response 字符串 成功| 失败
info 字符串 监控项处理结果。

例子:

{
        · "response": "success",
        · "info": "processed: 2; failed: 0; total: 2; seconds spent: 0.003534"
       }

Heartbeat message

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

It is used to monitor the availability of active checks.

{
         "request": "active check heartbeat",
         "host": "Zabbix server",
         "heartbeat_freq": 60
       }
Field Type Mandatory Value
request string yes active check heartbeat
host string yes The host name.
heartbeat_freq number yes The agent heartbeat frequency (HeartbeatFrequency configuration parameter).