Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
66327ec
DI-26927 Python SDK code for GET Alert Definitions
srbhaakamai Aug 21, 2025
b94544c
DI-26927 Python SDK code modified for client code
srbhaakamai Aug 21, 2025
ba218c8
DI-26927 Added Unit test cases and missing classes
srbhaakamai Aug 22, 2025
1c4d705
DI-26927 made corrections to keep code consistent
srbhaakamai Aug 25, 2025
cc91d56
DI-26927 Updated Unit and Integratoion Tests
srbhaakamai Sep 1, 2025
d74bdcd
[dev 51950af] DI-26927 Updated Unit and Integratoion Tests
srbhaakamai Sep 1, 2025
a279a5a
Revert "DI-26927 Updated Unit and Integratoion Tests"
srbhaakamai Sep 1, 2025
7f0bf2d
Revert "[dev 51950af] DI-26927 Updated Unit and Integratoion Tests"
srbhaakamai Sep 1, 2025
9f631b1
DI-26927 Updated Unit and Integratoion Tests
srbhaakamai Sep 1, 2025
04f2c1c
Remove .venv from repo and add to .gitignore
srbhaakamai Sep 1, 2025
e499726
DI-26927 reverted git ignore
srbhaakamai Sep 1, 2025
c30c97f
DI-26927 reverted conftest,py
srbhaakamai Sep 1, 2025
762d49c
DI-26927 added accidentlly deleted file
srbhaakamai Sep 1, 2025
1c4fd7e
DI-26927 Corrected Integration and Unit Test cases for Alerting APIs
srbhaakamai Sep 2, 2025
39e9f41
DI-26927 Reverted conftest.py and check integration without those cha…
srbhaakamai Sep 3, 2025
c8e8961
DI-26927 fixed integration test for firewall and added time for alert…
srbhaakamai Sep 3, 2025
9a97568
DI-26927 fixed changing monitor.py as per review comments
srbhaakamai Sep 4, 2025
12491b6
DI-26927 fixed changing monitor.py as per review comments
srbhaakamai Sep 4, 2025
d67d284
DI-26927 fixed changing monitor.py as per review comments
srbhaakamai Sep 4, 2025
c04d801
DI-26927 Intermediate change to address internal review comments
srbhaakamai Sep 4, 2025
a735230
DI-26927 CLosed review comments
srbhaakamai Sep 8, 2025
03fe6b1
DI-26927 CLosed review comments
srbhaakamai Sep 8, 2025
a938d35
DI-27156 closed review comments from Ketan
srbhaakamai Sep 8, 2025
13a188b
DI-27156 closed review comments from Ketan
srbhaakamai Sep 8, 2025
e10da0c
DI-27156 fixed unit test cases post review comments fixes
srbhaakamai Sep 8, 2025
8bec096
DI-27156 Updated docstring and make unit test cases changes
srbhaakamai Sep 9, 2025
9f5ed8a
DI-27156 Added unit test cases post review comments fixes
srbhaakamai Sep 8, 2025
a0d6afc
DI-27156 Added unit test cases post review comments fixes
srbhaakamai Sep 8, 2025
0ea9aeb
tests(monitor): add MonitorAlertDefinitionsTest and update fixtures f…
srbhaakamai Sep 8, 2025
0774dcc
DI-27156 Added unit test cases post review comments fixes
srbhaakamai Sep 8, 2025
cfd02d5
DI-27156 Updated docstring
srbhaakamai Sep 8, 2025
16d17f3
DI-27156 Updated unit test errors
srbhaakamai Sep 9, 2025
47a6e25
removed unwanted files
srbhaakamai Sep 9, 2025
400eb0a
added missing doxcstring
srbhaakamai Sep 9, 2025
4584ea4
added missing doxcstring
srbhaakamai Sep 9, 2025
c5e8491
added missing doxcstring
srbhaakamai Sep 9, 2025
c4c4490
rmoved test files
srbhaakamai Sep 9, 2025
06bd0ce
closed final review comments
srbhaakamai Sep 9, 2025
fcd4d2d
fixing integration test issues
srbhaakamai Sep 9, 2025
c8ddabd
Corrected Integration Test Case
srbhaakamai Sep 9, 2025
71c5b30
DI-26927 Corrected json to object modifications issues
srbhaakamai Sep 9, 2025
a5e81cc
DI-26927 Corrected json to object modifications issues
srbhaakamai Sep 9, 2025
a2e73fd
DI-26927 Unit test corrections for mofied functions name
srbhaakamai Sep 9, 2025
3252718
Delete test/fixtures/monitor/services/dbaas/alert-definitions.json
srbhaakamai Sep 10, 2025
261686f
Delete test.py
srbhaakamai Sep 10, 2025
f3b50f3
Delete test/fixtures/monitor/alert-definitions.json
srbhaakamai Sep 10, 2025
5f08522
DI-26927 reverted fixtures.py as its not necesary to change
srbhaakamai Sep 10, 2025
f9052de
DI-26927 reverted fixtures.py as its not necesary to change
srbhaakamai Sep 10, 2025
aabf3f1
DI-26927 reverted fixtures.py as its not necesary to change
srbhaakamai Sep 10, 2025
68468b3
DI-26927 fixed linting error
srbhaakamai Sep 11, 2025
26b79a7
DI-26927 fixed linting error
srbhaakamai Sep 11, 2025
0dd18d6
DI-26927 fixed lint error caught in CI
srbhaakamai Sep 12, 2025
54b8ab1
Update test/unit/groups/monitor_api_test.py
srbhaakamai Sep 12, 2025
752936d
Update test/integration/models/monitor/test_monitor.py
srbhaakamai Sep 12, 2025
c2690a6
Update test/integration/models/monitor/test_monitor.py
srbhaakamai Sep 12, 2025
fb9e4bd
Update test/integration/models/monitor/test_monitor.py
srbhaakamai Sep 12, 2025
d3a7c2d
Update linode_api4/objects/monitor.py
srbhaakamai Sep 12, 2025
8558a57
DI-26927 fixed copilot comments
srbhaakamai Sep 12, 2025
bb2a05e
fixed review comments from APIv4 team
srbhaakamai Sep 17, 2025
a9554f9
fixed review comments from APIv4 team
srbhaakamai Sep 17, 2025
76606d1
fixed review comments from APIv4 team
srbhaakamai Sep 17, 2025
6d6a9a5
fixed review comments from APIv4 team
srbhaakamai Sep 17, 2025
52f6e20
DI-26927 fixed review comments from API v4 team
srbhaakamai Sep 18, 2025
efdbea8
fixed review comments from APIv4 team
srbhaakamai Sep 18, 2025
0ea97d6
fixed lint errors
srbhaakamai Sep 19, 2025
0ab0687
Update linode_api4/groups/monitor.py
srbhaakamai Sep 19, 2025
a91f384
Update linode_api4/groups/monitor.py
srbhaakamai Sep 19, 2025
86782a8
fixed review errors
srbhaakamai Sep 19, 2025
9775ab2
fixed unittest
srbhaakamai Sep 19, 2025
c39a19d
fixed unittest
srbhaakamai Sep 19, 2025
d327b02
fixed unittest
srbhaakamai Sep 19, 2025
4e1384e
fixed unittest
srbhaakamai Sep 19, 2025
e71320d
fixed unittest
srbhaakamai Sep 20, 2025
cabde89
fixed unittest
srbhaakamai Sep 20, 2025
bb157b7
added update use case to integration test
srbhaakamai Sep 21, 2025
4f1c7db
Merge branch 'linode:dev' into dev
srbhaakamai Sep 29, 2025
b4e2128
Update linode_api4/objects/monitor.py
srbhaakamai Sep 29, 2025
7550bb4
Update linode_api4/objects/monitor.py
srbhaakamai Sep 29, 2025
559e9e7
Update linode_api4/objects/monitor.py
srbhaakamai Sep 29, 2025
f1861cd
Update linode_api4/objects/monitor.py
srbhaakamai Sep 29, 2025
b626bf9
fixed further review comments
srbhaakamai Sep 29, 2025
e459ac8
Updated integration test
srbhaakamai Sep 29, 2025
e595a72
Updated integration test with more assert statements
srbhaakamai Sep 29, 2025
4132d1b
Fix Linode interfaces property (#604)
srbhaakamai Oct 3, 2025
ce9ad27
Fix test for interfaces (#605)
srbhaakamai Oct 3, 2025
d2a519d
Fix test
srbhaakamai Oct 3, 2025
f5503a4
changed as per github-advanced-security comments
srbhaakamai Oct 2, 2025
31198da
fixed formatting errors using python black
srbhaakamai Oct 3, 2025
7d1dd7e
Migrate test fixtures discovery to be with pathlib (#599)
srbhaakamai Oct 3, 2025
e8c35d1
Merge branch 'linode:dev' into dev
srbhaakamai Oct 4, 2025
23c4071
Update linode_api4/objects/monitor.py
srbhaakamai Oct 6, 2025
d90f992
Merge branch 'dev' into dev
zliang-akamai Oct 7, 2025
df6370f
Fixed Copilot comments on unit and integration tests
srbhaakamai Oct 8, 2025
5694f6e
corrected unit test assert statement
srbhaakamai Oct 8, 2025
0864866
Added comment as per copilot suggestion for save() and delete()
srbhaakamai Oct 8, 2025
5c35c8a
resolved comments from copilot commented whereever not applicable
srbhaakamai Oct 8, 2025
205ed92
Merge branch 'dev' into dev
srbhaakamai Oct 12, 2025
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
147 changes: 143 additions & 4 deletions linode_api4/groups/monitor.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
__all__ = [
"MonitorGroup",
]
from typing import Any, Optional
from typing import Any, Optional, Union

from linode_api4 import PaginatedList
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import (
AlertChannel,
AlertDefinition,
MonitorDashboard,
MonitorMetricsDefinition,
MonitorService,
MonitorServiceToken,
)

__all__ = [
"MonitorGroup",
]


class MonitorGroup(Group):
"""
Expand Down Expand Up @@ -145,3 +148,139 @@ def create_token(
"Unexpected response when creating token!", json=result
)
return MonitorServiceToken(token=result["token"])

def alert_definitions(
self,
*filters,
service_type: Optional[str] = None,
) -> Union[PaginatedList]:
"""
Retrieve alert definitions.

Returns a paginated collection of :class:`AlertDefinition` objects. If you
need to obtain a single :class:`AlertDefinition`, use :meth:`LinodeClient.load`
and supply the `service_type` as the parent identifier, for example:

alerts = client.monitor.alert_definitions()
alerts_by_service = client.monitor.alert_definitions(service_type="dbaas")
.. note:: This endpoint is in beta and requires using the v4beta base URL.

API Documentation:
https://techdocs.akamai.com/linode-api/reference/get-alert-definitions
https://techdocs.akamai.com/linode-api/reference/get-alert-definitions-for-service-type

:param service_type: Optional service type to scope the query (e.g. ``"dbaas"``).
:type service_type: Optional[str]
:param filters: Optional filtering expressions to apply to the returned
collection. See :doc:`Filtering Collections</linode_api4/objects/filtering>`.

:returns: A paginated list of :class:`AlertDefinition` objects.
:rtype: PaginatedList[AlertDefinition]
"""

endpoint = "/monitor/alert-definitions"
if service_type:
endpoint = f"/monitor/services/{service_type}/alert-definitions"

# Requesting a list
return self.client._get_and_filter(
AlertDefinition, *filters, endpoint=endpoint
)

def alert_channels(self, *filters) -> PaginatedList:
"""
List alert channels for the authenticated account.

Returns a paginated collection of :class:`AlertChannel` objects which
describe destinations for alert notifications (for example: email
lists, webhooks, PagerDuty, Slack, etc.). By default this method
returns all channels visible to the authenticated account; you can
supply optional filter expressions to restrict the results.

Examples:
channels = client.monitor.alert_channels()

.. 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

:param filters: Optional filter expressions to apply to the collection.
See :doc:`Filtering Collections</linode_api4/objects/filtering>` for details.
:returns: A paginated list of :class:`AlertChannel` objects.
:rtype: PaginatedList[AlertChannel]
"""
return self.client._get_and_filter(AlertChannel, *filters)

def create_alert_definition(
self,
service_type: str,
label: str,
severity: int,
channel_ids: list[int],
rule_criteria: dict = None,
trigger_conditions: dict = None,
entity_ids: Optional[list[str]] = None,
description: Optional[str] = None,
) -> AlertDefinition:
"""
Create a new alert definition for a given service type.

The alert definition configures when alerts are fired and which channels
are notified.

.. note:: This endpoint is in beta and requires using the v4beta base URL.

API Documentation: https://techdocs.akamai.com/linode-api/reference/post-alert-definition-for-service-type

:param service_type: Service type for which to create the alert definition
(e.g. ``"dbaas"``).
:type service_type: str
:param label: Human-readable label for the alert definition.
:type label: str
:param severity: Severity level for the alert (numeric severity used by API).
:type severity: int
:param channel_ids: List of alert channel IDs to notify when the alert fires.
:type channel_ids: list[int]
:param rule_criteria: (Optional) Rule criteria that determine when the alert
should be evaluated. Structure depends on the service
metric definitions.
:type rule_criteria: Optional[dict]
:param trigger_conditions: (Optional) Trigger conditions that define when
the alert should transition state.
:type trigger_conditions: Optional[dict]
:param entity_ids: (Optional) Restrict the alert to a subset of entity IDs.
:type entity_ids: Optional[list[str]]
:param description: (Optional) Longer description for the alert definition.
:type description: Optional[str]

:returns: The newly created :class:`AlertDefinition`.
:rtype: AlertDefinition

NOTE:
# For updating an alert definition, use the `save()` method on the AlertDefinition object.
# For deleting an alert definition, use the `delete()` method directly on the AlertDefinition object.
"""
params = {
"label": label,
"severity": severity,
"channel_ids": channel_ids,
"rule_criteria": rule_criteria,
"trigger_conditions": trigger_conditions,
}
if description is not None:
params["description"] = description
if entity_ids is not None:
params["entity_ids"] = entity_ids

# API will handle check for service_type return error if missing
result = self.client.post(
f"/monitor/services/{service_type}/alert-definitions", data=params
)

if "id" not in result:
raise UnexpectedResponseError(
"Unexpected response when creating alert definition!",
json=result,
)

return AlertDefinition(self.client, result["id"], service_type, result)
Loading