企业微信告警配置

元气满满
2026-03-09 / 0 评论 / 0 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2026年03月09日,已超过232天没有更新,若内容或图片失效,请留言反馈。
创建企业微信机器人

1、企业微信创建群聊
2、创建机器人,记住webhook地址

创建prometheus-alert

prometheus-alert-03.png
prometheus-alert-04.png

# 企业微信卡片
{
    "msgtype": "news",
    "news": {
        "articles": [
            {{ range .alerts }}
            {
                "title": "{{ if eq .status "resolved" }}✅【已恢复】{{ .labels.alertname }}{{ else }}🚨【告警通知】{{ .labels.alertname }}{{ end }}",
                "description": "级别: {{ .labels.severity }}\n主机: {{ .labels.instance }}\n{{ if eq .status "resolved" }}开始: {{ slice .startsAt 0 10 }} {{ slice .startsAt 11 19 }}\n结束: {{ slice .endsAt 0 10 }} {{ slice .endsAt 11 19 }}{{ else }}时间: {{ slice .startsAt 0 10 }} {{ slice .startsAt 11 19 }}\n当前值: {{ .annotations.value }}{{ end }}\n详情: {{ .annotations.description }}",
                "url": "https://alert.prd.emal.cc/",
                "picurl": "https://package.prd.emal.cc/package/img/prometheus-alter.png"
            }
            {{ end }}
        ]
    }
}

prometheus-alert-05.png

# 企业微信文本格式
{
    "msgtype": "markdown",
    "markdown": {
        "content": "{{ range .alerts }}{{ if eq .status "resolved" }}**✅【已恢复】** **{{ .labels.alertname }}**\n\n**级别**: **{{ .labels.severity }}**\n**主机**: **{{ .labels.instance }}**\n**开始**: **{{ slice .startsAt 0 10 }} {{ slice .startsAt 11 19 }}**\n**结束**: **{{ slice .endsAt 0 10 }} {{ slice .endsAt 11 19 }}**\n**详情**: **{{ .annotations.description }}**\n{{ else }}**🚨【告警通知】** **{{ .labels.alertname }}**\n\n**级别**: **{{ .labels.severity }}**\n**主机**: **{{ .labels.instance }}**\n**时间**: **{{ slice .startsAt 0 10 }} {{ slice .startsAt 11 19 }}**\n**当前值**: **{{ .annotations.value }}**\n**详情**: **{{ .annotations.description }}**\n{{ end }}{{ end }}"
    }
}
alertmanager.yml配置

prometheus-alert-06.png

docker-compose restart alertmanager
0

评论 (0)

取消