[comment]: # translation:outdated

[comment]: # ({d756b50a-d756b50a})
# 更新

[comment]: # ({/d756b50a-d756b50a})

[comment]: # ({8480f308-0d23e0d8})
### 描述

`object discoveryrule.update(object/array lldRules)`

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

::: noteclassic
此方法只有 *Admin(管理员)* 和 *Super admin(超级管理员)* 用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看[用户角色](/manual/web_interface/frontend_sections/administration/user_roles)。
:::

[comment]: # ({/8480f308-0d23e0d8})

[comment]: # ({703714b8-cf98658c})

### 参数

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

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

除了 [标准 LLD 规则属性](object#lld规则)，该方法还接受以下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|---------|---------------------------------------------------|-----------|
|filter|object|LLD规则[过滤](/manual/api/reference/discoveryrule/object#lld-规则过滤器)替换当前过滤器的对象|
|preprocessing|array|LLD规则[预处理](/manual/api/reference/discoveryrule/object#lld-规则预处理)替换当前预处理选项的选项。|
|lld\_macro\_paths|array|LLD规则[lld\_macro\_path](/manual/api/reference/discoveryrule/object#lld宏路径)选项。|
|overrides|array|LLD规则[覆盖](/manual/api/reference/discoveryrule/object#lld规则覆盖)选项。|

[comment]: # ({/703714b8-cf98658c})

[comment]: # ({6f962e26-6f962e26})
### 返回值

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

[comment]: # ({/6f962e26-6f962e26})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({0eadd7af-67c9278f})
#### LLD 规则添加过滤器

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

请求：

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

响应：

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

[comment]: # ({/0eadd7af-67c9278f})

[comment]: # ({9c4607cd-f3fd4d6c})
#### 添加LLD宏路径

请求：

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

响应：

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

[comment]: # ({/9c4607cd-f3fd4d6c})

[comment]: # ({a9838ef7-8d8cc019})
#### 禁止 trapping

禁止自动发现规则trapping。

请求：

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

响应：

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

[comment]: # ({/a9838ef7-8d8cc019})

[comment]: # ({6c854586-bef0a5f5})
#### 更新LLD规则预处理选项

使用预处理规则“JSONPath”更新LLD规则。

请求：

``` {.java}
{
    "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
}
```

响应：

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

[comment]: # ({/6c854586-bef0a5f5})

[comment]: # ({1d73918a-3f18a1c3})
#### 更新LLD规则脚本

使用不同的脚本更新 LLD 规则脚本，并删除之前脚本使用的不必要参数。

请求：

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

响应：

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

[comment]: # ({/1d73918a-3f18a1c3})

[comment]: # ({6a73b645-6a73b645})
### 来源

*ui/include/classes/api/services/CDiscoveryRule.php* 中的 CDiscoveryRule::update()。

[comment]: # ({/6a73b645-6a73b645})
