[comment]: # ({35eb8af0-f5d7e62f})
# 创建

[comment]: # ({/35eb8af0-f5d7e62f})

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

`object sla.create(object/array SLAs)`

此方法用于创建新的 SLA 对象。

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

[comment]: # ({/d7447075-c44d5a50})

[comment]: # ({bdf1088b-69be5e01})
### 参数

`(object/array)` 要创建的 SLA 对象。

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

|参数|[类型](/manual/api/reference_commentary#data-types)|描述|
|--|--|------|
|service_tags|array|要为 SLA 创建的 [SLA 服务标签](/manual/api/reference/sla/object#sla-service-tag)。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- *必需*|
|schedule|array|要为 SLA 创建的 [SLA 计划](/manual/api/reference/sla/object#sla-schedule)。<br>指定空参数将被解释为 24x7 计划。<br>默认值：24x7 计划。|
|excluded_downtimes|array|要为 SLA 创建的 [SLA 排除的停机时间](/manual/api/reference/sla/object#sla-excluded-downtime)。|

[comment]: # ({/bdf1088b-69be5e01})

[comment]: # ({49fa241a-f5eb6cfd})

### 返回值

`(对象)` 返回一个包含创建的 SLA 的 ID 的对象，这些 ID 在 `slaids` 属性下。返回的 ID 的顺序与传入 SLA 的顺序相匹配。

[comment]: # ({/49fa241a-f5eb6cfd})

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

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

[comment]: # ({4591adda-fc6bed3c})

#### 创建一个 SLA

指示创建一个 SLA 条目:
* 跟踪与 SQL 引擎相关的服务的正常运行时间;
* 自定义时间表，所有工作日都包括在内，但不包括星期六的最后一个小时;
* 生效时间为 2022年的最后一天;
* 计划停机时间为 1 小时 15 分钟，从 7 月 4 日午夜开始;
* 将启用SLA 每周报告计算;
* 最低可接受的 SLO 为 99.9995%。

[comment]: # ({/4591adda-fc6bed3c})

[comment]: # ({ce7393a0-18749288})
[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "sla.create",
    "params": [
        {
            "name": "数据库正常运行时间",
            "slo": "99.9995",
            "period": "1",
            "timezone": "America/Toronto",
            "description": "为主要数据库引擎提供出色的正常运行时间。",
            "effective_date": 1672444800,
            "status": 1,
            "schedule": [
                {
                    "period_from": 0,
                    "period_to": 601200
                }
            ],
            "service_tags": [
                {
                    "tag": "database",
                    "operator": "0",
                    "value": "mysql"
                },
                {
                    "tag": "database",
                    "operator": "0",
                    "value": "postgresql"
                }
            ],
            "excluded_downtimes": [
                {
                    "name": "软件版本升级发布",
                    "period_from": "1648760400",
                    "period_to": "1648764900"
                }
            ]
        }
    ],
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "slaids": [
            "5"
        ]
    },
    "id": 1
}
```

[comment]: # ({/ce7393a0-18749288})

[comment]: # ({b5a2d850-fda6729e})
### 来源

CSla::create() 在 *ui/include/classes/api/services/CSla.php*。

[comment]: # ({/b5a2d850-fda6729e})
