Commit 0f75550a authored by Adam Harrison's avatar Adam Harrison
Browse files

Dedupe and sort names of blocking alerts

parent b0259b6c
......@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"sort"
"time"
"github.com/prometheus/client_golang/api/prometheus"
......@@ -27,14 +28,21 @@ func PrometheusActiveAlerts(prometheusURL string, filter *regexp.Regexp) ([]stri
if value.Type() == model.ValVector {
if vector, ok := value.(model.Vector); ok {
var activeAlerts []string
activeAlertSet := make(map[string]bool)
for _, sample := range vector {
if alertName, isAlert := sample.Metric[model.AlertNameLabel]; isAlert && sample.Value != 0 {
if filter == nil || !filter.MatchString(string(alertName)) {
activeAlerts = append(activeAlerts, string(alertName))
activeAlertSet[string(alertName)] = true
}
}
}
var activeAlerts []string
for activeAlert, _ := range activeAlertSet {
activeAlerts = append(activeAlerts, activeAlert)
}
sort.Sort(sort.StringSlice(activeAlerts))
return activeAlerts, nil
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment