diff --git a/linode_api4/objects/monitor.py b/linode_api4/objects/monitor.py index 4315e4c2e..ca8f83921 100644 --- a/linode_api4/objects/monitor.py +++ b/linode_api4/objects/monitor.py @@ -116,6 +116,19 @@ class DashboardType(StrEnum): custom = "custom" +class AlertStatus(StrEnum): + """ + Enum for supported alert status values. + """ + + AlertDefinitionStatusProvisioning = "provisioning" + AlertDefinitionStatusEnabling = "enabling" + AlertDefinitionStatusDisabling = "disabling" + AlertDefinitionStatusEnabled = "enabled" + AlertDefinitionStatusDisabled = "disabled" + AlertDefinitionStatusFailed = "failed" + + @dataclass class Filter(JSONObject): """ @@ -428,6 +441,40 @@ class ChannelContent(JSONObject): # Other channel types like 'webhook', 'slack' could be added here as Optional fields. +@dataclass +class EmailDetails(JSONObject): + """ + Represents email-specific details for an alert channel. + """ + + usernames: Optional[List[str]] = None + recipient_type: Optional[str] = None + + +@dataclass +class ChannelDetails(JSONObject): + """ + Represents the details block for an AlertChannel, which varies by channel type. + """ + + email: Optional[EmailDetails] = None + + +@dataclass +class AlertInfo(JSONObject): + """ + Represents a reference to alerts associated with an alert channel. + Fields: + - url: str - API URL to fetch the alerts for this channel + - type: str - Type identifier (e.g., 'alerts-definitions') + - alert_count: int - Number of alerts associated with this channel + """ + + url: str = "" + _type: str = field(default="", metadata={"json_key": "type"}) + alert_count: int = 0 + + class AlertChannel(Base): """ Represents an alert channel used to deliver notifications when alerts @@ -450,7 +497,8 @@ class AlertChannel(Base): "label": Property(), "type": Property(), "channel_type": Property(), - "alerts": Property(mutable=False, json_object=Alerts), + "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), diff --git a/test/integration/models/monitor/test_monitor.py b/test/integration/models/monitor/test_monitor.py index b6cf40b54..02ca5211d 100644 --- a/test/integration/models/monitor/test_monitor.py +++ b/test/integration/models/monitor/test_monitor.py @@ -16,6 +16,7 @@ MonitorService, MonitorServiceToken, ) +from linode_api4.objects.monitor import AlertStatus # List all dashboards @@ -227,7 +228,8 @@ def wait_for_alert_ready(alert_id, service_type: str): interval = initial_timeout alert = client.load(AlertDefinition, alert_id, service_type) while ( - getattr(alert, "status", None) == "in progress" + getattr(alert, "status", None) + == AlertStatus.AlertDefinitionStatusEnabling and (time.time() - start) < timeout ): time.sleep(interval)