[comment]: # translation:outdated

[comment]: # ({0ec30c22-0ec30c22})
# item.update

[comment]: # ({/0ec30c22-0ec30c22})

[comment]: # ({38961105-38961105})
### 描述

`object item.update(object/array items)`

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

::: noteclassic
Web 监控项无法通过Zabbix API进行更新.

:::

::: noteclassic
此方法仅适用于*Admin*和*Super admin*
用户类型. 调用该方法的权限可以在用户角色
设置中撤销. 更多信息请参阅[User
roles](/manual/web_interface/frontend_sections/administration/user_roles).

:::

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

[comment]: # ({5678d8e9-4e151fd6})
### 参数

`(object/array)` 监控项 待更新的属性.

每个监控项必须定义`itemid`属性，其他
属性均为可选。仅传递的属性会被更新，其余
属性将保持不变。

除[监控项](object#监控项)外，该方法
还接受以下参数。

| 参数 | [数据类型](/manual/api/reference_commentary#数据类型) | 描述 |
|--|--|------|
| preprocessing | array | 用于替换当前预处理选项的[预处理](/manual/api/reference/item/object#预处理)选项。 |
| tags | array | 监控项的[监控项-标签](/manual/api/reference/item/object#监控项-标签) |

[comment]: # ({/5678d8e9-4e151fd6})

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

`(object)` 返回一个包含已更新object ID的监控项，
这些ID位于`itemids`属性下。

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

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

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

[comment]: # ({534da9af-5388578b})
#### 启用 监控项

启用一个监控项，即将其状态设置为"0".

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "item.update",
    "params": {
        "itemid": "10092",
        "status": 0
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "10092"
        ]
    },
    "id": 1
}
```

[comment]: # ({/534da9af-5388578b})

[comment]: # ({d312232b-0bf89382})
#### 更新依赖的 监控项

更新依赖监控项名称和主监控项 ID。仅支持相同
主机 是被允许的，因此主节点和从属节点 监控项 应保持一致
hostid.

请求

```json
{
    "jsonrpc": "2.0",
    "method": "item.update",
    "params": {
        "name": "Dependent item updated name",
        "master_itemid": "25562",
        "itemid": "189019"
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "189019"
        ]
    },
    "id": 1
}
```

[comment]: # ({/d312232b-0bf89382})

[comment]: # ({f05084a9-8f365363})
#### 更新 HTTP agent 监控项

启用 监控项 值捕获功能.

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "item.update",
    "params": {
        "itemid": "23856",
        "allow_traps": 1
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "23856"
        ]
    },
    "id": 1
}
```

[comment]: # ({/f05084a9-8f365363})

[comment]: # ({134fd698-44f323b8})
#### 更新带有预处理的 监控项

使用预处理规则"In range"更新监控项与监控项

请求

```json
{
    "jsonrpc": "2.0",
    "method": "item.update",
    "params": {
        "itemid": "23856",
        "preprocessing": [
            {
                "type": 13,
                "params": "\n100",
                "error_handler": 1,
                "error_handler_params": ""
            }
        ]
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "23856"
        ]
    },
    "id": 1
}
```

[comment]: # ({/134fd698-44f323b8})

[comment]: # ({5c588e1f-dcfb98a0})
#### 更新脚本 监控项

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

请求:

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

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

[comment]: # ({/5c588e1f-dcfb98a0})

[comment]: # ({646fe32a-646fe32a})
### 来源

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

[comment]: # ({/646fe32a-646fe32a})
