[comment]: # translation:outdated

[comment]: # ({c7a5132c-2587902b})
# sla.get

[comment]: # ({/c7a5132c-2587902b})

[comment]: # ({19361ddd-bfd5de7f})
### 描述

`integer/array sla.get(object parameters)`

该方法允许根据给定参数检索SLA objects。

::: noteclassic
此方法适用于任何类型的用户。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见[User
roles](/manual/web_interface/frontend_sections/users/user_roles)。

:::

[comment]: # ({/19361ddd-bfd5de7f})

[comment]: # ({f104dcc3-e7637a1d})
### 参数

`(object)` 定义期望输出的参数.

该方法支持以下参数.

| 参数 | [数据类型](/manual/api/reference_commentary#数据类型) | 描述 |
|--|--|------|
| slaids | ID/array | 仅返回具有指定ID的SLAs. |
| serviceids | ID/array | 仅返回匹配特定服务的SLAs. |
| selectSchedule | query | 返回包含SLA时间表的`schedule`属性.<br><br>支持`count`. |
| selectExcludedDowntimes | query | 返回包含SLA排除停机时间的`excluded_downtimes`属性.<br><br>支持`count`. |
| selectServiceTags | query | 返回包含SLA服务标签的`service_tags`属性.<br><br>支持`count`. |
| sortfield | string/array | 按给定属性对结果进行排序.<br><br>可能的值: `slaid`, `name`, `period`, `slo`, `effective_date`, `timezone`, `status`, `description`. |
| countOutput | boolean | 这些参数在[通用get方法参数](/manual/api/reference_commentary#通用get方法参数)中有描述. |
| editable | boolean | ^           |
| excludeSearch | boolean | ^           |
| filter | object | ^           |
| limit | integer | ^           |
| output | query | ^           |
| preservekeys | boolean | ^           |
| search | object | ^           |
| searchByAny | boolean | ^           |
| searchWildcardsEnabled | boolean | ^           |
| sortorder | string/array | ^           |
| startSearch | boolean | ^           |

[comment]: # ({/f104dcc3-e7637a1d})

[comment]: # ({07ca11ca-7223bab1})
### 返回值

`(integer/array)` 返回以下两种情况之一:

- 一个包含array的objects数组
- 检索到的objects数量，如果使用了`countOutput`参数

[comment]: # ({/07ca11ca-7223bab1})

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

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

[comment]: # ({578ccfee-cd4e4011})
#### 检索所有SLA

获取所有SLA及其属性的完整数据

[执行请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "sla.get",
    "params": {
        "output": "extend",
        "selectSchedule": ["period_from", "period_to"],
        "selectExcludedDowntimes": ["name", "period_from", "period_to"],
        "selectServiceTags": ["tag", "operator", "value"],
        "preservekeys": true
    },
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "1": {
            "slaid": "1",
            "name": "Database Uptime",
            "period": "1",
            "slo": "99.9995",
            "effective_date": "1672444800",
            "timezone": "America/Toronto",
            "status": "1",
            "description": "Provide excellent uptime for main SQL database engines.",
            "service_tags": [
                {
                    "tag": "database",
                    "operator": "0",
                    "value": "mysql"
                },
                {
                    "tag": "database",
                    "operator": "0",
                    "value": "postgresql"
                }
            ],
            "schedule": [
                {
                    "period_from": "0",
                    "period_to": "601200"
                }
            ],
            "excluded_downtimes": [
                {
                    "name": "Software version upgrade rollout",
                    "period_from": "1648760400",
                    "period_to": "1648764900"
                }
            ]
        }
    },
    "id": 1
}
```

[comment]: # ({/578ccfee-cd4e4011})

[comment]: # ({1f2163e3-05e3cf18})
### 来源

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

[comment]: # ({/1f2163e3-05e3cf18})
