[comment]: # ({f47b150e-f47b150e})
# 创建

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

[comment]: # ({a2eec896-e8498ebc})
### 说明

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

该方法允许创建维护模式。

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

[comment]: # ({/a2eec896-e8498ebc})

[comment]: # ({0f755a82-6c14daac})
### 参数

`(object/array)` 要创建的维护。

除了[标准维护属性](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)。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- *必需*|
|tags|object/array|[问题标签](/manual/api/reference/maintenance/object#problem-tag)。<br><br>用于定义必须被抑制的问题。<br>如果未提供标签，则所有处于活动维护中的主机问题都将被抑制。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- 当[维护对象](object#maintenance)的 `maintenance_type` 设置为“采集数据”时，*支持*|

[comment]: # ({/0f755a82-6c14daac})

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

 `(object)`在`maintenanceids`属性中返回一个包含所有已被创建的维护模式的对象的ID。返回的IDs的排序与传递的维护模式的IDs顺序一致。

[comment]: # ({/48c4869c-48c4869c})

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

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

[comment]: # ({f3843348-bb812c67})
#### 创建维护

为 ID 为“2”的主机组创建一个带数据收集的维护，并带有
问题标签 **service:mysqld** 和 **error**。该维护必须从
17.03.2026 持续到 17.03.2027，每周日 18:00 生效，持续
一小时。

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

```json
{
    "jsonrpc": "2.0",
    "method": "maintenance.create",
    "params": {
        "name": "Sunday maintenance",
        "active_since": 1773720240,
        "active_till": 1805256240,
        "tags_evaltype": 0,
        "groups": [
            {"groupid": "2"}
        ],
        "timeperiods": [
            {
                "period": 3600,
                "timeperiod_type": 3,
                "start_time": 64800,
                "every": 1,
                "dayofweek": 64
            }
        ],
        "tags": [
            {
                "tag": "service",
                "operator": "0",
                "value": "mysqld"
            },
            {
                "tag": "error",
                "operator": "2",
                "value": ""
            }
        ]
    },
    "id": 1
}
```

响应：

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

[comment]: # ({/f3843348-bb812c67})

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

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

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

[comment]: # ({3e3a556f-3e3a556f})
### 来源

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

[comment]: # ({/3e3a556f-3e3a556f})
