From 657cb162ccf2b6efaa5f0cb7df88a237ad548310 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 12 Oct 2017 09:57:06 -0300 Subject: [PATCH 1/2] also hide inhibited alerts --- api/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/api.go b/api/api.go index 2a10f764bb..108bd67be0 100644 --- a/api/api.go +++ b/api/api.go @@ -342,6 +342,9 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { if !showSilenced && len(status.SilencedBy) != 0 { continue } + if !showSilenced && len(status.InhibitedBy) != 0 { + continue + } apiAlert := &dispatch.APIAlert{ Alert: &a.Alert, From 2f96f3aa7861b60ce1c5e1384ec62a0c647fe8f5 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 13 Oct 2017 12:03:06 -0300 Subject: [PATCH 2/2] split inhibited and silenced --- api/api.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/api/api.go b/api/api.go index 108bd67be0..a55e4977d1 100644 --- a/api/api.go +++ b/api/api.go @@ -264,9 +264,10 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { re *regexp.Regexp // Initialize result slice to prevent api returning `null` when there // are no alerts present - res = []*dispatch.APIAlert{} - matchers = []*labels.Matcher{} - showSilenced = true + res = []*dispatch.APIAlert{} + matchers = []*labels.Matcher{} + showSilenced = true + showInhibited = true ) if filter := r.FormValue("filter"); filter != "" { @@ -295,6 +296,21 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { } } + if inhibitedParam := r.FormValue("inhibited"); inhibitedParam != "" { + if inhibitedParam == "false" { + showInhibited = false + } else if inhibitedParam != "true" { + respondError(w, apiError{ + typ: errorBadData, + err: fmt.Errorf( + "parameter 'inhibited' can either be 'true' or 'false', not '%v'", + inhibitedParam, + ), + }, nil) + return + } + } + if receiverParam := r.FormValue("receiver"); receiverParam != "" { re, err = regexp.Compile("^(?:" + receiverParam + ")$") if err != nil { @@ -342,7 +358,8 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { if !showSilenced && len(status.SilencedBy) != 0 { continue } - if !showSilenced && len(status.InhibitedBy) != 0 { + + if !showInhibited && len(status.InhibitedBy) != 0 { continue }