[comment]: # translation:outdated

[comment]: # ({0e4c7681-0ea9fa0f})
# 3 Zabbix agent 2 协议

[comment]: # ({/0e4c7681-0ea9fa0f})

[comment]: # ({34adf2a8-e87a981b})


### 概述

本节提供以下信息:

*   Agent2 -> 服务器 : 主动检查请求
*   服务器 -> Agent2 : 主动检查响应

*   Agent2 -> 服务器 : agent 数据请求
*   服务器 -> Agent2 : agent 数据响应

[comment]: # ({/34adf2a8-e87a981b})

[comment]: # ({420faeae-1c996373})


### 主动检查请求

主动检查请求用于获取由agent处理的主动检查项。该请求由agent在启动时发送，随后按*RefreshActiveChecks*间隔定期发送。

| 字段 | 类型 | 必填 | 值 |
|-|-|-|--------|
| request | _string_ | yes | `active checks` |
| host | _string_ | yes | 主机名. |
| version | _string_ | yes | agent的version版本: \<主版本>.\<次版本>. |
| host_metadata | _string_ | no | 配置参数HostMetadata或HostMetadataItem的指标值。 |
| interface | _string_ | no | 配置参数HostInterface或HostInterfaceItem的指标值。 |
| ip | _string_ | no | 若设置则返回配置参数ListenIP的第一个IP地址。 |
| port | _number_ | no | 若设置且非默认agent监听端口，则返回配置参数ListenPort的值。 |

示例:

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

[comment]: # ({/420faeae-1c996373})

[comment]: # ({c6796ce2-44da8f0a})


### 主动检查响应

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

| 字段 | <   | 类型 | 必填 | 值 |
|-|------|--|-|-----------------------|
| response | <   | _string_ | yes | `success` \ | `failed` |
| info | <   | _string_ | no | 失败时的错误信息. |
| data | <   | _array of objects_ | no | 主动检查监控项. |
|       | key | _string_ | no | 带扩展宏的监控项键值. |
| ^ | itemid | _number_ | no | 监控项标识符. |
| ^ | delay | _string_ | no | 监控项update间隔. |
| ^ | lastlogsize | _number_ | no | 监控项lastlogsize. |
| ^ | mtime | _number_ | no | 监控项mtime. |
| regexp | <   | _array of objects_ | no | 全局正则表达式. |
|       | name | _string_ | no | 全局正则表达式名称. |
| ^ | expression | _string_ | no | 全局正则表达式. |
| ^ | expression_type | _number_ | no | 全局正则表达式类型. |
| ^ | exp_delimiter | _string_ | no | 全局正则表达式分隔符. |
| ^ | case_sensitive | _number_ | no | 全局正则表达式大小写敏感设置. |

示例:

```json
{
  "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
    }
  ]
}
```

[comment]: # ({/c6796ce2-44da8f0a})

[comment]: # ({6e86f730-8a564dbc})


### Agent 数据请求

agent数据请求包含收集的监控项值.

| 字段 | <   | 类型 | 必填 | 值 |
|-|------|--|-|-----------------------|
| request | <   | _string_ | yes | `agent data` |
| host | <   | _string_ | yes | 主机名. |
| version | <   | _string_ | yes | agentversion: \<major>.\<minor>. |
| session | <   | _string_ | yes | 每次启动agent时生成的唯一会话标识符. |
| data | <   | _array of objects_ | yes | 监控项值. |
|       | id  | _number_ | yes | 值标识符(用于在网络问题情况下检查重复值的递增计数器). |
| ^ | itemid | _number_ | yes | 监控项标识符. |
| ^ | value | _string_ | no | 监控项值. |
| ^ | lastlogsize | _number_ | no | 监控项lastlogsize. |
| ^ | mtime | _number_ | no | 监控项mtime. |
| ^ | state | _number_ | no | 监控项状态. |
| ^ | source | _string_ | no | 值事件日志来源. |
| ^ | eventid | _number_ | no | 值事件日志eventid. |
| ^ | severity | _number_ | no | 值事件日志严重级别. |
| ^ | timestamp | _number_ | no | 值事件日志时间戳. |
| ^ | clock | _number_ | yes | 值时间戳(自Epoch起的秒数). |
| ^ | ns  | _number_ | yes | 值时间戳纳秒部分. |

示例:

```json
{
  "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"
}
```

[comment]: # ({/6e86f730-8a564dbc})

[comment]: # ({a61e102f-b302d014})


### Agent 数据响应

服务器在处理完agent数据请求后，会将agent数据响应发送回agent。

| 字段 | 类型 | 必填 | 值 |
|-|-|-|--------|
| response | _string_ | yes | `success` \ | `failed` |
| info | _string_ | yes | 监控项处理结果。 |

示例:

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

[comment]: # ({/a61e102f-b302d014})
