本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
提醒通知渠道 API
使用提醒通知渠道 API 创建、更新、删除和检索通知渠道。
通知渠道的标识符 (id) 是一个自动递增的数值,并且仅在每个工作空间中是唯一的。通知渠道的唯一标识符 (uid) 可用于在多个工作空间之间唯一标识文件夹。如果您在创建通知渠道时未提供通知,则会自动生成该消息。uid 允许在访问通知渠道和在多个 Amazon Managed Grafana 工作空间之间同步通知渠道时拥有一致的网址。
注意
要在亚马逊托管 Grafana 工作空间中使用 Grafana API,您必须拥有有效的 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 工作区控制台用户界面中提供警报通知渠道。
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 Managed 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" }