fixed alerting bug
This commit is contained in:
parent
2c07a3f535
commit
8cfea1fc36
|
@ -31,7 +31,7 @@ func (h *AlertAPI) ignoreAlertMessage(w http.ResponseWriter, req *http.Request,
|
|||
}
|
||||
|
||||
if len(body.Messages) == 0 {
|
||||
h.WriteError(w, "alert ids should not be empty", http.StatusInternalServerError)
|
||||
h.WriteError(w, "messages should not be empty", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
messageIDs := make([]string, 0, len(body.Messages))
|
||||
|
@ -67,17 +67,9 @@ func (h *AlertAPI) ignoreAlertMessage(w http.ResponseWriter, req *http.Request,
|
|||
log.Error(err)
|
||||
return
|
||||
}
|
||||
//update kv cache
|
||||
//delete kv cache
|
||||
for _, msg := range body.Messages {
|
||||
stateBytes, err := kv.GetValue(alerting2.KVLastMessageState, []byte(msg.RuleID))
|
||||
if err != nil && stateBytes != nil {
|
||||
message := &alerting.AlertMessage{}
|
||||
util.MustFromJSONBytes(stateBytes, message)
|
||||
if message.Status == alerting.MessageStateAlerting {
|
||||
message.Status = alerting.MessageStateIgnored
|
||||
_ = kv.AddValue(alerting2.KVLastMessageState, []byte(msg.RuleID), util.MustToJSONBytes(message))
|
||||
}
|
||||
}
|
||||
_ = kv.DeleteKey(alerting2.KVLastMessageState, []byte(msg.RuleID))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -547,14 +547,18 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
|
|||
}
|
||||
}
|
||||
if alertItem != nil {
|
||||
for _, actionResult := range alertItem.ActionExecutionResults {
|
||||
if actionResult.Error != "" {
|
||||
alertItem.Error = actionResult.Error
|
||||
if err != nil{
|
||||
alertItem.State = alerting.AlertStateError
|
||||
alertItem.Error = err.Error()
|
||||
}else {
|
||||
for _, actionResult := range alertItem.ActionExecutionResults {
|
||||
if actionResult.Error != "" {
|
||||
alertItem.Error = actionResult.Error
|
||||
alertItem.State = alerting.AlertStateError
|
||||
}
|
||||
}
|
||||
}
|
||||
if alertItem.Error != ""{
|
||||
alertItem.State = alerting.AlertStateError
|
||||
}
|
||||
|
||||
err = orm.Save(alertItem)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
@ -976,19 +980,19 @@ func getLastAlertMessage(ruleID string, duration time.Duration) (*alerting.Alert
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if messageBytes == nil {
|
||||
return nil, nil
|
||||
}
|
||||
message := &alerting.AlertMessage{}
|
||||
err = util.FromJSONBytes(messageBytes, message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if messageBytes != nil {
|
||||
|
||||
err = util.FromJSONBytes(messageBytes, message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if time.Now().Sub(message.Updated) <= duration {
|
||||
return message, nil
|
||||
}
|
||||
}
|
||||
if time.Now().Sub(message.Updated) > duration {
|
||||
err = getLastAlertMessageFromES(ruleID, message)
|
||||
return message, err
|
||||
}
|
||||
return message, nil
|
||||
err = getLastAlertMessageFromES(ruleID, message)
|
||||
return message, err
|
||||
}
|
||||
|
||||
func saveAlertMessageToES(message *alerting.AlertMessage) error {
|
||||
|
|
Loading…
Reference in New Issue