-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathnotification_groups.go
63 lines (53 loc) · 2.38 KB
/
notification_groups.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
package mackerel
import "fmt"
// NotificationLevel represents a level of notification.
type NotificationLevel string
// NotificationLevels
const (
NotificationLevelAll NotificationLevel = "all"
NotificationLevelCritical NotificationLevel = "critical"
)
// NotificationGroup represents a Mackerel notification group.
// ref. https://mackerel.io/api-docs/entry/notification-groups
type NotificationGroup struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
NotificationLevel NotificationLevel `json:"notificationLevel"`
ChildNotificationGroupIDs []string `json:"childNotificationGroupIds"`
ChildChannelIDs []string `json:"childChannelIds"`
Monitors []*NotificationGroupMonitor `json:"monitors,omitempty"`
Services []*NotificationGroupService `json:"services,omitempty"`
}
// NotificationGroupMonitor represents a notification target monitor rule.
type NotificationGroupMonitor struct {
ID string `json:"id"`
SkipDefault bool `json:"skipDefault"`
}
// NotificationGroupService represents a notification target service.
type NotificationGroupService struct {
Name string `json:"name"`
}
// FindNotificationGroups finds notification groups.
func (c *Client) FindNotificationGroups() ([]*NotificationGroup, error) {
data, err := requestGet[struct {
NotificationGroups []*NotificationGroup `json:"notificationGroups"`
}](c, "/api/v0/notification-groups")
if err != nil {
return nil, err
}
return data.NotificationGroups, nil
}
// CreateNotificationGroup creates a notification group.
func (c *Client) CreateNotificationGroup(param *NotificationGroup) (*NotificationGroup, error) {
return requestPost[NotificationGroup](c, "/api/v0/notification-groups", param)
}
// UpdateNotificationGroup updates a notification group.
func (c *Client) UpdateNotificationGroup(id string, param *NotificationGroup) (*NotificationGroup, error) {
path := fmt.Sprintf("/api/v0/notification-groups/%s", id)
return requestPut[NotificationGroup](c, path, param)
}
// DeleteNotificationGroup deletes a notification group.
func (c *Client) DeleteNotificationGroup(id string) (*NotificationGroup, error) {
path := fmt.Sprintf("/api/v0/notification-groups/%s", id)
return requestDelete[NotificationGroup](c, path)
}