also hide inhibited alerts (#1039)

* also hide inhibited alerts

* split inhibited and silenced
This commit is contained in:
Carlos Alexandro Becker 2017-10-17 06:49:59 -02:00 committed by stuart nelson
parent 4a8e710691
commit 26489b13ef
1 changed files with 23 additions and 3 deletions

View File

@ -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,