-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathalert_group_settings.go
More file actions
77 lines (65 loc) · 3.22 KB
/
Copy pathalert_group_settings.go
File metadata and controls
77 lines (65 loc) · 3.22 KB
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
package mackerel
import (
"context"
"fmt"
)
// AlertGroupSetting represents a Mackerel alert group setting.
// ref. https://mackerel.io/api-docs/entry/alert-group-settings
type AlertGroupSetting struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Memo string `json:"memo,omitempty"`
ServiceScopes []string `json:"serviceScopes,omitempty"`
RoleScopes []string `json:"roleScopes,omitempty"`
MonitorScopes []string `json:"monitorScopes,omitempty"`
NotificationInterval uint64 `json:"notificationInterval,omitempty"`
}
// FindAlertGroupSettings finds alert group settings.
func (c *Client) FindAlertGroupSettings() ([]*AlertGroupSetting, error) {
return c.FindAlertGroupSettingsContext(context.Background())
}
// FindAlertGroupSettingsContext finds alert group settings.
func (c *Client) FindAlertGroupSettingsContext(ctx context.Context) ([]*AlertGroupSetting, error) {
data, err := requestGetContext[struct {
AlertGroupSettings []*AlertGroupSetting `json:"alertGroupSettings"`
}](ctx, c, "/api/v0/alert-group-settings")
if err != nil {
return nil, err
}
return data.AlertGroupSettings, nil
}
// CreateAlertGroupSetting creates an alert group setting.
func (c *Client) CreateAlertGroupSetting(param *AlertGroupSetting) (*AlertGroupSetting, error) {
return c.CreateAlertGroupSettingContext(context.Background(), param)
}
// CreateAlertGroupSettingContext creates an alert group setting.
func (c *Client) CreateAlertGroupSettingContext(ctx context.Context, param *AlertGroupSetting) (*AlertGroupSetting, error) {
return requestPostContext[AlertGroupSetting](ctx, c, "/api/v0/alert-group-settings", param)
}
// GetAlertGroupSetting gets an alert group setting.
func (c *Client) GetAlertGroupSetting(id string) (*AlertGroupSetting, error) {
return c.GetAlertGroupSettingContext(context.Background(), id)
}
// GetAlertGroupSettingContext gets an alert group setting.
func (c *Client) GetAlertGroupSettingContext(ctx context.Context, id string) (*AlertGroupSetting, error) {
path := fmt.Sprintf("/api/v0/alert-group-settings/%s", id)
return requestGetContext[AlertGroupSetting](ctx, c, path)
}
// UpdateAlertGroupSetting updates an alert group setting.
func (c *Client) UpdateAlertGroupSetting(id string, param *AlertGroupSetting) (*AlertGroupSetting, error) {
return c.UpdateAlertGroupSettingContext(context.Background(), id, param)
}
// UpdateAlertGroupSettingContext updates an alert group setting.
func (c *Client) UpdateAlertGroupSettingContext(ctx context.Context, id string, param *AlertGroupSetting) (*AlertGroupSetting, error) {
path := fmt.Sprintf("/api/v0/alert-group-settings/%s", id)
return requestPutContext[AlertGroupSetting](ctx, c, path, param)
}
// DeleteAlertGroupSetting deletes an alert group setting.
func (c *Client) DeleteAlertGroupSetting(id string) (*AlertGroupSetting, error) {
return c.DeleteAlertGroupSettingContext(context.Background(), id)
}
// DeleteAlertGroupSettingContext deletes an alert group setting.
func (c *Client) DeleteAlertGroupSettingContext(ctx context.Context, id string) (*AlertGroupSetting, error) {
path := fmt.Sprintf("/api/v0/alert-group-settings/%s", id)
return requestDeleteContext[AlertGroupSetting](ctx, c, path)
}