Grafana
在本示例中,您将在Grafana 和 Port 之间创建一个 webhook 集成,用于接收警报实体。
Port 配置
创建以下蓝图定义:
Alert blueprint
{
"identifier": "grafanaAlert",
"description": "This blueprint represents a Grafana alert in your software catalog",
"title": "Grafana Alert",
"icon": "Grafana",
"schema": {
"properties": {
"status": {
"title": "Status",
"description": "Current status of the alert, firing or resolved",
"type": "string",
"enum": ["firing", "resolved"],
"enumColors": {
"firing": "red",
"resolved": "green"
}
},
"labels": {
"title": "Labels",
"type": "object",
"description": "Labels that are part of this alert, map of string keys to string values"
},
"description": {
"title": "Description",
"type": "string"
},
"createdAt": {
"title": "Created at",
"description": "Start time of the alert",
"type": "string",
"format": "date-time"
},
"resolvedAt": {
"title": "Resolved At",
"type": "string",
"description": "End time of the alert",
"format": "date-time"
},
"values": {
"title": "Values",
"type": "object",
"description": "Values that triggered the current status"
},
"generatorURL": {
"title": "Generator URL",
"type": "string",
"description": "URL of the alert rule in the Grafana UI",
"format": "url"
},
"fingerprint": {
"title": "Fingerprint",
"description": "The labels fingerprint, alarms with the same labels will have the same fingerprint",
"type": "string"
},
"silenceURL": {
"title": "Silence URL",
"description": "URL to silence the alert rule in the Grafana UI",
"type": "string",
"format": "url"
},
"summary": {
"title": "Summary",
"type": "string"
},
"runbookURL": {
"title": "Runbook URL",
"type": "string",
"description": "URL of the runbook in the Grafana UI",
"format": "url"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
创建以下 webhook 配置using Port's UI
Alert webhook configuration
- 基本信息 选项卡 - 填写以下详细信息:
1.title:
Grafana Alert Mapper
; 2.标识符 :grafana_alert_mapper
; 3.Description :将 Grafana 警报映射到 Port
的 webhook 配置; 4.图标 :Grafana
; - 集成配置选项卡 - 填写以下 JQ 映射:
[
{
"blueprint": "grafanaAlert",
"filter": "true",
"itemsToParse": ".body.alerts",
"entity": {
"identifier": ".item.labels.alertname + \"-\" + .item.fingerprint | gsub(\"[^a-zA-Z0-9@_.:/=-]\"; \"-\") | tostring",
"title": ".item.labels.alertname",
"properties": {
"status": ".item.status",
"labels": ".item.labels",
"description": ".item.annotations.description",
"summary": ".item.annotations.summary",
"runbookURL": ".item.annotations.runbook_url",
"createdAt": ".item.startsAt",
"resolvedAt": ".item.endsAt",
"values": ".item.values",
"generatorURL": "if .item.generatorURL != \"\" then .item.generatorURL else null end",
"fingerprint": ".item.fingerprint",
"silenceURL": "if .item.silenceURL != \"\" then .item.silenceURL else null end"
}
}
}
]
3.点击页面底部的保存。
在 Grafana 中创建 webhook
- 转到 Grafana 账户中的警报;
- 在联系点下点击添加联系点;
- 输入以下详细信息:
- 名称"- 被用于一个有意义的名称,如 Port Webhook;
- 集成"- 从列表中选择 "Webhook";
URL
- 输入创建 Webhook 配置后收到的url
键的值; 4.单击 保存联系人点保存联系人; 5.转到通知策略,将 Port Webhook 联系点添加到您的默认策略,并在 Grafana 中收到任何警报通知; 6.您可以选择将联系点添加到现有的通知策略或创建新策略,具体取决于您的用例; 7.单击保存策略。
完成!您在 Grafana 中的警报发生的任何变化都会触发一个 Webhook 事件,发送到 Port 提供的 Webhook URL。 Port 将根据映射解析事件,并相应地更新目录实体。