object itemprototype.create(object/array itemPrototypes)
该方法允许create新的监控项原型.
此方法仅适用于管理员和超级管理员 用户类型。调用该方法的权限可以在用户角色 设置中撤销。更多信息请参阅User roles
(object/array)
监控项原型到create.
除了监控项原型之外,该方法还接受以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
ruleid (required) |
string | 该监控项所属的LLD规则ID。 |
preprocessing | array | 监控项原型监控项-原型预处理选项。 |
tags | array | 监控项原型监控项-原型标签。 |
(object)
返回一个包含所创建objectID的监控项原型数组,这些ID存储在itemids
属性下。返回的ID顺序与传入的监控项原型顺序保持一致。
创建一个监控项原型用于监控被发现的file系统上的磁盘剩余空间。被发现的监控项应为数值型Zabbix agent 监控项,每30秒更新一次。
请求:
{
"jsonrpc": "2.0",
"method": "itemprototype.create",
"params": {
"name": "Free disk space on {#FSNAME}",
"key_": "vfs.fs.size[{#FSNAME},free]",
"hostid": "10197",
"ruleid": "27665",
"type": 0,
"value_type": 3,
"interfaceid": "112",
"delay": "30s"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
使用每秒变化值和自定义乘数作为第二步创建监控项.
请求:
{
"jsonrpc": "2.0",
"method": "itemprototype.create",
"params": {
"name": "Incoming network traffic on {#IFNAME}",
"key_": "net.if.in[{#IFNAME}]",
"hostid": "10001",
"ruleid": "27665",
"type": 0,
"value_type": 3,
"delay": "60s",
"units": "bps",
"interfaceid": "1155",
"preprocessing": [
{
"type": 10,
"params": "",
"error_handler": 0,
"error_handler_params": ""
},
{
"type": 1,
"params": "8",
"error_handler": 2,
"error_handler_params": "10"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
为ID为44211的主监控项原型创建依赖监控项原型 仅允许对同一主机(模板/发现规则)的依赖关系 因此主节点和从属节点的监控项应具有相同的主机ID和规则ID。
请求:
{
"jsonrpc": "2.0",
"method": "itemprototype.create",
"params": {
"hostid": "10001",
"ruleid": "27665",
"name": "Dependent test item prototype",
"key_": "dependent.prototype",
"type": 18,
"master_itemid": "44211",
"value_type": 3
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应
使用用户宏、query字段和自定义头部创建带URL的监控项原型
请求:
{
"jsonrpc": "2.0",
"method": "itemprototype.create",
"params": {
"type": "19",
"hostid": "10254",
"ruleid": "28256",
"interfaceid": "2",
"name": "api item prototype example",
"key_": "api_http_item",
"value_type": 3,
"url": "{$URL_PROTOTYPE}",
"query_fields": [
{
"min": "10"
},
{
"max": "100"
}
],
"headers": {
"X-Source": "api"
},
"delay": "35"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
使用脚本监控项原型创建一个简单的数据收集。
请求:
{
"jsonrpc": "2.0",
"method": "itemprototype.create",
"params": {
"name": "Script example",
"key_": "custom.script.itemprototype",
"hostid": "12345",
"type": 21,
"value_type": 4,
"params": "var request = new CurlHttpRequest();\nreturn request.Post(\"https://postman-echo.com/post\", JSON.parse(value));",
"parameters": [
{
"name": "host",
"value": "{HOST.CONN}"
}
],
"timeout": "6s",
"delay": "30s"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 2
}
响应:
CItemPrototype::create() 位于 ui/include/classes/api/services/CItemPrototype.php 文件中.