discoveryrule.update

描述

object discoveryrule.update(object/array lldRules)

此方法允许update现有的LLD规则.

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

参数

(object/array) 待更新的LLD规则属性.

每个LLD规则必须定义itemid属性,其他所有属性均为可选。仅传递的属性会被更新,其余属性将保持不变。

除了lld规则外, 该方法还接受以下参数。

参数 数据类型 描述
filter object 用于替换现有过滤器的lld-规则过滤器
preprocessing object/array 用于替换现有预处理选项的lld-规则预处理选项。

参数行为:
- 继承的objects为只读
lld_macro_paths object/array 用于替换现有lld_macro_path选项的LLD规则lld-宏路径选项。

参数行为:
- 继承的objects为只读
overrides object/array 用于替换现有覆盖选项的lld-规则覆盖选项。

参数行为:
- 继承的objects为只读

返回值

(object) 返回一个包含更新后的LLD规则ID的object 该ID位于itemids属性下

示例

向 LLD 规则添加过滤器

添加过滤器以使{#FSTYPE}宏的内容 匹配@用于发现的文件系统正则表达式

执行请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.update",
           "params": {
               "itemid": "22450",
               "filter": {
                   "evaltype": 1,
                   "conditions": [
                       {
                           "macro": "{#FSTYPE}",
                           "value": "@File systems for discovery"
                       }
                   ]
               }
           },
           "id": 1
       }

响应:

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

添加 LLD 宏路径

执行请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.update",
           "params": {
               "itemid": "22450",
               "lld_macro_paths": [
                   {
                       "lld_macro": "{#MACRO1}",
                       "path": "$.json.path"
                   }
               ]
           },
           "id": 1
       }

响应:

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

禁用陷阱

禁用发现规则的LLD陷阱功能

执行请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.update",
           "params": {
               "itemid": "28336",
               "allow_traps": 0
           },
           "id": 1
       }

响应:

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

更新LLD规则预处理选项

更新带有预处理规则"JSONPath"的LLD规则

执行请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.update",
           "params": {
               "itemid": "44211",
               "preprocessing": [
                   {
                       "type": 12,
                       "params": "$.path.to.json",
                       "error_handler": 2,
                       "error_handler_params": "5"
                   }
               ]
           },
           "id": 1
       }

响应:

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

更新LLD规则脚本

使用不同的脚本更新LLD规则脚本,并移除先前脚本使用的非必要参数。

执行请求:

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

响应:

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

更新LLD规则生命周期

将LLD规则更新为在12小时后禁用不再发现的实体 并在7天后delete它

执行请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.update",
           "params": {
               "itemid": "46864",
               "lifetime_type": 0, 
               "lifetime": "7d",
               "enabled_lifetime_type": 0,
               "enabled_lifetime": "12h"
           },
           "id": 1
       }

响应:

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

来源

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