From 700d847bd46ffbfb43ec899438e4020def063e5f Mon Sep 17 00:00:00 2001 From: lvjianzhao Date: Fri, 30 Jan 2026 20:18:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(prometheusalert):=20=E8=AF=B7=E6=B1=82/prom?= =?UTF-8?q?etheusalert=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=AF=B7=E6=B1=82body?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E6=B3=95=E6=97=B6=E8=BF=94=E5=9B=9E=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E6=8A=A5=E9=94=99=EF=BC=8C=E8=80=8C=E9=9D=9E=E7=A9=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/prometheusalert.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/controllers/prometheusalert.go b/controllers/prometheusalert.go index c4de9ebe..33aedb66 100644 --- a/controllers/prometheusalert.go +++ b/controllers/prometheusalert.go @@ -80,6 +80,7 @@ type PrometheusAlertMsg struct { func (c *PrometheusAlertController) PrometheusAlert() { logsign := "[" + LogsSign() + "]" + var message string var p_json interface{} //针对prometheus的消息特殊处理 p_alertmanager_json := make(map[string]interface{}) @@ -107,7 +108,11 @@ func (c *PrometheusAlertController) PrometheusAlert() { AliyunAlertJson.Timestamp = c.Input().Get("timestamp") p_json = AliyunAlertJson } else { - json.Unmarshal(c.Ctx.Input.RequestBody, &p_json) + err := json.Unmarshal(c.Ctx.Input.RequestBody, &p_json) + if err != nil { + message = "请求body不是合法json." + logs.Error(logsign, message) + } //针对prometheus的消息特殊处理 json.Unmarshal(c.Ctx.Input.RequestBody, &p_alertmanager_json) } @@ -161,7 +166,6 @@ func (c *PrometheusAlertController) PrometheusAlert() { } } - var message string if pMsg.Type != "" && PrometheusAlertTpl != nil { //判断是否是来自 Prometheus的告警 if pMsg.Split != "false" && PrometheusAlertTpl.Tpluse == "Prometheus" {