mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-29 09:32:16 +00:00
Sort alerts consistently in web UI.
This commit is contained in:
parent
fa41146ce0
commit
55b390f049
@ -15,6 +15,7 @@ package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/prometheus/alertmanager/manager"
|
||||
)
|
||||
@ -35,9 +36,25 @@ func (h *AlertsHandler) silenceForAlert(a *manager.Alert) *manager.Silence {
|
||||
return silence
|
||||
}
|
||||
|
||||
type aggregatesByLabelset struct {
|
||||
manager.AlertAggregates
|
||||
}
|
||||
|
||||
func (aggs aggregatesByLabelset) Less(i, j int) bool {
|
||||
iAlert := aggs.AlertAggregates[i].Alert
|
||||
jAlert := aggs.AlertAggregates[j].Alert
|
||||
if iAlert.Name() == jAlert.Name() {
|
||||
return iAlert.Fingerprint() < jAlert.Fingerprint()
|
||||
}
|
||||
return iAlert.Name() < jAlert.Name()
|
||||
}
|
||||
|
||||
func (h *AlertsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
aggs := h.Manager.GetAll(nil)
|
||||
sort.Sort(aggregatesByLabelset{aggs})
|
||||
|
||||
alertStatus := &AlertStatus{
|
||||
AlertAggregates: h.Manager.GetAll(nil),
|
||||
AlertAggregates: aggs,
|
||||
SilenceForAlert: h.silenceForAlert,
|
||||
}
|
||||
executeTemplate(w, "alerts", alertStatus, h.PathPrefix)
|
||||
|
Loading…
Reference in New Issue
Block a user