|
| 1 | +package linodego |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | +) |
| 6 | + |
| 7 | +// AlertChannelEnvelope represents a single alert channel entry returned inside alert definition |
| 8 | +type AlertChannelEnvelope struct { |
| 9 | + ID int `json:"id"` |
| 10 | + Label string `json:"label"` |
| 11 | + Type string `json:"type"` |
| 12 | + URL string `json:"url"` |
| 13 | +} |
| 14 | + |
| 15 | +// AlertChannel represents a Monitor Channel object. |
| 16 | +type AlertChannel struct { |
| 17 | + ID int `json:"id"` |
| 18 | + Alerts []AlertChannelEnvelope `json:"alerts"` |
| 19 | + Label string `json:"label"` |
| 20 | + Channel_type string `json:"channel_type"` |
| 21 | + Content ChannelContent `json:"content"` |
| 22 | + Type AlertType `json:"type"` |
| 23 | + Details AlertChannelDetail `json:"details"` |
| 24 | + Created string `json:"created"` |
| 25 | + Created_by string `json:"created_by"` |
| 26 | + Updated string `json:"updated"` |
| 27 | + Updated_by string `json:"updated_by"` |
| 28 | +} |
| 29 | + |
| 30 | +// AlertChannelDetail represents the details of a Monitor Channel. |
| 31 | +type AlertChannelDetail struct { |
| 32 | + To string `json:"to,omitempty"` |
| 33 | + From string `json:"from,omitempty"` |
| 34 | + User string `json:"user,omitempty"` |
| 35 | + Token string `json:"token,omitempty"` |
| 36 | + URL string `json:"url,omitempty"` |
| 37 | +} |
| 38 | + |
| 39 | +// AlertChannelCreateOptions are the options used to create a new Monitor Channel. |
| 40 | +type AlertChannelCreateOptions struct { |
| 41 | + Label string `json:"label"` |
| 42 | + Type string `json:"type"` |
| 43 | + Details AlertChannelDetailOptions `json:"details"` |
| 44 | +} |
| 45 | + |
| 46 | +// AlertChannelDetailOptions are the options used to create the details of a new Monitor Channel. |
| 47 | +type AlertChannelDetailOptions struct { |
| 48 | + To string `json:"to,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// Backwards-compat alias for older name |
| 52 | +type AlertingChannelCreateOptions = AlertChannelCreateOptions |
| 53 | + |
| 54 | +type EmailChannelContent struct { |
| 55 | + EmailAddresses []string `json:"email_addresses"` |
| 56 | +} |
| 57 | + |
| 58 | +// ChannelContent represents the content block for an AlertChannel, which varies by channel type. |
| 59 | +type ChannelContent struct { |
| 60 | + Email *EmailChannelContent `json:"email,omitempty"` |
| 61 | + // Other channel types like 'webhook', 'slack' could be added here as optional fields. |
| 62 | +} |
| 63 | + |
| 64 | +// ListMonitorChannels gets a paginated list of Monitor Channels. |
| 65 | +func (c *Client) ListAlertChannels(ctx context.Context, opts *ListOptions) ([]AlertChannel, error) { |
| 66 | + endpoint := formatAPIV4BetaPath("monitor/channels") |
| 67 | + return getPaginatedResults[AlertChannel](ctx, c, endpoint, opts) |
| 68 | +} |
| 69 | + |
| 70 | +// GetMonitorChannel gets a Monitor Channel by ID. |
| 71 | +func (c *Client) GetAlertChannel(ctx context.Context, channelID int) (*AlertChannel, error) { |
| 72 | + e := formatAPIV4BetaPath("monitor/channels/%d", channelID) |
| 73 | + return doGETRequest[AlertChannel](ctx, c, e) |
| 74 | +} |
| 75 | + |
| 76 | +func (c *Client) GetAlertChannels(ctx context.Context) (*AlertChannel, error) { |
| 77 | + e := formatAPIV4BetaPath("monitor/alert-channels/") |
| 78 | + return doGETRequest[AlertChannel](ctx, c, e) |
| 79 | +} |
0 commit comments