itemprototype.update

描述

object itemprototype.update(object/array itemPrototypes)

此方法允许update现有的监控项原型.

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

参数

(object/array) 监控项 原型属性将被更新。

itemid 属性必须为每个 监控项 原型定义,所有其他 属性都是可选的。只有传递的属性会被更新,所有 其他属性将保持不变。

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

参数 数据类型 描述
preprocessing array 监控项-原型预处理 选项用于替换当前的预处理选项。

参数行为:
- 只读 用于继承的 objects
tags array 监控项-原型标签.

返回值

(object) 返回一个包含更新后的object ID的监控项原型数组 存储在itemids属性下

示例

修改 监控项 原型的接口

更改将被发现的监控项所使用的主机接口。

执行请求:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.update",
           "params": {
               "itemid": "27428",
               "interfaceid": "132"
           },
           "id": 1
       }

响应:

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

更新依赖的 监控项 原型

使用新的主监控项原型ID更新依赖监控项原型。仅 允许在同一主机(模板/发现规则)上存在依赖关系 因此主节点和从属节点的监控项应具有相同的hostid和ruleid。

执行请求:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.update",
           "params": {
               "master_itemid": "25570",
               "itemid": "189030"
           },
           "id": 1
       }

响应

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

更新 HTTP agent 监控项 原型

修改query字段并移除所有自定义头部

执行请求:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.update",
           "params": {
               "itemid":"28305",
               "query_fields": [
                   {
                       "name": "random",
                       "value": "qwertyuiopasdfghjklzxcvbnm"
                   }
               ],
               "headers": []
           }
           "id": 1
       }

响应:

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

更新 监控项 预处理选项

使用监控项预处理规则“Custom”更新监控项原型 乘数".

执行请求:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.update",
           "params": {
               "itemid": "44211",
               "preprocessing": [
                   {
                       "type": 1,
                       "params": "4",
                       "error_handler": 2,
                       "error_handler_params": "5"
                   }
               ]
           },
           "id": 1
       }

响应

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

更新脚本 监控项 原型

使用不同的脚本更新脚本监控项原型,并移除先前脚本使用的不必要参数。

执行请求:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.update",
           "params": {
               "itemid": "23865",
               "parameters": [],
               "script": "Zabbix.log(3, 'Log test');\nreturn 1;"
           },
           "id": 1
       }

响应:

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

来源

CItemPrototype::update() 位于 ui/include/classes/api/services/CItemPrototype.php 文件中.