-
Notifications
You must be signed in to change notification settings - Fork 9
/
notification.go
87 lines (72 loc) · 2.7 KB
/
notification.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
package cloud66
type NotificationUploadParams struct {
Alerts []Notification `json:"alerts"`
ApplicationGroupName string `json:"application_group_name,omitempty"`
}
type NotificationSubscription struct {
Channel string `json:"channel"`
SlackUrl string `json:"slack_url,omitempty" yaml:"slack_url,omitempty"`
WebookUrl string `json:"webhook_url,omitempty" yaml:"webhook_url,omitempty"`
}
type Notification struct {
Name string `json:"alert_name"`
Subscriptions []NotificationSubscription `json:"subscriptions,omitempty"`
}
type NotificationResponse struct {
Alerts []string `json:"alerts"`
Count int `json:"count"`
}
type NotificationResponseFailureBody struct {
Alert string `json:"alert_name"`
Reason string `json:"reason"`
}
type NotificationResponseFailure struct {
Alerts []NotificationResponseFailureBody `json:"alerts"`
Count int `json:"count"`
}
type NotificationResponseBody struct {
Successes NotificationResponse `json:"successes"`
NotApplicable NotificationResponseFailure `json:"not_applicable"`
Failures NotificationResponseFailure `json:"failures"`
}
func (c *Client) NotificationDownload(stackUid string) ([]Notification, error) {
var notifications []Notification
req, err := c.NewRequest("GET", "/stacks/"+stackUid+"/notifications", nil, nil)
if err != nil {
return nil, err
}
err = c.DoReq(req, ¬ifications, nil)
if err != nil {
return nil, err
}
return notifications, nil
}
func (c *Client) NotificationUploadStack(targetStackUid string, alerts []Notification) (*NotificationResponseBody, error) {
var notificationUploadParams NotificationUploadParams
notificationUploadParams.Alerts = alerts
return c.NotificationUpload(notificationUploadParams, &targetStackUid)
}
func (c *Client) NotificationUploadApplicationGroup(targetUid string, alerts []Notification) (*NotificationResponseBody, error) {
var notificationUploadParams NotificationUploadParams
notificationUploadParams.Alerts = alerts
notificationUploadParams.ApplicationGroupName = targetUid
return c.NotificationUpload(notificationUploadParams, nil)
}
func (c *Client) NotificationUpload(notification NotificationUploadParams, targetStackUid *string) (*NotificationResponseBody, error) {
var notifications NotificationResponseBody
var requestPath string
if targetStackUid != nil {
requestPath = "/stacks/" + *targetStackUid + "/notifications"
} else {
requestPath = "/application_groups/notifications"
}
req, err := c.NewRequest("PATCH", requestPath, notification, nil)
if err != nil {
return nil, err
}
err = c.DoReq(req, ¬ifications, nil)
if err != nil {
return nil, err
}
return ¬ifications, nil
}