-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathmonitor_alert_channels.go
More file actions
95 lines (76 loc) · 2.59 KB
/
monitor_alert_channels.go
File metadata and controls
95 lines (76 loc) · 2.59 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
type AlertNotificationType string
const (
EmailAlertNotification AlertNotificationType = "email"
)
type AlertChannelType string
const (
SystemAlertChannel AlertChannelType = "system"
UserAlertChannel AlertChannelType = "user"
)
// AlertChannel represents a Monitor Channel object.
type AlertChannel struct {
Alerts AlertsInfo `json:"alerts"`
ChannelType AlertNotificationType `json:"channel_type"`
Content ChannelContent `json:"content"`
Details ChannelDetails `json:"details"`
Created *time.Time `json:"-"`
CreatedBy string `json:"created_by"`
Updated *time.Time `json:"-"`
UpdatedBy string `json:"updated_by"`
ID int `json:"id"`
Label string `json:"label"`
Type AlertChannelType `json:"type"`
}
// AlertsInfo represents alert information for a channel
type AlertsInfo struct {
URL string `json:"url"`
Type string `json:"type"`
AlertCount int `json:"alert_count"`
}
type EmailChannelContent struct {
EmailAddresses []string `json:"email_addresses,omitempty"`
}
// ChannelContent represents the content block for an AlertChannel, which varies by channel type.
type ChannelContent struct {
Email *EmailChannelContent `json:"email"`
// Other channel types like 'webhook', 'slack' could be added her
}
// ChannelDetails represents the details block for an AlertChannel
type ChannelDetails struct {
Email *EmailChannelDetails `json:"email"`
// Other channel types could be added here
}
// EmailChannelDetails represents email-specific details for a channel
type EmailChannelDetails struct {
Usernames []string `json:"usernames"`
RecipientType string `json:"recipient_type"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (a *AlertChannel) UnmarshalJSON(b []byte) error {
type Mask AlertChannel
p := struct {
*Mask
Updated *parseabletime.ParseableTime `json:"updated"`
Created *parseabletime.ParseableTime `json:"created"`
}{
Mask: (*Mask)(a),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
a.Updated = (*time.Time)(p.Updated)
a.Created = (*time.Time)(p.Created)
return nil
}
// ListAlertChannels gets a paginated list of Alert Channels.
func (c *Client) ListAlertChannels(ctx context.Context, opts *ListOptions) ([]AlertChannel, error) {
endpoint := formatAPIPath("monitor/alert-channels")
return getPaginatedResults[AlertChannel](ctx, c, endpoint, opts)
}