forked from AcalephStorage/consul-alerts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
181 lines (151 loc) · 3.19 KB
/
interface.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package consul
import "time"
type Event struct {
ID string
Name string
Payload []byte
NodeFilter string
ServiceFilter string
TagFilter string
Version uint
LTime uint
}
type Check struct {
Node string
CheckID string
Name string
Status string
Notes string
Output string
ServiceID string
ServiceName string
}
type ConsulAlertConfig struct {
Checks *ChecksConfig
Events *EventsConfig
Notifiers *NotifiersConfig
}
type ChecksConfig struct {
Enabled bool
ChangeThreshold int
}
type EventsConfig struct {
Enabled bool
Handlers []string
}
type NotifiersConfig struct {
Email *EmailNotifierConfig
Log *LogNotifierConfig
Influxdb *InfluxdbNotifierConfig
Slack *SlackNotifierConfig
PagerDuty *PagerDutyNotifierConfig
Custom []string
}
type EmailNotifierConfig struct {
ClusterName string
Enabled bool
Url string
Port int
Username string
Password string
SenderAlias string
SenderEmail string
Receivers []string
Template string
}
type LogNotifierConfig struct {
Enabled bool
Path string
}
type InfluxdbNotifierConfig struct {
Enabled bool
Host string
Username string
Password string
Database string
SeriesName string
}
type SlackNotifierConfig struct {
Enabled bool
ClusterName string
Url string
Channel string
Username string
IconUrl string
IconEmoji string
}
type PagerDutyNotifierConfig struct {
Enabled bool
ServiceKey string
ClientName string
ClientUrl string
}
type Status struct {
Current string
CurrentTimestamp time.Time
Pending string
PendingTimestamp time.Time
HealthCheck *Check
ForNotification bool
}
type Consul interface {
LoadConfig()
EventsEnabled() bool
ChecksEnabled() bool
EventHandlers(eventName string) []string
EmailConfig() *EmailNotifierConfig
LogConfig() *LogNotifierConfig
InfluxdbConfig() *InfluxdbNotifierConfig
SlackConfig() *SlackNotifierConfig
PagerDutyConfig() *PagerDutyNotifierConfig
CheckChangeThreshold() int
UpdateCheckData()
NewAlerts() []Check
IsBlacklisted(check *Check) bool
CustomNotifiers() []string
CheckStatus(node, statusId, checkId string) (status, output string)
}
func DefaultAlertConfig() *ConsulAlertConfig {
checks := &ChecksConfig{
Enabled: true,
ChangeThreshold: 60,
}
events := &EventsConfig{
Enabled: true,
Handlers: []string{},
}
email := &EmailNotifierConfig{
ClusterName: "Consul-Alerts",
Enabled: false,
SenderAlias: "Consul Alerts",
Receivers: []string{},
}
log := &LogNotifierConfig{
Enabled: true,
Path: "/tmp/consul-notifications.log",
}
influxdb := &InfluxdbNotifierConfig{
Enabled: false,
SeriesName: "consul-alerts",
}
slack := &SlackNotifierConfig{
Enabled: false,
ClusterName: "Consul-Alerts",
}
pagerduty := &PagerDutyNotifierConfig{
Enabled: false,
}
notifiers := &NotifiersConfig{
Email: email,
Log: log,
Influxdb: influxdb,
Slack: slack,
PagerDuty: pagerduty,
Custom: []string{},
}
return &ConsulAlertConfig{
Checks: checks,
Events: events,
Notifiers: notifiers,
}
}