

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 警报通知渠道 API
<a name="v10-Grafana-API-AlertingNotificationChannels"></a>

使用警报通知渠道 API 创建、更新、删除和检索通知渠道。

通知渠道的标识符（id）是一个自动递增的数值，并且对于每个工作区是唯一的。通知渠道的唯一标识符（uid）可用于在多个工作区之间唯一标识文件夹。如果您在创建通知渠道时未提供 uid，则会自动生成一个。Uid 允许在访问通知渠道和在多个 Amazon Managed Grafana 工作区之间同步通知渠道时拥有一致的 URL。

**注意**  
要在您的亚马逊托管 Grafana 工作空间中使用 Grafana API，您必须拥有有效的服务账户令牌。您可以将其包含在 API 请求的 `Authorization` 字段中。

## 获取所有通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-getall"></a>

返回经过身份验证的用户有权查看的所有通知渠道。

```
GET /api/alert-notifications
```

**示例请求**

```
GET /api/alert-notifications HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

[
  {
    "id": 1,
    "uid": "sns-uid",
    "name": "test",
    "type": "sns",
    "isDefault": false,
    "sendReminder": false,
    "disableResolveMessage": false,
    "frequency": "",
    "created": "2023-09-08T19:57:56Z",
    "updated": "2023-09-08T19:57:56Z",
    "settings": {
      "authProvider": "default",
      "autoResolve": true,
      "httpMethod": "POST",
      "messageFormat": "json",
      "severity": "critical",
      "topic": "<SNS-TOPIC-ARN>",
      "uploadImage": false
    },
    "secureFields": {}
  }
]
```

## 获取所有通知渠道（查询）
<a name="v10-Grafana-API-AlertNotificationChannels-getlookup"></a>

返回所有通知渠道，但信息不太详细。任何经过身份验证的用户都可以访问，主要在配置警报规则时用于在 Grafana 工作区控制台 UI 中提供警报通知渠道。

```
GET /api/alert-notifications/lookup
```

**示例请求**

```
GET /api/alert-notifications/lookup HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

[
  {
    "id": 1,
    "uid": "sns-uid",
    "name": "test",
    "type": "sns",
    "isDefault": false
  },
  {
    "id": 2,
    "uid": "slack-uid",
    "name": "Slack",
    "type": "slack",
    "isDefault": false
  }
]
```

## 按 UID 获取所有通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-getbyUID"></a>

```
GET /api/alert-notifications/uid/:uid
```

**示例请求**

```
GET /api/alert-notifications/uid/sns-uid HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "test",
  "type": "sns",
  "isDefault": false,
  "sendReminder": false,
  "disableResolveMessage": false,
  "frequency": "",
  "created": "2023-09-08T19:57:56Z",
  "updated": "2023-09-08T19:57:56Z",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "secureFields": {}
}
```

## 按 ID 获取所有通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-getbyId"></a>

```
GET /api/alert-notifications/:id
```

**示例请求**

```
GET /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "test",
  "type": "sns",
  "isDefault": false,
  "sendReminder": false,
  "disableResolveMessage": false,
  "frequency": "",
  "created": "2023-09-08T19:57:56Z",
  "updated": "2023-09-08T19:57:56Z",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "secureFields": {}
}
```

## 创建通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-Create"></a>

要查看 Amazon Managed Grafana 支持哪些通知渠道，请参阅 [使用联系点](alert-contact-points.md) 中支持的通知渠道列表。

```
POST /api/alert-notifications
```

**示例请求**

```
POST /api/alert-notifications HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "uid": "new-sns-uid", // optional
  "name": "sns alert notification",  //Required
  "type":  "sns", //Required
  "isDefault": false,
  "sendReminder": false,
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "new-sns-uid",
  "name": "sns alert notification",
  "type": "sns",
  "isDefault": false,
  "sendReminder": false,
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "created": "2018-04-23T14:44:09+02:00",
  "updated": "2018-08-20T15:47:49+02:00"
}
```

## 按 UID 更新通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-UpdatebyUID"></a>

```
PUT /api/alert-notifications/uid/:uid
```

**示例请求**

```
PUT /api/alert-notifications/uid/sns-uid HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "uid": "sns-uid", // optional
  "name": "sns alert notification",  //Required
  "type":  "sns", //Required
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "sns alert notification",
  "type": "sns",
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "created": "2017-01-01 12:34",
  "updated": "2017-01-01 12:34"
}
```

## 按 Id 更新通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-UpdatebyId"></a>

```
PUT /api/alert-notifications/:id
```

**示例请求**

```
PUT /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "id": 1,
  "uid": "sns-uid", // optional
  "name": "sns alert notification",  //Required
  "type":  "sns", //Required
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "sns alert notification",
  "type": "sns",
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "created": "2017-01-01 12:34",
  "updated": "2017-01-01 12:34"
}
```

## 按 UID 删除通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-DeletebyUID"></a>

```
DELETE /api/alert-notifications/uid/:uid
```

**示例请求**

```
DELETE /api/alert-notifications/uid/sns-uid HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "message": "Notification deleted"
}
```

## 按 Id 删除通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-DeletebyId"></a>

```
DELETE /api/alert-notifications/:id
```

**示例请求**

```
DELETE /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "message": "Notification deleted"
}
```

## 测试通知渠道
<a name="v10-Grafana-API-AlertNotificationChannels-Test"></a>

针对给定的通知渠道类型和设置发送测试通知消息。

```
POST /api/alert-notifications/test
```

**示例请求**

```
POST /api/alert-notifications/test HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "type":  "sns",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{
  "message": "Test notification sent"
}
```