mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
fix(monitor): dedupe alert trigger condition in notify templates (#24780)
This commit is contained in:
@@ -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}}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user