From c4608e30b6f1c6f60023550e26dc2808eb4ff199 Mon Sep 17 00:00:00 2001 From: Cairry Date: Sat, 22 Feb 2025 14:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=E6=AD=A3=E5=88=99=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E5=8C=B9=E9=85=8D=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B4=9F=E6=95=B0=E5=92=8C=E5=B0=8F=E6=95=B0=E7=82=B9=20(#136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alert/consumer/consumer.go | 1 - pkg/tools/cmd.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/alert/consumer/consumer.go b/alert/consumer/consumer.go index 15904d4..b8af6cf 100644 --- a/alert/consumer/consumer.go +++ b/alert/consumer/consumer.go @@ -198,7 +198,6 @@ func (c *Consume) executeTask(faultCenter models.FaultCenter, taskChan chan stru // 事件分组 var alertGroups AlertGroups c.alarmGrouping(faultCenter, &alertGroups, filterEvents) - fmt.Println("alertGroups->", tools.JsonMarshal(alertGroups.Rules)) // 事件聚合 aggEvents := c.alarmAggregation(faultCenter, &alertGroups) // 发送事件 diff --git a/pkg/tools/cmd.go b/pkg/tools/cmd.go index 5172b04..93896af 100644 --- a/pkg/tools/cmd.go +++ b/pkg/tools/cmd.go @@ -152,8 +152,8 @@ func ProcessRuleExpr(ruleExpr string) (string, float64, error) { // 去除空格 trimmedExpr := strings.ReplaceAll(ruleExpr, " ", "") - // 正则表达式匹配 - re := regexp.MustCompile(`([^\d]+)(\d+)`) + // 正则表达式匹配,支持负数和小数点 + re := regexp.MustCompile(`([^\d\-]+)(-?\d+(?:\.\d+)?)`) matches := re.FindStringSubmatch(trimmedExpr) if len(matches) < 3 { return "", 0, fmt.Errorf("无效的表达式: %s", ruleExpr)