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

discoveryrule.update

Description 说明

object discoveryrule.update(object/array lldRules)

This method allows to update existing LLD rules. 此方法允许更新已存在的LLD规则。

Parameters 参数

(object/array) LLD rule properties to be updated. (object/array) 要更新的''LLD规则属性。

The itemid property must be defined for each LLD rule, all other properties are optional. Only the passed properties will be updated, all others will remain unchanged. 每个LLD规则的itemid属性必须被定义,其他属性为可选。值传递要被更新的属性,其他属性保持不变。

Additionally to the standard LLD rule properties, the method accepts the following parameters. 另外见standard LLD rule properties,此方法接受如下参数。

Parameter Type Description
filter object LLD rule filter object to replace the current filter. LLD规则要替换当前的筛选对象。

Return values 返回值

(object) Returns an object containing the IDs of the updated LLD rules under the itemids property. (object)itemids属性下返回一个包含被更新的LLD规则的IDs。

Examples 示例

Adding a filter to an LLD rule 为LLD规则添加一个筛选器

Add a filter so that the contents of the {#FSTYPE} macro would match the @File systems for discovery regexp.

Request:

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

Response:

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

Disable trapping 禁用trapping

Disable LLD trapping for discovery rule. 禁用LLD trapping 发现规则。

Request:

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

Response:

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

Source

CDiscoveryRule::update() in frontends/php/include/classes/api/services/CDiscoveryRule.php.

Updating LLD rule preprocessing options

Update an LLD rule with preprocessing rule “JSONPath”.

Request:

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

Response:

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

Updating LLD rule script

Update an LLD rule script with a different script and remove unnecessary parameters that were used by previous script.

Request:

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

Response:

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

Source

CDiscoveryRule::update() in ui/include/classes/api/services/CDiscoveryRule.php.