itemprototype.create

描述

object itemprototype.create(object/array itemPrototypes)

该方法允许创建新的监控项原型。

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

参数

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

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

参数 数据类型 说明
ruleid
(required)
string 所属LLD规则的ID
preprocessing array 监控项原型监控项-原型预处理选项
tags array 监控项原型监控项-原型标签

返回值

(object) 返回一个包含所创建itemids属性下监控项原型ID的object。返回的ID顺序与传入的监控项原型顺序一致。

示例

创建 监控项 原型

创建一个监控项原型用于监控已发现文件系统的剩余磁盘空间。发现的监控项应为数值型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",
           "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"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "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
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

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

创建 HTTP agent 监控项 原型

使用用户宏、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",
           "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 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
       }

响应:

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

CItemPrototype::create() 方法位于 ui/include/classes/api/services/CItemPrototype.php 文件中。