diff --git a/api/api.go b/api/api.go index 2a10f764..a55e4977 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 { @@ -343,6 +359,10 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { continue } + if !showInhibited && len(status.InhibitedBy) != 0 { + continue + } + apiAlert := &dispatch.APIAlert{ Alert: &a.Alert, Status: status,