mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
feat(api): expose the number of matched alerts on /silences.json
This commit is contained in:
@@ -475,6 +475,25 @@ func silences(c *gin.Context) {
|
||||
return dedupedSilences[i].Silence.EndsAt.Before(dedupedSilences[j].Silence.EndsAt) == recentFirst
|
||||
})
|
||||
|
||||
silenceCounters := make(map[string]int, len(dedupedSilences))
|
||||
for _, silence := range dedupedSilences {
|
||||
silenceCounters[silence.Silence.ID] = 0
|
||||
}
|
||||
for _, alertGroup := range alertmanager.DedupAlerts() {
|
||||
for _, alert := range alertGroup.Alerts {
|
||||
for _, sID := range alert.SilencedBy {
|
||||
if _, ok := silenceCounters[sID]; ok {
|
||||
silenceCounters[sID]++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := range dedupedSilences {
|
||||
if counter, ok := silenceCounters[dedupedSilences[i].Silence.ID]; ok {
|
||||
dedupedSilences[i].AlertCount = counter
|
||||
}
|
||||
}
|
||||
|
||||
data, err := json.Marshal(dedupedSilences)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
|
||||
@@ -27,7 +27,8 @@ type Silence struct {
|
||||
|
||||
// ManagedSilence is a standalone silence detached from any alert
|
||||
type ManagedSilence struct {
|
||||
Cluster string `json:"cluster"`
|
||||
IsExpired bool `json:"isExpired"`
|
||||
Silence Silence `json:"silence"`
|
||||
Cluster string `json:"cluster"`
|
||||
IsExpired bool `json:"isExpired"`
|
||||
AlertCount int `json:"alertCount"`
|
||||
Silence Silence `json:"silence"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user