itemprototype.create

描述

object itemprototype.create(object/array itemPrototypes)

此方法允许create新的监控项原型。

此方法仅适用于管理员超级管理员用户类型。可以在用户角色设置中撤销调用该方法的权限。更多信息请参见User roles

参数

(object/array) 监控项 原型以创建。

除了 监控项原型 外,该方法还接受以下参数。

参数 数据类型 描述
ruleid ID lld规则 的 ID,监控项 所属的监控项。

参数行为:
- 必填
preprocessing array 监控项-原型预处理 选项。
tags array 监控项-原型标签

返回值

(object) 返回一个 object,其中包含创建的 监控项 原型的 ID,这些 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"
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "27666"
               ]
           },
           "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"
                   }
               ]
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "44211"
               ]
           },
           "id": 1
       }

创建依赖的 监控项 原型

为主ID为44211的主监控项原型创建依赖监控项原型。 仅允许依赖同一主机(模板/发现规则) 因此主节点和从属节点的监控项应具有相同的hostid和ruleid。

执行请求:

{
           "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
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "44212"
               ]
           },
           "id": 1
       }

创建 HTTP agent 监控项 原型

使用用户宏、监控项 字段和自定义头创建 query 原型。

执行请求:

{
           "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": [
                   {
                       "name": "min",
                       "value": "10"
                   },
                   {
                       "name": "max",
                       "value" "100"
                   }
               ],
               "headers": [
                   {
                       "name": "X-Source",
                       "value": "api"
                   }
               ],
               "delay": "35"
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "28305"
               ]
           },
           "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 HttpRequest();\nreturn request.post(\"https://postman-echo.com/post\", JSON.parse(value));",
               "parameters": [
                   {
                       "name": "host",
                       "value": "{HOST.CONN}"
                   }
               ],
               "timeout": "6s",
               "delay": "30s"
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "23865"
               ]
           },
           "id": 1
       }

来源

CItemPrototype::create() 在 ui/include/classes/api/services/CItemPrototype.php 中。