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

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

[comment]: # ({e3d076ea-292dcffa})
### 描述

`object maintenance.update(object/array maintenances)`

此方法允许更新已存在的维护模式。

::: noteclassic
此方法仅适用于 *管理员* 和 *超级管理员* 用户类型。可以在用户角色中撤销调用该方法的权限设置。请参阅[用户角色](/manual/web_interface/frontend_sections/users/user_roles) 了解更多信息。
:::

[comment]: # ({/e3d076ea-292dcffa})

[comment]: # ({364d131c-678c22b3})
### 参数

`(object/array)` 要更新的维护属性。

必须为每个维护定义 `maintenanceid` 属性，其他所有属性均为可选。只有传入的属性会被更新，其他所有属性将保持不变。

除了[标准维护属性](object#maintenance)之外，该方法还接受以下参数。

|参数|[类型](/manual/api/reference_commentary#data-types)|描述|
|--|--|------|
|groups|object/array|用于替换当前组的[主机组](/manual/api/reference/hostgroup/object)。<br><br>主机组必须仅定义 `groupid` 属性。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 如果未设置 `hosts`，则为*必需*|
|hosts|object/array|用于替换当前主机的[主机](/manual/api/reference/host/object)。<br><br>主机必须仅定义 `hostid` 属性。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 如果未设置 `groups`，则为*必需*|
|timeperiods|object/array|用于替换当前时间段的维护[时间段](/manual/api/reference/maintenance/object#time-period)。|
|tags|object/array|用于替换当前标签的[问题标签](/manual/api/reference/maintenance/object#problem-tag)。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 当[维护对象](object#maintenance)的 `maintenance_type` 设置为“采集数据”时，*支持*该参数|

[comment]: # ({/364d131c-678c22b3})

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

 `(object)`在`maintenanceids`属性中返回一个包含已被更新的维护模式的IDs的对象。

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

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

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

[comment]: # ({ffac6646-25215f8d})
#### 指定不同的主机

将当前分配维护的主机替换为两台不同的主机。

[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "maintenance.update",
    "params": {
        "maintenanceid": "3",
        "hosts": [
            {"hostid": "10085"},
            {"hostid": "10084"}
        ]
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "maintenanceids": [
            "3"
        ]
    },
    "id": 1
}
```

[comment]: # ({/ffac6646-25215f8d})

[comment]: # ({db5fcf06-82b3ef0e})
### 另请参阅

-   [时间段](object#time-period)

[comment]: # ({/db5fcf06-82b3ef0e})

[comment]: # ({63ad1661-63ad1661})
### 来源

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

[comment]: # ({/63ad1661-63ad1661})
