forked from prymitive/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalerts.go
62 lines (54 loc) · 1.58 KB
/
alerts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"github.com/prymitive/karma/internal/alertmanager"
"github.com/prymitive/karma/internal/filters"
"github.com/prymitive/karma/internal/models"
"github.com/prymitive/karma/internal/slices"
log "github.com/sirupsen/logrus"
)
func getFiltersFromQuery(filterStrings []string) ([]filters.FilterT, bool) {
validFilters := false
matchFilters := []filters.FilterT{}
for _, filterExpression := range filterStrings {
f := filters.NewFilter(filterExpression)
if f.GetIsValid() {
validFilters = true
}
matchFilters = append(matchFilters, f)
}
return matchFilters, validFilters
}
func getUpstreams() models.AlertmanagerAPISummary {
summary := models.AlertmanagerAPISummary{}
clusters := map[string][]string{}
upstreams := alertmanager.GetAlertmanagers()
for _, upstream := range upstreams {
members := upstream.ClusterMemberNames()
key, err := slices.StringSliceToSHA1(members)
if err != nil {
log.Errorf("slices.StringSliceToSHA1 error: %s", err)
continue
}
if _, found := clusters[key]; !found {
clusters[key] = members
}
u := models.AlertmanagerAPIStatus{
Name: upstream.Name,
URI: upstream.SanitizedURI(),
PublicURI: upstream.PublicURI(),
Error: upstream.Error(),
Version: upstream.Version(),
Cluster: upstream.ClusterID(),
ClusterMembers: members,
}
summary.Instances = append(summary.Instances, u)
summary.Counters.Total++
if u.Error == "" {
summary.Counters.Healthy++
} else {
summary.Counters.Failed++
}
}
summary.Clusters = clusters
return summary
}