Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions monitor_alert_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,60 @@ func (a *AlertChannel) UnmarshalJSON(b []byte) error {
return nil
}

// AlertChannelCreateOptions represents options for creating an alert notification channel.
type AlertChannelCreateOptions struct {
ChannelType AlertNotificationType `json:"channel_type"`
Details AlertChannelDetailsOptions `json:"details"`
Label *string `json:"label,omitzero"`
}

// AlertChannelDetailsOptions represents the details configuration for an alert channel.
type AlertChannelDetailsOptions struct {
Email *EmailChannelCreateOptions `json:"email,omitzero"`
}

// EmailChannelCreateOptions represents email-specific configuration for an alert channel.
type EmailChannelCreateOptions struct {
Usernames []string `json:"usernames"`
RecipientType *string `json:"recipient_type,omitzero"`
}

// AlertChannelUpdateOptions represents options for updating an alert notification channel.
type AlertChannelUpdateOptions struct {
Details *AlertChannelUpdateDetailsOptions `json:"details,omitzero"`
Label *string `json:"label,omitzero"`
}

// AlertChannelUpdateDetailsOptions represents update details for an alert channel.
type AlertChannelUpdateDetailsOptions struct {
Email *EmailChannelUpdateOptions `json:"email,omitzero"`
}

// EmailChannelUpdateOptions represents email-specific update configuration for an alert channel.
type EmailChannelUpdateOptions struct {
Usernames []string `json:"usernames,omitzero"`
}

// 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)
}

// CreateAlertChannel creates a new alert notification channel.
func (c *Client) CreateAlertChannel(ctx context.Context, opts AlertChannelCreateOptions) (*AlertChannel, error) {
endpoint := formatAPIPath("monitor/alert-channels")
return doPOSTRequest[AlertChannel](ctx, c, endpoint, opts)
}

// UpdateAlertChannel updates an alert notification channel.
func (c *Client) UpdateAlertChannel(ctx context.Context, channelID int, opts AlertChannelUpdateOptions) (*AlertChannel, error) {
endpoint := formatAPIPath("monitor/alert-channels/%d", channelID)
return doPUTRequest[AlertChannel](ctx, c, endpoint, opts)
}

// DeleteAlertChannel deletes an alert notification channel.
func (c *Client) DeleteAlertChannel(ctx context.Context, channelID int) error {
endpoint := formatAPIPath("monitor/alert-channels/%d", channelID)
return doDELETERequest(ctx, c, endpoint)
}
276 changes: 276 additions & 0 deletions test/integration/fixtures/TestMonitorAlertChannel_Create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/account/users?page=1
method: GET
response:
body: '{"data": [{"username": "test_user1", "email": "test_user1@example.com",
"restricted": false, "ssh_keys": [], "tfa_enabled": true, "verified_phone_number":
"+48695154186", "password_created": "2018-01-02T03:04:05", "last_login": {"login_datetime":
"2018-01-02T03:04:05", "status": "successful"}, "user_type": "default"}, {"username":
"test_user2", "email": "test_user2@example.com", "restricted": false,
"ssh_keys": ["bfenski", "fenio", "fenio", "fenio", "fenio"], "tfa_enabled":
true, "verified_phone_number": "+48513467293", "password_created": "2018-01-02T03:04:05",
"last_login": {"login_datetime": "2018-01-02T03:04:05", "status": "successful"},
"user_type": "default"}], "page": 1, "pages": 1, "results": 2}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Mon, 06 Jul 2026 18:46:20 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
- Authorization, X-Filter
- Accept-Encoding
X-Accepted-Oauth-Scopes:
- account:read_only
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- account:read_only databases:read_only domains:read_only events:read_only firewall:read_only
images:read_only ips:read_only linodes:read_only lke:read_only longview:read_only
monitor:read_write nodebalancers:read_only object_storage:read_only stackscripts:read_only
volumes:read_only
X-Ratelimit-Limit:
- "1840"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
- request:
body: '{"channel_type":"email","details":{"email":{"usernames":["test_user1","test_user2"],"recipient_type":"user"}},"label":"linodego-sdk-test-alert-channel"}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/monitor/alert-channels
method: POST
response:
body: '{"id": 10284, "label": "linodego-sdk-test-alert-channel", "channel_type":
"email", "type": "user", "details": {"email": {"usernames": ["test_user1",
"test_user2"], "recipient_type": "user"}}, "alerts": {"url": "/monitor/alert-channels/10284/alerts",
"type": "alerts-definitions", "alert_count": 0}, "created": "2018-01-02T03:04:05",
"updated": "2018-01-02T03:04:05", "created_by": "tester", "updated_by":
"tester"}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "470"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Mon, 06 Jul 2026 18:46:21 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- monitor:read_write
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- account:read_only databases:read_only domains:read_only events:read_only firewall:read_only
images:read_only ips:read_only linodes:read_only lke:read_only longview:read_only
monitor:read_write nodebalancers:read_only object_storage:read_only stackscripts:read_only
volumes:read_only
X-Ratelimit-Limit:
- "1840"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
- request:
body: '{"details":{"email":{"usernames":["test_user1","test_user2"]}},"label":"linodego-sdk-test-alert-channel-updated"}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/monitor/alert-channels/10284
method: PUT
response:
body: '{"id": 10284, "label": "linodego-sdk-test-alert-channel-updated", "channel_type":
"email", "type": "user", "details": {"email": {"usernames": ["test_user1",
"test_user2"], "recipient_type": "user"}}, "alerts": {"url": "/monitor/alert-channels/10284/alerts",
"type": "alerts-definitions", "alert_count": 0}, "created": "2018-01-02T03:04:05",
"created_by": "tester", "updated_by": "tester"}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "478"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Mon, 06 Jul 2026 18:46:22 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- monitor:read_write
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- account:read_only databases:read_only domains:read_only events:read_only firewall:read_only
images:read_only ips:read_only linodes:read_only lke:read_only longview:read_only
monitor:read_write nodebalancers:read_only object_storage:read_only stackscripts:read_only
volumes:read_only
X-Ratelimit-Limit:
- "1840"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/monitor/alert-channels/10284
method: DELETE
response:
body: '{}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "2"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Mon, 06 Jul 2026 18:46:25 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- monitor:read_write
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- account:read_only databases:read_only domains:read_only events:read_only firewall:read_only
images:read_only ips:read_only linodes:read_only lke:read_only longview:read_only
monitor:read_write nodebalancers:read_only object_storage:read_only stackscripts:read_only
volumes:read_only
X-Ratelimit-Limit:
- "1840"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
Loading