update acknowledge api
This commit is contained in:
parent
57d5dbc662
commit
6ac22f53a3
|
@ -21,7 +21,7 @@ type Rule struct {
|
||||||
Schedule Schedule `json:"schedule" elastic_mapping:"schedule:{type:object}"`
|
Schedule Schedule `json:"schedule" elastic_mapping:"schedule:{type:object}"`
|
||||||
LastNotificationTime time.Time `json:"-" elastic_mapping:"last_notification_time:{type:date}"`
|
LastNotificationTime time.Time `json:"-" elastic_mapping:"last_notification_time:{type:date}"`
|
||||||
LastTermStartTime time.Time `json:"-"` //标识最近一轮告警的开始时间
|
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 }"`
|
SearchText string `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,16 @@ func (h *AlertAPI) acknowledgeAlert(w http.ResponseWriter, req *http.Request, ps
|
||||||
body := struct {
|
body := struct {
|
||||||
AlertIDs []string `json:"ids"`
|
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{
|
queryDsl := util.MapStr{
|
||||||
"query": util.MapStr{
|
"query": util.MapStr{
|
||||||
"terms": 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),
|
"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 {
|
if err != nil {
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|
Loading…
Reference in New Issue