This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
alertnotification.go
88 lines (74 loc) · 3.1 KB
/
alertnotification.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
package gapi
import (
"encoding/json"
"fmt"
)
// AlertNotification represents a Grafana alert notification.
// Deprecated: Grafana Legacy Alerting is deprecated as of 9.0 and will be removed in the future. Use ContactPoint instead.
type AlertNotification struct {
ID int64 `json:"id,omitempty"`
UID string `json:"uid"`
Name string `json:"name"`
Type string `json:"type"`
IsDefault bool `json:"isDefault"`
DisableResolveMessage bool `json:"disableResolveMessage"`
SendReminder bool `json:"sendReminder"`
Frequency string `json:"frequency"`
Settings interface{} `json:"settings"`
SecureFields interface{} `json:"secureFields,omitempty"`
SecureSettings interface{} `json:"secureSettings,omitempty"`
}
// AlertNotifications fetches and returns Grafana alert notifications.
// Deprecated: Grafana Legacy Alerting is deprecated as of 9.0 and will be removed in the future. Use ContactPoints instead.
func (c *Client) AlertNotifications() ([]AlertNotification, error) {
alertnotifications := make([]AlertNotification, 0)
err := c.request("GET", "/api/alert-notifications/", nil, nil, &alertnotifications)
if err != nil {
return nil, err
}
return alertnotifications, err
}
// AlertNotification fetches and returns a Grafana alert notification.
// Deprecated: Grafana Legacy Alerting is deprecated as of 9.0 and will be removed in the future. Use ContactPoint instead.
func (c *Client) AlertNotification(id int64) (*AlertNotification, error) {
path := fmt.Sprintf("/api/alert-notifications/%d", id)
result := &AlertNotification{}
err := c.request("GET", path, nil, nil, result)
if err != nil {
return nil, err
}
return result, err
}
// NewAlertNotification creates a new Grafana alert notification.
// Deprecated: Grafana Legacy Alerting is deprecated as of 9.0 and will be removed in the future. Use NewContactPoint instead.
func (c *Client) NewAlertNotification(a *AlertNotification) (int64, error) {
data, err := json.Marshal(a)
if err != nil {
return 0, err
}
result := struct {
ID int64 `json:"id"`
}{}
err = c.request("POST", "/api/alert-notifications", nil, data, &result)
if err != nil {
return 0, err
}
return result.ID, err
}
// UpdateAlertNotification updates a Grafana alert notification.
// Deprecated: Grafana Legacy Alerting is deprecated as of 9.0 and will be removed in the future. Use UpdateContactPoint instead.
func (c *Client) UpdateAlertNotification(a *AlertNotification) error {
path := fmt.Sprintf("/api/alert-notifications/%d", a.ID)
data, err := json.Marshal(a)
if err != nil {
return err
}
err = c.request("PUT", path, nil, data, nil)
return err
}
// DeleteAlertNotification deletes a Grafana alert notification.
// Deprecated: Grafana Legacy Alerting is deprecated as of 9.0 and will be removed in the future. Use DeleteContactPoint instead.
func (c *Client) DeleteAlertNotification(id int64) error {
path := fmt.Sprintf("/api/alert-notifications/%d", id)
return c.request("DELETE", path, nil, nil, nil)
}