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
2 changes: 1 addition & 1 deletion linode_api4/groups/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def alert_channels(self, *filters) -> PaginatedList:
.. note:: This endpoint is in beta and requires using the v4beta base URL.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-alert-channels
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-notification-channels
:param filters: Optional filter expressions to apply to the collection.
See :doc:`Filtering Collections</linode_api4/objects/filtering>` for details.
Expand Down
22 changes: 1 addition & 21 deletions linode_api4/objects/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,25 +422,6 @@ class AlertDefinition(DerivedBase):
}


@dataclass
class EmailChannelContent(JSONObject):
"""
Represents the content for an email alert channel.
"""

email_addresses: Optional[List[str]] = None


@dataclass
class ChannelContent(JSONObject):
"""
Represents the content block for an AlertChannel, which varies by channel type.
"""

email: Optional[EmailChannelContent] = None
# Other channel types like 'webhook', 'slack' could be added here as Optional fields.


@dataclass
class EmailDetails(JSONObject):
"""
Expand Down Expand Up @@ -481,7 +462,7 @@ 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-alert-channels
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-notification-channels

This class maps to the Monitor API's `/monitor/alert-channels` resource
and is used by the SDK to list, load, and inspect channels.
Expand All @@ -499,7 +480,6 @@ class AlertChannel(Base):
"channel_type": Property(),
"details": Property(mutable=False, json_object=ChannelDetails),
"alerts": Property(mutable=False, json_object=AlertInfo),
"content": Property(mutable=False, json_object=ChannelContent),
"created": Property(is_datetime=True),
"updated": Property(is_datetime=True),
"created_by": Property(),
Expand Down
31 changes: 31 additions & 0 deletions test/fixtures/monitor_alert-channels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"data": [
{
"id": 123,
"label": "alert notification channel",
"type": "user",
"channel_type": "email",
"details": {
"email": {
"usernames": [
"admin-user1",
"admin-user2"
],
"recipient_type": "user"
}
},
"alerts": {
"url": "/monitor/alert-channels/123/alerts",
"type": "alerts-definitions",
"alert_count": 0
},
"created": "2024-01-01T00:00:00",
"updated": "2024-01-01T00:00:00",
"created_by": "tester",
"updated_by": "tester"
}
],
"page": 1,
"pages": 1,
"results": 1
}
26 changes: 25 additions & 1 deletion test/unit/objects/monitor_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from test.unit.base import ClientBaseCase

from linode_api4.objects import MonitorDashboard, MonitorService
from linode_api4.objects import AlertChannel, MonitorDashboard, MonitorService


class MonitorTest(ClientBaseCase):
Expand Down Expand Up @@ -146,3 +146,27 @@ def test_create_token(self):
service_type="linode", entity_ids=["compute-instance-1"]
)
self.assertEqual(m.return_dct["token"], "abcdefhjigkfghh")

def test_alert_channels(self):
channels = self.client.monitor.alert_channels()

self.assertEqual(len(channels), 1)
self.assertIsInstance(channels[0], AlertChannel)
self.assertEqual(channels[0].id, 123)
self.assertEqual(channels[0].label, "alert notification channel")
self.assertEqual(channels[0].type, "user")
self.assertEqual(channels[0].channel_type, "email")
self.assertIsNotNone(channels[0].details)
self.assertIsNotNone(channels[0].details.email)
self.assertEqual(
channels[0].details.email.usernames,
["admin-user1", "admin-user2"],
)
self.assertEqual(channels[0].details.email.recipient_type, "user")
self.assertIsNotNone(channels[0].alerts)
self.assertEqual(
channels[0].alerts.url,
"/monitor/alert-channels/123/alerts",
)
self.assertEqual(channels[0].alerts.alert_count, 0)
self.assertFalse(hasattr(channels[0], "content"))