forked from AcalephStorage/consul-alerts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
198 lines (163 loc) · 4.27 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package consul
import (
"time"
notifier "github.com/AcalephStorage/consul-alerts/notifier"
)
// Event data from consul
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 *notifier.Notifiers
}
type ChecksConfig struct {
Enabled bool
ChangeThreshold int
}
type EventsConfig struct {
Enabled bool
Handlers []string
}
type Status struct {
Current string
CurrentTimestamp time.Time
Pending string
PendingTimestamp time.Time
HealthCheck *Check
ForNotification bool
}
// ProfileInfo is for reading in JSON from profile keys
type ProfileInfo struct {
Interval int
NotifList map[string]bool
VarOverrides notifier.Notifiers
}
// Consul interface provides access to consul client
type Consul interface {
LoadConfig()
EventsEnabled() bool
ChecksEnabled() bool
EventHandlers(eventName string) []string
EmailNotifier() *notifier.EmailNotifier
LogNotifier() *notifier.LogNotifier
InfluxdbNotifier() *notifier.InfluxdbNotifier
SlackNotifier() *notifier.SlackNotifier
MattermostNotifier() *notifier.MattermostNotifier
MattermostWebhookNotifier() *notifier.MattermostWebhookNotifier
PagerDutyNotifier() *notifier.PagerDutyNotifier
HipChatNotifier() *notifier.HipChatNotifier
OpsGenieNotifier() *notifier.OpsGenieNotifier
AwsSnsNotifier() *notifier.AwsSnsNotifier
VictorOpsNotifier() *notifier.VictorOpsNotifier
ILertNotifier() *notifier.ILertNotifier
CheckChangeThreshold() int
UpdateCheckData()
NewAlerts() []Check
NewAlertsWithFilter(node string, service string, checkId string, statuses []string, ignoreBlacklist bool) []Check
IsBlacklisted(check *Check) bool
CustomNotifiers() map[string]string
CheckStatus(node, statusId, checkId string) (status, output string)
CheckKeyExists(key string) bool
GetProfileInfo(node, serviceID, checkID string) ProfileInfo
GetReminders() []notifier.Message
SetReminder(m notifier.Message)
DeleteReminder(node string, checkid string)
}
// DefaultAlertConfig loads default config settings
func DefaultAlertConfig() *ConsulAlertConfig {
checks := &ChecksConfig{
Enabled: true,
ChangeThreshold: 60,
}
events := &EventsConfig{
Enabled: true,
Handlers: []string{},
}
email := ¬ifier.EmailNotifier{
ClusterName: "Consul-Alerts",
Enabled: false,
SenderAlias: "Consul Alerts",
Receivers: []string{},
}
log := ¬ifier.LogNotifier{
Enabled: true,
Path: "/tmp/consul-notifications.log",
}
influxdb := ¬ifier.InfluxdbNotifier{
Enabled: false,
SeriesName: "consul-alerts",
}
slack := ¬ifier.SlackNotifier{
Enabled: false,
ClusterName: "Consul-Alerts",
}
mattermost := ¬ifier.MattermostNotifier{
Enabled: false,
ClusterName: "Consul-Alerts",
}
mattermostWebhook := ¬ifier.MattermostWebhookNotifier{
Enabled: false,
ClusterName: "Consul-Alerts",
}
pagerduty := ¬ifier.PagerDutyNotifier{
Enabled: false,
}
hipchat := ¬ifier.HipChatNotifier{
Enabled: false,
ClusterName: "Consul-Alerts",
}
opsgenie := ¬ifier.OpsGenieNotifier{
Enabled: false,
ClusterName: "Consul-Alerts",
}
awsSns := ¬ifier.AwsSnsNotifier{
Enabled: false,
ClusterName: "Consul-Alerts",
}
victorOps := ¬ifier.VictorOpsNotifier{
Enabled: false,
}
ilert := ¬ifier.ILertNotifier{
Enabled: false,
IncidentKeyTemplate: "{{.Node}}:{{.Service}}:{{.Check}}",
}
notifiers := ¬ifier.Notifiers{
Email: email,
Log: log,
Influxdb: influxdb,
Slack: slack,
Mattermost: mattermost,
MattermostWebhook: mattermostWebhook,
PagerDuty: pagerduty,
HipChat: hipchat,
OpsGenie: opsgenie,
AwsSns: awsSns,
VictorOps: victorOps,
ILert: ilert,
Custom: []string{},
}
return &ConsulAlertConfig{
Checks: checks,
Events: events,
Notifiers: notifiers,
}
}