fix(monitor): dedupe alert trigger condition in notify templates (#24780)

This commit is contained in:
Zexi Li
2026-05-07 15:52:51 +08:00
committed by GitHub
parent c35e95046d
commit b5cf4bb575
3 changed files with 4 additions and 8 deletions
@@ -1,9 +1,7 @@
策略名称: {{.name}}
触发时间: {{.start_time}}
报警级别: {{.level}}
触发条件:{{if eq (len .matches) 1}} {{(index .matches 0).condition | unescaped}}{{else}}
{{- range .matches}}- {{.condition | unescaped}}
{{- end}}{{end}}
触发条件: {{.description | unescaped}}
{{if .reason}}报警原因: {{.reason}}
{{end}}报警数量:{{len .matches}}
资源名称:{{.resource_name}}
@@ -1,9 +1,7 @@
AlertName: {{.name}}
Time: {{.start_time}}
Level: {{.level}}
TriggerCondition:{{if eq (len .matches) 1}} {{(index .matches 0).condition | unescaped}}{{else}}
{{- range .matches}}- {{.condition | unescaped}}
{{- end}}{{end}}
TriggerCondition: {{.description | unescaped}}
{{if .reason}}Reason: {{.reason}}
{{end}}AlertCount: {{len .matches}}
ResourceName: {{.resource_name}}
+2 -2
View File
@@ -212,12 +212,12 @@ func (c *EvalContext) GetNotificationTemplateConfig(matches []*monitor.EvalMatch
conds = append(conds, m.Condition)
}
if len(conds) > 0 {
desc = strings.Join(conds, " ")
desc = strings.Join(conds, ", ")
log.Debugf("[GetNotificationTemplateConfig] rule=%s matches=%d desc from match conditions: %s", c.Rule.Name, len(matches), desc)
}
} else if len(c.Rule.TriggeredMessages) > 0 {
// 兼容旧逻辑:如果没有按 match 填充 Condition,则退回到规则级 TriggeredMessages
desc = strings.Join(c.Rule.TriggeredMessages, " ")
desc = strings.Join(c.Rule.TriggeredMessages, ", ")
log.Debugf("[GetNotificationTemplateConfig] rule=%s matches=%d desc from TriggeredMessages (fallback): %s", c.Rule.Name, len(matches), desc)
}
if c.Error != nil {