Skip to content

Commit 53f94a5

Browse files
committed
fixed review errors
1 parent 1ef9221 commit 53f94a5

File tree

3 files changed

+22
-114
lines changed

3 files changed

+22
-114
lines changed

linode_api4/groups/monitor.py

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -155,39 +155,27 @@ def alert_definitions(
155155
service_type: Optional[str] = None,
156156
) -> Union[PaginatedList, AlertDefinition]:
157157
"""
158-
Retrieve one or more alert definitions.
158+
Retrieve alert definitions.
159159
160-
If both `service_type` and `alert_id` are provided, a single
161-
:class:`AlertDefinition` instance is returned. If only `service_type` is
162-
provided (or neither), a paginated list of :class:`AlertDefinition`
163-
objects is returned.
164-
165-
Examples:
166-
alert_definitions = client.monitor.get_alert_definitions()
167-
alert_definition = client.load(AlertDefinition, alert_id,"dbaas")
168-
alert_definitions_for_service = client.monitor.get_alert_definitions(service_type="dbaas")
160+
Returns a paginated collection of :class:`AlertDefinition` objects. If you
161+
need to obtain a single :class:`AlertDefinition`, use :meth:`LinodeClient.load`
162+
and supply the `service_type` as the parent identifier, for example:
169163
164+
alerts = client.monitor.alert_definitions()
165+
alerts_by_service = client.monitor.alert_definitions(service_type="dbaas")
170166
.. note:: This endpoint is in beta and requires using the v4beta base URL.
171167
172168
API Documentation:
173-
https://techdocs.akamai.com/linode-api/reference/get-alert-definition
174169
https://techdocs.akamai.com/linode-api/reference/get-alert-definitions
175170
https://techdocs.akamai.com/linode-api/reference/get-alert-definitions-for-service-type
176171
177-
:param service_type: If provided, limits the query to alert definitions for
178-
the given service type (e.g. ``"dbaas"``).
172+
:param service_type: Optional service type to scope the query (e.g. ``"dbaas"``).
179173
:type service_type: Optional[str]
180-
:param alert_id: If provided, the ID of the alert definition to fetch. When
181-
specifying an ``alert_id``, ``service_type`` must also be
182-
provided.
183-
:type alert_id: Optional[int]
184174
:param filters: Optional filtering expressions to apply to the returned
185175
collection. See :doc:`Filtering Collections</linode_api4/objects/filtering>`.
186176
187-
:returns: A single :class:`AlertDefinition` when ``alert_id`` is used, or
188-
a :class:`PaginatedList` of :class:`AlertDefinition` objects
189-
otherwise.
190-
:rtype: Union[AlertDefinition, PaginatedList[AlertDefinition]]
177+
:returns: A paginated list of :class:`AlertDefinition` objects.
178+
:rtype: PaginatedList[AlertDefinition]
191179
"""
192180

193181
endpoint = "/monitor/alert-definitions"
@@ -291,75 +279,4 @@ def create_alert_definition(
291279
json=result,
292280
)
293281

294-
return AlertDefinition(self.client, result["id"],service_type, result)
295-
296-
def update_alert_definition(
297-
self,
298-
service_type: str,
299-
alert_id: int,
300-
label: Optional[str] = None,
301-
severity: Optional[str] = None,
302-
description: Optional[str] = None,
303-
rule_criteria: Optional[dict] = None,
304-
trigger_conditions: Optional[dict] = None,
305-
entity_ids: Optional[list[str]] = None,
306-
channel_ids: Optional[list[int]] = None,
307-
) -> AlertDefinition:
308-
"""
309-
Update an existing alert definition.
310-
311-
Only the parameters provided will be updated; omitted parameters are left
312-
unchanged.
313-
314-
.. note:: This endpoint is in beta and requires using the v4beta base URL.
315-
316-
API Documentation: https://techdocs.akamai.com/linode-api/reference/put-alert-definition
317-
318-
:param service_type: Service type of the alert definition to update
319-
(e.g. ``"dbaas"``).
320-
:type service_type: str
321-
:param alert_id: ID of the alert definition to update.
322-
:type alert_id: int
323-
:param label: (Optional) New label for the alert definition.
324-
:type label: Optional[str]
325-
:param severity: (Optional) New severity for the alert. The SDK accepts
326-
this value as provided to the API (commonly an integer).
327-
:type severity: Optional[str]
328-
:param description: (Optional) New description for the alert definition.
329-
:type description: Optional[str]
330-
:param rule_criteria: (Optional) New rule criteria to replace the current
331-
definition.
332-
:type rule_criteria: Optional[RuleCriteria]
333-
:param trigger_conditions: (Optional) New trigger conditions.
334-
:type trigger_conditions: Optional[TriggerConditions]
335-
:param entity_ids: (Optional) New list of entity IDs to scope the alert.
336-
:type entity_ids: Optional[list[str]]
337-
:param channel_ids: (Optional) New list of channel IDs to notify.
338-
:type channel_ids: Optional[list[int]]
339-
340-
:returns: The updated :class:`AlertDefinition` as returned by the API.
341-
:rtype: AlertDefinition
342-
"""
343-
params = {}
344-
if label is not None:
345-
params["label"] = label
346-
if severity is not None:
347-
params["severity"] = severity
348-
if description is not None:
349-
params["description"] = description
350-
if rule_criteria is not None:
351-
params["rule_criteria"] = rule_criteria
352-
if trigger_conditions is not None:
353-
params["trigger_conditions"] = trigger_conditions
354-
if entity_ids is not None:
355-
params["entity_ids"] = entity_ids
356-
if channel_ids is not None:
357-
params["channel_ids"] = channel_ids
358-
359-
#API will handle check for service_type and alert_id and return correct error if missing
360-
result = self.client.put(
361-
f"/monitor/services/{service_type}/alert-definitions/{alert_id}",
362-
data=params,
363-
)
364-
365-
return AlertDefinition(self.client, result["id"], service_type, result)
282+
return AlertDefinition(self.client, result["id"],service_type, result)

