-
Notifications
You must be signed in to change notification settings - Fork 87
Adding create channel api changes to python SDK #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| MonitorService, | ||
| MonitorServiceToken, | ||
| ) | ||
| from linode_api4.objects.monitor import ChannelDetails | ||
|
|
||
| __all__ = [ | ||
| "MonitorGroup", | ||
|
|
@@ -332,3 +333,68 @@ def alert_definition_entities( | |
| *filters, | ||
| endpoint=endpoint, | ||
| ) | ||
|
|
||
| def channel_create( | ||
| self, | ||
| label: str, | ||
| channel_type: str, | ||
| details: ChannelDetails, | ||
| ) -> AlertChannel: | ||
| """ | ||
| Creates a new alert channel for the authenticated account. | ||
|
|
||
| An alert channel defines a notification destination (for example: an | ||
| email list) that can be associated with one or more alert definitions. | ||
| Currently only ``email`` is supported as a ``channel_type``. | ||
|
|
||
| Example usage:: | ||
|
|
||
| from linode_api4.objects.monitor import ChannelDetails, EmailDetails | ||
|
|
||
| client = LinodeClient(TOKEN) | ||
|
|
||
| new_channel = client.monitor.channel_create( | ||
| label="Email channel for api change", | ||
| channel_type="email", | ||
| details=ChannelDetails( | ||
| email=EmailDetails( | ||
| recipient_type="user", | ||
| usernames=["username-test"], | ||
| ) | ||
| ), | ||
| ) | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/post-alert-channel | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| :param label: Human-readable name for the new alert channel. | ||
| :type label: str | ||
| :param channel_type: The type of notification channel (e.g. ``"email"``). | ||
| :type channel_type: str | ||
| :param details: Notification-type-specific configuration. Use | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even here usage may not be required |
||
| :class:`~linode_api4.objects.monitor.ChannelDetails` with | ||
| a nested :class:`~linode_api4.objects.monitor.EmailDetails` | ||
| for email channels. | ||
| :type details: ChannelDetails | ||
|
|
||
| :returns: The newly created :class:`AlertChannel`. | ||
| :rtype: AlertChannel | ||
|
|
||
| .. note:: | ||
| For updating an alert channel, use the ``save()`` method on the :class:`AlertChannel` object. | ||
| For deleting an alert channel, use the ``delete()`` method directly on the :class:`AlertChannel` object. | ||
| """ | ||
| params = { | ||
| "label": label, | ||
| "channel_type": channel_type, | ||
| "details": details.dict, | ||
| } | ||
|
|
||
| result = self.client.post("/monitor/alert-channels", data=params) | ||
|
|
||
| if "id" not in result: | ||
| raise UnexpectedResponseError( | ||
| "Unexpected response when creating alert channel!", | ||
| json=result, | ||
| ) | ||
|
|
||
| return AlertChannel(self.client, result["id"], result) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -492,23 +492,22 @@ class AlertChannel(Base): | |
| fire. Alert channels define a destination and configuration for | ||
| notifications (for example: email lists, webhooks, PagerDuty, Slack, etc.). | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/get-notification-channels | ||
| API Documentation: | ||
| List/Get: https://techdocs.akamai.com/linode-api/reference/get-alert-channels | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GET: https://techdocs.akamai.com/linode-api/reference/get-notification-channel This class will be used for response contract. Single response object. |
||
| Create: https://techdocs.akamai.com/linode-api/reference/post-alert-channel | ||
|
|
||
| This class maps to the Monitor API's `/monitor/alert-channels` resource | ||
| and is used by the SDK to list, load, and inspect channels. | ||
|
|
||
| NOTE: Only read operations are supported for AlertChannel at this time. | ||
| Create, update, and delete (CRUD) operations are not allowed. | ||
| This class maps to the Monitor API's ``/monitor/alert-channels`` resource | ||
| and is used by the SDK to list, load, create, and inspect channels. | ||
| """ | ||
|
|
||
| api_endpoint = "/monitor/alert-channels/{id}" | ||
|
|
||
| properties = { | ||
| "id": Property(identifier=True), | ||
| "label": Property(), | ||
| "label": Property(mutable=True), | ||
| "type": Property(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can define enum Type for user & system values |
||
| "channel_type": Property(), | ||
| "details": Property(mutable=False, json_object=ChannelDetails), | ||
| "details": Property(mutable=True, json_object=ChannelDetails), | ||
| "alerts": Property(mutable=False, json_object=AlertInfo), | ||
| "created": Property(is_datetime=True), | ||
| "updated": Property(is_datetime=True), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example usage may not be required