Skip to content

Commit 90c287a

Browse files
srbhaakamaiCopilot
andauthored
ACLP Alerting get_channles() API changes and Added Enum for 'Status' (#645)
* Resolving requirement.txt conflicts * Added test with new Status and Alert Definition change * Revert "Resolving requirement.txt conflicts" This reverts commit d40b96c. * introduced enums for alert status * Update linode_api4/objects/monitor.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fixed reviewer comments * fixed lint error * fix lint errors from make lint command * changed wait code to wait until its enabled --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1fd5851 commit 90c287a

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

linode_api4/objects/monitor.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ class DashboardType(StrEnum):
116116
custom = "custom"
117117

118118

119+
class AlertStatus(StrEnum):
120+
"""
121+
Enum for supported alert status values.
122+
"""
123+
124+
AlertDefinitionStatusProvisioning = "provisioning"
125+
AlertDefinitionStatusEnabling = "enabling"
126+
AlertDefinitionStatusDisabling = "disabling"
127+
AlertDefinitionStatusEnabled = "enabled"
128+
AlertDefinitionStatusDisabled = "disabled"
129+
AlertDefinitionStatusFailed = "failed"
130+
131+
119132
@dataclass
120133
class Filter(JSONObject):
121134
"""
@@ -428,6 +441,40 @@ class ChannelContent(JSONObject):
428441
# Other channel types like 'webhook', 'slack' could be added here as Optional fields.
429442

430443

444+
@dataclass
445+
class EmailDetails(JSONObject):
446+
"""
447+
Represents email-specific details for an alert channel.
448+
"""
449+
450+
usernames: Optional[List[str]] = None
451+
recipient_type: Optional[str] = None
452+
453+
454+
@dataclass
455+
class ChannelDetails(JSONObject):
456+
"""
457+
Represents the details block for an AlertChannel, which varies by channel type.
458+
"""
459+
460+
email: Optional[EmailDetails] = None
461+
462+
463+
@dataclass
464+
class AlertInfo(JSONObject):
465+
"""
466+
Represents a reference to alerts associated with an alert channel.
467+
Fields:
468+
- url: str - API URL to fetch the alerts for this channel
469+
- type: str - Type identifier (e.g., 'alerts-definitions')
470+
- alert_count: int - Number of alerts associated with this channel
471+
"""
472+
473+
url: str = ""
474+
_type: str = field(default="", metadata={"json_key": "type"})
475+
alert_count: int = 0
476+
477+
431478
class AlertChannel(Base):
432479
"""
433480
Represents an alert channel used to deliver notifications when alerts
@@ -450,7 +497,8 @@ class AlertChannel(Base):
450497
"label": Property(),
451498
"type": Property(),
452499
"channel_type": Property(),
453-
"alerts": Property(mutable=False, json_object=Alerts),
500+
"details": Property(mutable=False, json_object=ChannelDetails),
501+
"alerts": Property(mutable=False, json_object=AlertInfo),
454502
"content": Property(mutable=False, json_object=ChannelContent),
455503
"created": Property(is_datetime=True),
456504
"updated": Property(is_datetime=True),

test/integration/models/monitor/test_monitor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
MonitorService,
1717
MonitorServiceToken,
1818
)
19+
from linode_api4.objects.monitor import AlertStatus
1920

2021

2122
# List all dashboards
@@ -227,7 +228,8 @@ def wait_for_alert_ready(alert_id, service_type: str):
227228
interval = initial_timeout
228229
alert = client.load(AlertDefinition, alert_id, service_type)
229230
while (
230-
getattr(alert, "status", None) == "in progress"
231+
getattr(alert, "status", None)
232+
!= AlertStatus.AlertDefinitionStatusEnabled
231233
and (time.time() - start) < timeout
232234
):
233235
time.sleep(interval)

0 commit comments

Comments
 (0)