linode_api4/objects/monitor.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,19 @@ class AlertDefinition(DerivedBase):
318318
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-alert-definition
319319
"""
320320

321-
api_endpoint = "/monitor/services/{service}/alert-definitions/{id}"
321+
api_endpoint = "/monitor/services/{service_type}/alert-definitions/{id}"
322322
derived_url_path = "alert-definitions"
323-
parent_id_name = "service"
323+
parent_id_name = "service_type"
324324
id_attribute = "id"
325325

326326
properties = {
327327
"id": Property(identifier=True),
328-
"label": Property(),
329-
"severity": Property(),
328+
"label": Property(mutable=True),
329+
"severity": Property(mutable=True),
330330
"type": Property(AlertType),
331-
"service_type": Property(mutable=True),
332-
"status": Property(mutable=True),
333-
"has_more_resources": Property(mutable=True),
331+
"service_type": Property(),
332+
"status": Property(),
333+
"has_more_resources": Property(),
334334
"rule_criteria": Property(RuleCriteria),
335335
"trigger_conditions": Property(TriggerConditions),
336336
"alert_channels": Property(List[AlertChannelEnvelope]),
@@ -339,7 +339,7 @@ class AlertDefinition(DerivedBase):
339339
"updated_by": Property(),
340340
"created_by": Property(),
341341
"entity_ids": Property(List[str]),
342-
"description": Property(),
342+
"description": Property(mutable=True),
343343
"_class": Property("class"),
344344
}
345345

@@ -366,6 +366,8 @@ class AlertChannel(Base):
366366
fire. Alert channels define a destination and configuration for
367367
notifications (for example: email lists, webhooks, PagerDuty, Slack, etc.).
368368
369+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-alert-channels
370+
369371
This class maps to the Monitor API's `/monitor/alert-channels` resource
370372
and is used by the SDK to list, load, and inspect channels.
371373
"""

test/integration/models/monitor/test_monitor.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from time import time
1+
import time
22

33
import pytest
44

@@ -155,7 +155,7 @@ def test_integration_create_get_update_delete_alert_definition(
155155
description = "E2E alert created by SDK integration test"
156156

157157
# Pick an existing alert channel to attach to the definition; skip if none
158-
channels = list(client.monitor.get_alert_channels())
158+
channels = list(client.monitor.alert_channels())
159159
if not channels:
160160
pytest.skip("No alert channels available on account for creating alert definitions")
161161

@@ -187,17 +187,6 @@ def test_integration_create_get_update_delete_alert_definition(
187187
# transient errors while polling; continue until timeout
188188
pass
189189

190-
# Update (may fail with 403 if token lacks permissions)
191-
new_label = f"{label}-updated"
192-
try:
193-
updated = client.monitor.update_alert_definition(service_type, created.id, label=new_label)
194-
assert getattr(updated, "label", None) == new_label
195-
except ApiError as e:
196-
if "403" in str(e) or "Access Denied" in str(e):
197-
pytest.skip("Token lacks monitor:write permission; skipping update assertion")
198-
else:
199-
raise
200-
201190
finally:
202191
if created:
203192
# Best-effort cleanup; allow transient errors.

0 commit comments

Comments
 (0)