

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

使用警示通知管道 API 來建立、更新、刪除和擷取通知管道。

通知通道的識別符 (id) 是自動遞增的數值，而且每個工作區都是唯一的。通知頻道的唯一識別符 (uid) 可用來唯一識別多個工作區之間的資料夾。如果您在建立通知管道時未提供通知管道，則會自動產生。uid 允許在多個 Amazon Managed Grafana 工作區之間存取通知通道和同步通知通道時具有一致的 URLs。

**注意**  
若要搭配 Amazon Managed 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"
}
```