diff --git a/model/alerting/rule.go b/model/alerting/rule.go index d8267bb3..508f8869 100644 --- a/model/alerting/rule.go +++ b/model/alerting/rule.go @@ -21,7 +21,7 @@ type Rule struct { Schedule Schedule `json:"schedule" elastic_mapping:"schedule:{type:object}"` LastNotificationTime time.Time `json:"-" elastic_mapping:"last_notification_time:{type:date}"` LastTermStartTime time.Time `json:"-"` //标识最近一轮告警的开始时间 - LastEscalationTime time.Time `json:"-"` //标识最近一轮告警的开始时间 + LastEscalationTime time.Time `json:"-"` //标识最近一次告警升级发送通知的时间 SearchText string `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"` } diff --git a/plugin/api/alerting/alert.go b/plugin/api/alerting/alert.go index 049c2de5..c8325e1a 100644 --- a/plugin/api/alerting/alert.go +++ b/plugin/api/alerting/alert.go @@ -47,6 +47,16 @@ func (h *AlertAPI) acknowledgeAlert(w http.ResponseWriter, req *http.Request, ps body := struct { AlertIDs []string `json:"ids"` }{} + err := h.DecodeJSON(req, &body) + if err != nil { + h.WriteError(w, err.Error(), http.StatusInternalServerError) + return + } + + if len(body.AlertIDs) == 0 { + h.WriteError(w, "alert ids should not be empty", http.StatusInternalServerError) + return + } queryDsl := util.MapStr{ "query": util.MapStr{ "terms": util.MapStr{ @@ -57,7 +67,7 @@ func (h *AlertAPI) acknowledgeAlert(w http.ResponseWriter, req *http.Request, ps "source": fmt.Sprintf("ctx._source['state'] = '%s'", alerting.AlertStateAcknowledge), }, } - err := orm.UpdateBy(alerting.Alert{}, util.MustToJSONBytes(queryDsl)) + err = orm.UpdateBy(alerting.Alert{}, util.MustToJSONBytes(queryDsl)) if err != nil { h.WriteError(w, err.Error(), http.StatusInternalServerError) log.Error(err)