/
notify.go
72 lines (61 loc) · 2.19 KB
/
notify.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
package monitor
// NotifyList wraps notifications.
type NotifyList struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Notifications []*Notification `json:"notify_list,omitempty"`
}
// Notification represents endpoint to alert to.
type Notification struct {
Type string `json:"type,omitempty"`
Config Config `json:"config,omitempty"`
}
// NewNotifyList returns a notify list that alerts via the given notifications.
func NewNotifyList(name string, nl ...*Notification) *NotifyList {
if nl == nil {
nl = []*Notification{}
}
return &NotifyList{Name: name, Notifications: nl}
}
// NewUserNotification returns a notification that alerts via user.
func NewUserNotification(username string) *Notification {
return &Notification{
Type: "user",
Config: Config{"user": username}}
}
// NewEmailNotification returns a notification that alerts via email.
func NewEmailNotification(email string) *Notification {
return &Notification{
Type: "email",
Config: Config{"email": email}}
}
// NewFeedNotification returns a notification that alerts via datafeed.
func NewFeedNotification(sourceID string) *Notification {
return &Notification{
Type: "datafeed",
Config: Config{"sourceid": sourceID}}
}
// NewWebNotification returns a notification that alerts via webhook.
func NewWebNotification(url string, headers map[string]string) *Notification {
return &Notification{
Type: "webhook",
Config: Config{"url": url, "headers": headers}}
}
// NewPagerDutyNotification returns a notification that alerts via pagerduty.
func NewPagerDutyNotification(key string) *Notification {
return &Notification{
Type: "pagerduty",
Config: Config{"service_key": key}}
}
// NewHipChatNotification returns a notification that alerts via hipchat.
func NewHipChatNotification(token, room string) *Notification {
return &Notification{
Type: "hipchat",
Config: Config{"token": token, "room": room}}
}
// NewSlackNotification returns a notification that alerts via slack.
func NewSlackNotification(url, username, channel string) *Notification {
return &Notification{
Type: "slack",
Config: Config{"url": url, "username": username, "channel": channel}}
}