From 7b261844696cabed3fda62bae2a6e5ae549a31d7 Mon Sep 17 00:00:00 2001 From: liugq Date: Sun, 5 Jun 2022 17:30:29 +0800 Subject: [PATCH] filter message stats api --- plugin/api/alerting/message.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/plugin/api/alerting/message.go b/plugin/api/alerting/message.go index eee5e1be..3f6e6db4 100644 --- a/plugin/api/alerting/message.go +++ b/plugin/api/alerting/message.go @@ -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{