forked from ansrivas/consul-alerts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier.go
64 lines (55 loc) · 1.1 KB
/
notifier.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
63
64
package notifier
import "time"
const (
SYSTEM_HEALTHY string = "HEALTHY"
SYSTEM_UNSTABLE string = "UNSTABLE"
SYSTEM_CRITICAL string = "CRITICAL"
)
type Message struct {
Node string
ServiceId string
Service string
CheckId string
Check string
Status string
Output string
Notes string
Timestamp time.Time
}
type Messages []Message
type Notifier interface {
Notify(alerts Messages) bool
}
func (m Message) IsCritical() bool {
return m.Status == "critical"
}
func (m Message) IsWarning() bool {
return m.Status == "warning"
}
func (m Message) IsPassing() bool {
return m.Status == "passing"
}
func (m Messages) Summary() (overallStatus string, pass, warn, fail int) {
hasCritical := false
hasWarnings := false
for _, message := range m {
switch {
case message.IsCritical():
hasCritical = true
fail++
case message.IsWarning():
hasWarnings = true
warn++
case message.IsPassing():
pass++
}
}
if hasCritical {
overallStatus = SYSTEM_CRITICAL
} else if hasWarnings {
overallStatus = SYSTEM_UNSTABLE
} else {
overallStatus = SYSTEM_HEALTHY
}
return
}