警示通知管道 API - Amazon Managed Grafana

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

警示通知管道 API

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

通知通道的識別碼 (id) 是自動遞增的數值,而且每個工作區僅具唯一性。通知通道的唯一標識符(uid)可用於唯一標識多個工作區之間的文件夾。如果您在建立通知頻道時未提供,系統會自動產生此功能。uid 允許使用一致的 URL 來存取通知通道,以及在多個 Amazon 受管的 Grafana 工作區之間同步通知通道時。

注意

若要將 Grafana API 與您的 Amazon 受管理工作區搭配使用,您必須擁有有效的 Grafana API 權杖。您可以在 API 要求的Authorization欄位中包含此項目。如需如何建立權杖以驗證 API 呼叫的相關資訊,請參閱使用令牌進行身

取得所有通知管道

傳回已驗證使用者有權檢視的所有通知通道。

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": {} } ]

取得所有通知管道 (查詢)

傳回所有通知通道,但資訊較少。可由任何經過驗證的使用者存取,主要用於在設定警示規則時在 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 獲取所有通知渠道

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 獲取所有通知渠道

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": {} }

建立通知管道

若要查看 Amazon 受管 Grafana 支援哪些通知管道,請參閱中支援的通知程式清單。使用接觸點

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 更新通知渠道

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 更新通知通道

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 刪除通知渠道

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 刪除通知頻道

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" }

測試通知通道

針對指定的通知通道類型和設定傳送測試通知訊息。

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" }