Skip to main content

普罗米修斯

在本示例中,您将在Prometheus Alertmanager 和 Port 之间创建一个 webhook 集成,用于接收警报实体。

Port 配置

创建以下蓝图定义:

Alert blueprint
{
"identifier": "prometheusAlerts",
"description": "Prometheus alerts in your software catalog",
"title": "Prometheus Alerts",
"icon": "Prometheus",
"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"
},
"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"
},
"generatorURL": {
"title": "Generator URL",
"type": "string",
"description": "URL of the alert rule in the Prometheus UI",
"format": "url"
},
"fingerprint": {
"title": "Fingerprint",
"description": "The labels fingerprint, alarms with the same labels will have the same fingerprint",
"type": "string"
},
"summary": {
"title": "Summary",
"type": "string"
},
"severity": {
"title": "Severity",
"type": "string",
"enum": [
"indeterminate",
"information",
"warning",
"minor",
"major",
"critical",
"fatal"
],
"enumColors": {
"indeterminate": "purple",
"information": "blue",
"warning": "yellow",
"minor": "lightGray",
"major": "pink",
"critical": "red",
"fatal": "red"
}
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}

创建以下 webhook 配置using Port's UI

Alert webhook configuration
  1. 基本信息 选项卡 - 填写以下详细信息: 1.title: Prometheus Alert Mapper; 2.标识符 : prometheus_alert_mapper; 3.Description : 将 Prometheus 警报映射到 Port 的 webhook 配置; 4.图标 : Prometheus
  2. 集成配置选项卡 - 填写以下 JQ 映射:
    [
    {
    "blueprint": "prometheusAlerts",
    "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",
    "severity": ".item.labels.severity",
    "labels": ".item.labels",
    "summary": ".item.annotations.summary",
    "createdAt": ".item.startsAt",
    "resolvedAt": ".item.endsAt",
    "generatorURL": "if .item.generatorURL != \"\" then .item.generatorURL else null end",
    "fingerprint": ".item.fingerprint"
    }
    }
    }
    ]

3.点击页面底部的保存

配置 Alertmanager 以发送 webhook

  1. 确保已按照prometheus/alertmanager 中的说明安装 Prometheus Alertmanager;

  2. 配置 Alertmanager,以便从服务器发送警报信息到 Port。编辑 Alertmanager 配置文件 (alertmanager.yaml),将从 Port 生成的 webhook 添加为接收器; 1.创建名为 port_webhook 的新接收器对象。将 webhook 的 URL 粘贴到 url 字段,并将 send_resolved 值设置为 true。 2.将 port_webhook receivers 添加到 route 对象中;

    Example configuration file.
    global:
    resolve_timeout: 20s

    route:
    group_wait: 30s
    group_interval: 5m
    repeat_interval: 3h
    receiver: port_webhook

    receivers:
    - name: port_webhook
    webhook_configs:
    - url: https://port-webhook-url
    send_resolved: true
  3. Save the alertmanager.yaml file and restart the alertmanager to apply the changes.

Done! Any change that happens to your alerts in your server will trigger a webhook event to the webhook URL provided by Port. Port will parse the events according to the mapping and update the catalog entities accordingly.