diff --git a/internal/models/alertgroup.go b/internal/models/alertgroup.go index b130ed2d5..c9703dd59 100644 --- a/internal/models/alertgroup.go +++ b/internal/models/alertgroup.go @@ -33,12 +33,13 @@ func (a AlertList) Less(i, j int) bool { // There is a hash computed from all alerts, it's used by UI to quickly tell // if there was any change in a group and it needs to refresh it type AlertGroup struct { - Receiver string `json:"receiver"` - Labels map[string]string `json:"labels"` - Alerts AlertList `json:"alerts"` - ID string `json:"id"` - Hash string `json:"hash"` - StateCount map[string]int `json:"stateCount"` + Receiver string `json:"receiver"` + Labels map[string]string `json:"labels"` + Alerts AlertList `json:"alerts"` + ID string `json:"id"` + Hash string `json:"hash"` + AlertmanagerCount map[string]int `json:"alertmanagerCount"` + StateCount map[string]int `json:"stateCount"` } // LabelsFingerprint is a checksum of this AlertGroup labels and the receiver diff --git a/views.go b/views.go index b65466222..3ae6ec022 100644 --- a/views.go +++ b/views.go @@ -84,11 +84,12 @@ func alerts(c *gin.Context) { var matches int for _, ag := range dedupedAlerts { agCopy := models.AlertGroup{ - ID: ag.ID, - Receiver: ag.Receiver, - Labels: ag.Labels, - Alerts: []models.Alert{}, - StateCount: map[string]int{}, + ID: ag.ID, + Receiver: ag.Receiver, + Labels: ag.Labels, + Alerts: []models.Alert{}, + AlertmanagerCount: map[string]int{}, + StateCount: map[string]int{}, } for _, s := range models.AlertStateList { agCopy.StateCount[s] = 0 @@ -127,6 +128,14 @@ func alerts(c *gin.Context) { agCopy.StateCount[alert.State]++ + for _, am := range alert.Alertmanager { + if _, found := agCopy.AlertmanagerCount[am.Name]; !found { + agCopy.AlertmanagerCount[am.Name] = 1 + } else { + agCopy.AlertmanagerCount[am.Name]++ + } + } + for key, value := range alert.Labels { if keyMap, foundKey := dedupedColors[key]; foundKey { if color, foundColor := keyMap[value]; foundColor {