filter message stats api

This commit is contained in:
liugq 2022-06-05 17:30:29 +08:00
parent bd1e982e61
commit 7b26184469
1 changed files with 18 additions and 9 deletions

View File

@ -81,19 +81,28 @@ func (h *AlertAPI) ignoreAlertMessage(w http.ResponseWriter, req *http.Request,
func (h *AlertAPI) getAlertMessageStats(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
esClient := elastic.GetClient(h.Config.Elasticsearch)
must := []util.MapStr{
{
"terms": util.MapStr{
"status": []string{
alerting.MessageStateAlerting,
},
},
},
}
clusterFilter, hasAllPrivilege := h.GetClusterFilter(req, "resource_id")
if !hasAllPrivilege && clusterFilter == nil {
h.WriteJSON(w, elastic.SearchResponse{}, http.StatusOK)
return
}
if !hasAllPrivilege {
must = append(must,clusterFilter)
}
queryDsl := util.MapStr{
"size": 0,
"query": util.MapStr{
"bool": util.MapStr{
"must": []util.MapStr{
{
"terms": util.MapStr{
"status": []string{
alerting.MessageStateAlerting,
},
},
},
},
"must": must,
},
},
"aggs": util.MapStr{