/
runbook.go
56 lines (45 loc) · 1.24 KB
/
runbook.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
package alertmanager
import (
platformv1alpha1 "github.com/pluralsh/plural-operator/apis/platform/v1alpha1"
)
func removeAlert(alerts []*platformv1alpha1.RunbookAlertStatus, name string) []*platformv1alpha1.RunbookAlertStatus {
result := make([]*platformv1alpha1.RunbookAlertStatus, 0)
for _, alert := range alerts {
if alert.Name != name {
result = append(result, alert)
}
}
return result
}
func hasAlert(alerts []*platformv1alpha1.RunbookAlertStatus, name string) bool {
for _, alert := range alerts {
if alert.Name == name {
return true
}
}
return false
}
func replaceAlert(alerts []*platformv1alpha1.RunbookAlertStatus, alert *Alert) []*platformv1alpha1.RunbookAlertStatus {
result := make([]*platformv1alpha1.RunbookAlertStatus, 0)
name, _ := alert.Labels[nameLabel]
found := false
runbookAlert := &platformv1alpha1.RunbookAlertStatus{
Name: name,
StartsAt: alert.StartsAt,
Annotations: alert.Annotations,
Labels: alert.Labels,
Fingerprint: alert.Fingerprint,
}
for _, alert := range alerts {
if alert.Name != name {
result = append(result, alert)
continue
}
result = append(result, runbookAlert)
found = true
}
if !found {
result = append(result, runbookAlert)
}
return result
}