[comment]: # ({f372a49b-bdae00e2})
# 4 Zabbix agent 2 插件协议

Zabbix Agent 2协议基于代码、大小和数据模型。

[comment]: # ({/f372a49b-bdae00e2})

[comment]: # ({b65bf947-a102065d})

### 代码

|类型|大小|注解|
|-----|-----|----------|
|Byte|	4	|Payload类型，目前仅支持JSON.|

[comment]: # ({/b65bf947-a102065d})

[comment]: # ({8edb0275-6f328f94})

### 大小

|类型|大小|注解|
|-----|-----|----------|
|Byte|	4	|当前有效负载的大小（以字节为单位）.|

[comment]: # ({/8edb0275-6f328f94})

[comment]: # ({0351e98f-e3974519})

### Payload数据

|类型|大小|注解|
|-----|-----|----------|
|Byte|	由 *Size* 字段定义	|JSON 格式的数据.|

[comment]: # ({/0351e98f-e3974519})

[comment]: # ({60a41fe8-265b88ca})
##### Payload 数据定义

###### 常用数据

这些参数存在于所有请求/响应中:

|名称|类型|注解|
|-----|--------|----------|
|id	  |uint32|对于请求 - 用于将请求与响应链接起来的递增标识符。在请求方向内唯一 (即从代理到插件或从插件到代理).<br>对于响应 - 相应请求的 ID.|
|type|uint32|请求类型.|

[comment]: # ({/60a41fe8-265b88ca})

[comment]: # ({3cf942f4-6bdfbea5})

###### 日志请求

插件发送的将日志消息写入代理日志文件的请求。

|   |   |
|---|---|
|direction|plugin → agent|
|response|no|

特定于日志请求的参数:

|名称|类型|注解|
|---------|--------|----------|
|severity|uint32|消息严重性（日志级别）.|
|message|string|要记录的消息.|

*例子:*

    {"id":0,"type":1,"severity":3,"message":"message"}

[comment]: # ({/3cf942f4-6bdfbea5})

[comment]: # ({3640b089-38f1c088})

###### 注册请求

代理在代理启动阶段发送的请求，用于获取注册插件所提供的指标。

|   |   |
|---|---|
|direction|agent → plugin|
|response|yes|

特定于注册请求的参数:

|名称|类型|注解|
|---------|--------|----------|
|version|string|协议版本 <major>.<minor>|

*例子:*

    {"id":1,"type":2,"version":"1.0"}

[comment]: # ({/3640b089-38f1c088})

[comment]: # ({92946a86-d8c62312})

###### 注册响应
插件对注册请求的响应。

|   |   |
|---|---|
|direction|plugin → agent|
|response|n/a|

特定于注册响应的参数:

|Name|Type|Comments|
|---------|--------|----------|
|name|string|插件名称.|
|metrics|array of strings (可选)|带有插件中使用的描述的指标。返回 RegisterMetrics()。如果返回错误则不存在.|
|interfaces|uint32 (可选)|插件支持的接口的掩码位。如果返回错误则不存在.|
|error|string (可选)|如果插件无法启动，则返回错误消息。如果返回指标，则不存在.|

*例子:*

    {"id":2,"type":3,"metrics":["external.test", "External exporter Test."], "interfaces": 4}

or

    {"id":2,"type":3,"error":"error message"}

[comment]: # ({/92946a86-d8c62312})

[comment]: # ({f190dd1a-0b67f229})

###### 开始请求

请求执行Runner接口的Start函数.

|   |   |
|---|---|
|direction|agent → plugin|
|response|no|

该请求没有具体参数, 它只包含 [常用数据](#常用数据) 参数。

*例子:*

    {"id":3,"type":4}

[comment]: # ({/f190dd1a-0b67f229})

[comment]: # ({fce4bba2-f3c8d489})

###### 终止请求

代理发送的关闭插件的请求。

|   |   |
|---|---|
|direction|agent → plugin|
|response|no|

该请求没有具体参数，它只包含 [常用数据](#常用数据) 参数。

*例子:*

    {"id":3,"type":5}

[comment]: # ({/fce4bba2-f3c8d489})

[comment]: # ({43e9416d-b2754963})

###### 导出请求

请求执行Exporter接口的Export函数。

|   |   |
|---|---|
|direction|agent → plugin|
|response|no|

特定于导出请求的参数:

|名称|类型|注解|
|---------|--------|----------|
|key|string|插件密钥.|
|parameters|array of strings (可选)|导出函数的参数.|

*例子:*

    {"id":4,"type":6,"key":"test.key","parameters":["foo","bar"]}

[comment]: # ({/43e9416d-b2754963})

[comment]: # ({33f976c2-27e2bd0c})

###### 导出响应

来自 Exporter 接口的 Export 功能的响应。

|   |   |
|---|---|
|direction|plugin → agent|
|response|n/a|

特定于导出响应的参数:

|名称|类型|注解|
|---------|--------|----------|
|value|string (可选) |来自导出功能的响应值。如果返回错误，则不存在.|
|error|string (可选) |如果导出功能未成功执行，则会出现错误消息。如果返回值，则不存在.|

*例子:*

    {"id":5,"type":7,"value":"response"}

or

    {"id":5,"type":7,"error":"error message"}

[comment]: # ({/33f976c2-27e2bd0c})

[comment]: # ({96eb71cf-15a7dce0})

###### 配置请求

执行 *Configurator* 接口的 *Configure* 功能的请求。

|   |   |
|---|---|
|direction|agent → plugin|
|response|n/a|

特定于*Configure* 请求的参数:

|名称|类型|注解|
|---------|--------|----------|
|global_options|JSON object|包含全局代理配置选项的JSON对象.|
|private_options|JSON object (可选)|包含私有插件配置选项的JSON对象，如果提供.|

*例子:*

    {"id":6,"type":8,"global_options":{...},"private_options":{...}}

[comment]: # ({/96eb71cf-15a7dce0})

[comment]: # ({99291487-14b279bc})

###### 验证请求

执行 *Configurator* 接口的 *Validate* 功能的请求。

|   |   |
|---|---|
|direction|agent → plugin|
|response|yes|

特定于 *Validate* 请求的参数:

|Name|Type|Comments|
|---------|--------|----------|
|private_options|JSON object (可选)|包含私有插件配置选项的 JSON 对象, 如果提供.|

*例子:*

    {"id":7,"type":9,"private_options":{...}}

[comment]: # ({/99291487-14b279bc})

[comment]: # ({3b19fa95-9a73001b})

###### 验证响应

来自 *Configurator* 接口的 *Validate* 函数的响应。

|   |   |
|---|---|
|direction|plugin → agent|
|response|n/a|

特定于 *Validate* 响应的参数:

|Name|Type|Comments|
|---------|--------|----------|
|error|string (可选)|如果 Validate 函数未成功执行，则返回错误消息。如果执行成功则不存在.|

*例子:*

    {"id":8,"type":10}

or

    {"id":8,"type":10,"error":"error message"}

[comment]: # ({/3b19fa95-9a73001b})

[comment]: # translation:outdated

