fix wrong channel name

This commit is contained in:
liugq 2023-08-21 18:03:23 +08:00
parent 2a1df9743e
commit 174126fa10
2 changed files with 18 additions and 11 deletions

View File

@ -470,7 +470,7 @@ func getMessageNotificationStats(msg *alerting.AlertMessage )(util.MapStr, error
}, },
}, },
"_source": util.MapStr{ "_source": util.MapStr{
"includes": []string{"created", "action_execution_results.channel_name"}, "includes": []string{"created", "action_execution_results.channel_name", "action_execution_results.channel_type"},
}, },
"size": 1, "size": 1,
}, },
@ -493,7 +493,7 @@ func getMessageNotificationStats(msg *alerting.AlertMessage )(util.MapStr, error
}, },
}, },
"_source": util.MapStr{ "_source": util.MapStr{
"includes": []string{"created", "escalation_action_results.channel_name"}, "includes": []string{"created", "escalation_action_results.channel_name", "escalation_action_results.channel_type"},
}, },
"size": 1, "size": 1,
}, },
@ -518,7 +518,7 @@ func getMessageNotificationStats(msg *alerting.AlertMessage )(util.MapStr, error
}, },
}, },
"_source": util.MapStr{ "_source": util.MapStr{
"includes": []string{"created", "recover_action_results.channel_name"}, "includes": []string{"created", "recover_action_results.channel_name", "recover_action_results.channel_type"},
}, },
"size": 1, "size": 1,
}, },
@ -575,7 +575,13 @@ func extractStatsFromRaw(searchRawRes []byte, grpKey string, actionKey string) [
statsItem := util.MapStr{} statsItem := util.MapStr{}
statsItem["channel_type"], _ = jsonparser.GetString(value, "key") statsItem["channel_type"], _ = jsonparser.GetString(value, "key")
statsItem["count"], _ = jsonparser.GetInt(value, "doc_count") statsItem["count"], _ = jsonparser.GetInt(value, "doc_count")
statsItem["channel_name"], _ = jsonparser.GetString(value, "top", "hits","hits", "[0]", "_source",actionKey, "[0]", "channel_name") jsonparser.ArrayEach(value, func(v []byte, dataType jsonparser.ValueType, offset int, err error) {
ck, _ := jsonparser.GetString(v, "channel_type")
cn, _ := jsonparser.GetString(v, "channel_name")
if ck == statsItem["channel_type"] {
statsItem["channel_name"] = cn
}
}, "top", "hits","hits", "[0]", "_source",actionKey)
statsItem["last_time"], _ = jsonparser.GetString(value, "top", "hits","hits", "[0]", "_source","created") statsItem["last_time"], _ = jsonparser.GetString(value, "top", "hits","hits", "[0]", "_source","created")
stats = append(stats, statsItem) stats = append(stats, statsItem)
}, "aggregations", grpKey, "buckets") }, "aggregations", grpKey, "buckets")

View File

@ -822,6 +822,9 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
if alertMessage == nil || period > periodDuration { if alertMessage == nil || period > periodDuration {
actionResults, _ := performChannels(notifyCfg.Normal, paramsCtx, false) actionResults, _ := performChannels(notifyCfg.Normal, paramsCtx, false)
if rule.ID == "builtin-calaqnh7h710dpnp2bm8" {
log.Info(actionResults)
}
alertItem.ActionExecutionResults = actionResults alertItem.ActionExecutionResults = actionResults
//change and save last notification time in local kv store when action error count equals zero //change and save last notification time in local kv store when action error count equals zero
rule.LastNotificationTime = time.Now() rule.LastNotificationTime = time.Now()
@ -851,16 +854,14 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
} }
} }
if time.Now().Sub(rule.LastEscalationTime.Local()) > periodDuration { if time.Now().Sub(rule.LastEscalationTime.Local()) > periodDuration {
actionResults, errCount := performChannels(notifyCfg.Escalation, paramsCtx, false) actionResults, _ := performChannels(notifyCfg.Escalation, paramsCtx, false)
alertItem.EscalationActionResults = actionResults alertItem.EscalationActionResults = actionResults
//todo init last escalation time when create task (by last alert item is escalated) //todo init last escalation time when create task (by last alert item is escalated)
if errCount == 0 {
rule.LastEscalationTime = time.Now() rule.LastEscalationTime = time.Now()
alertItem.IsEscalated = true alertItem.IsEscalated = true
strTime := rule.LastEscalationTime.UTC().Format(time.RFC3339) strTime := rule.LastEscalationTime.UTC().Format(time.RFC3339)
kv.AddValue(alerting2.KVLastEscalationTime, []byte(rule.ID), []byte(strTime)) kv.AddValue(alerting2.KVLastEscalationTime, []byte(rule.ID), []byte(strTime))
} }
}
} }
} }