On this page
Zabbix agent 2 插件协议
Zabbix agent 2 协议基于代码、大小和数据模型。
代码
| Type | Size | Comments |
|---|---|---|
| Byte | 4 | 有效负载类型,目前仅支持 JSON。 |
大小
| Type | Size | Comments |
|---|---|---|
| Byte | 4 | 当前有效负载的字节大小。 |
负载数据
| Type | Size | Comments |
|---|---|---|
| Byte | 由 Size 字段定义 | JSON 格式的数据。 |
负载数据定义
通用数据
以下参数存在于所有请求/响应中:
| Name | Type | Comments |
|---|---|---|
| id | uint32 | 对于请求 - 用于将请求与响应关联起来的递增标识符。在单个请求方向内唯一(即从 agent 到插件,或从插件到 agent)。 对于响应 - 对应请求的 ID。 |
| type | uint32 | 请求类型。 |
日志请求
由插件发送的请求,用于将日志消息写入 agent 日志文件。
| direction | plugin → agent |
| response | no |
日志请求特有的参数:
| Name | Type | Comments |
|---|---|---|
| severity | uint32 | 消息严重级别(日志级别)。 |
| message | string | 要记录的消息。 |
示例:
{"id":0,"type":1,"severity":3,"message":"message"}
注册请求
agent 在启动阶段发送的请求,用于获取所提供的监控项并注册插件。
| direction | agent → plugin |
| response | yes |
注册请求特有的参数:
| Name | Type | Comments |
|---|---|---|
| version | string | 协议版本 <major>.<minor> |
示例:
{"id":1,"type":2,"version":"1.0"}
注册响应
插件对注册请求的响应。
| direction | plugin → agent |
| response | n/a |
注册响应特有的参数:
| Name | Type | Comments |
|---|---|---|
| name | string | 插件名称。 |
| metrics | array of strings (optional) | 插件中使用的带描述的监控项。返回 RegisterMetrics()。如果返回错误,则不存在。 |
| interfaces | uint32 (optional) | 插件支持的接口位掩码。如果返回错误,则不存在。 |
| error | string (optional) | 如果插件无法启动,则返回的错误消息。如果返回监控项,则不存在。 |
示例:
{"id":2,"type":3,"metrics":["external.test", "External exporter Test."], "interfaces": 4}
或
{"id":2,"type":3,"error":"error message"}
启动请求
用于执行 Runner 接口的 Start 函数的请求。
| direction | agent → plugin |
| response | no |
该请求没有特定参数,只包含 common data 参数。
示例:
{"id":3,"type":4}
终止请求
由 agent 发送给插件以关闭插件的请求。
| direction | agent → plugin |
| response | no |
该请求没有特定参数,只包含 common data 参数。
示例:
{"id":3,"type":5}
导出请求
用于执行 Exporter 接口的 Export 函数的请求。
| direction | agent → plugin |
| response | no |
导出请求特有的参数:
| Name | Type | Comments |
|---|---|---|
| key | string | 插件键。 |
| parameters | array of strings (optional) | Export 函数的参数。 |
示例:
{"id":4,"type":6,"key":"test.key","parameters":["foo","bar"]}
导出响应
来自 Exporter 接口的 Export 函数的响应。
| direction | plugin → agent |
| response | n/a |
导出响应特有的参数:
| Name | Type | Comments |
|---|---|---|
| value | string (optional) | 来自 Export 函数的响应值。如果返回错误,则不存在。 |
| error | string (optional) | 如果 Export 函数未成功执行,则为错误消息。如果返回 value,则不存在。 |
示例:
{"id":5,"type":7,"value":"response"}
或
{"id":5,"type":7,"error":"error message"}
配置请求
用于执行 Configurator 接口的 Configure 函数的请求。
| direction | agent → plugin |
| response | n/a |
Configure 请求的特定参数:
| Name | Type | Comments |
|---|---|---|
| global_options | JSON object | 包含全局 agent 配置选项的 JSON 对象。 |
| private_options | JSON object (optional) | 包含私有插件配置选项的 JSON 对象(如果提供)。 |
示例:
{"id":6,"type":8,"global_options":{...},"private_options":{...}}
验证请求
用于执行 Configurator 接口的 Validate 函数的请求。
| direction | agent → plugin |
| response | yes |
Validate 请求的特定参数:
| Name | Type | Comments |
|---|---|---|
| private_options | JSON object (optional) | 包含私有插件配置选项的 JSON 对象(如果提供)。 |
示例:
{"id":7,"type":9,"private_options":{...}}
验证响应
来自 Configurator 接口的 Validate 函数的响应。
| direction | plugin → agent |
| response | n/a |
Validate 响应特有的参数:
| Name | Type | Comments |
|---|---|---|
| error | string (optional) | 如果 Validate 函数未成功执行,则返回的错误消息。若执行成功,则不存在。 |
示例:
{"id":8,"type":10}
或
{"id":8,"type":10,"error":"error message"}