2022 Zabbix中国峰会
2022 Zabbix中国峰会

更新

描述

object discoveryrule.update(object/array lldRules)

此方法更新已存在的LLD规则。

此方法只有 Admin(管理员)Super admin(超级管理员) 用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看用户角色

参数

(object/array) 需要更新的 LLD 规则属性。

必须为每个 LLD 规则定义“itemid”属性,所有其他属性都是可选的。只有传递的属性将被更新,所有其他的将保持不变。

除了 标准 LLD 规则属性,该方法还接受以下参数。

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

参数行为:
- 对于继承对象是只读
lld_macro_paths object/array LLD规则lld_macro_path选项,用于替换现有的lld_macro_path选项。

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

参数行为:
- 对于继承对象是只读

返回值

(object) 返回一个对象,其中包含 itemids 属性下更新的 LLD 规则的 ID。

示例

LLD 规则添加一个过滤器

添加一个过滤器,以便 {#FSTYPE} 宏的内容与 @File systems for discovery 正则表达式匹配。

请求

{
           "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
       }

禁用 trapping

禁用发现规则的LLD trapping。

请求:

{
           "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天后删除它。

请求

{
           "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() in ui/include/classes/api/services/CDiscoveryRule.php.