also hide inhibited alerts (#1039)
* also hide inhibited alerts * split inhibited and silenced
This commit is contained in:
parent
4a8e710691
commit
26489b13ef
26
api/api.go
26
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,
|
||||
|
|
Loading…
Reference in New Issue