object itemprototype.create(object/array itemPrototypes)
此方法允许create新的监控项原型.
此方法仅适用于管理员和超级管理员 用户类型. 调用该方法的权限可以在用户角色 设置中撤销. 更多信息请参阅User roles.
(object/array) 监控项 原型到 create.
除了 监控项原型 之外,该方法还接受以下参数。
| 参数 | 数据类型 | 描述 | 
|---|---|---|
| ruleid | ID | 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"
           },
           "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
       }响应:
为主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
       }响应
使用用户宏、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": [
                   {
                       "name": "min",
                       "value": "10"
                   },
                   {
                       "name": "max",
                       "value" "100"
                   }
               ],
               "headers": [
                   {
                       "name": "X-Source",
                       "value": "api"
                   }
               ],
               "delay": "35"
           },
           "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
       }响应:
CItemPrototype::create() 位于 ui/include/classes/api/services/CItemPrototype.php 文件中.