Skip to content

Python SDK for ACLP Alerts #589

Merged
yec-akamai merged 127 commits intolinode:devfrom
srbhaakamai:dev
Dec 2, 2025
Merged

Python SDK for ACLP Alerts #589
yec-akamai merged 127 commits intolinode:devfrom
srbhaakamai:dev

Conversation

@srbhaakamai
Copy link
Copy Markdown
Contributor

@srbhaakamai srbhaakamai commented Sep 1, 2025

📝 Description

Add Monitor alerting SDK + fix/harden monitor unit & integration tests

What does this PR do and why is this change necessary?

  1. Adds full SDK support for Monitor alert definitions (create / get / update / delete) used by tests and examples.
  2. Fixes serialization so JSONObject payloads containing Enum values serialize to primitives (prevents json.dumps errors).
  3. Adds and updates unit fixtures and monitor unit tests; adds integration test coverage for create → update → delete alert definitions.
  4. Makes integration fixtures resilient to tokens lacking certain scopes (skips firewall / DB provisioning when unauthorized) to allow running partial E2E locally.

This change is necessary because:

  1. Unit tests were failing due to missing Enum serialization and missing mock helpers.
  2. Integration tests would fail the whole session on tokens without cloud networking / DB scopes. Making fixtures skip when unauthorized lets developers iterate locally without privileged tokens.
  3. Adding SDK monitor methods enables first-class programmatic control over alert definitions as documented in the API (POST /monitor/services/{service_type}/alert-definitions).

SDK additions (high level)

  1. MonitorGroup methods (exposed on client.monitor):
  2. alert_definitions(service_type, alert_id=None) — list or get
  3. create_alert_definition(service_type, label, severity, type, description, channel_ids, trigger_conditions, rule_criteria, notification_groups, conditions)
  4. update_alert_definition(service_type, alert_id, **fields) or client.monitor.update_alert_definition(...)
  5. delete_alert_definition(service_type, alert_id)
  6. alert_channels() — list alert channels
  7. These map to the Monitor Alert Definition endpoints per docs: https://techdocs.akamai.com/linode-api/reference/post-alert-definition-for-service-type

Note:

  1. severity must be integer.
  2. trigger_conditions.polling_interval_seconds and evaluation_period_seconds must be API-allowed values (for these services 300s in our tests).
  3. label/description must begin and end with an alphanumeric character.

✔️ How to Test

Clone the repository
Prepare environment (zsh / macOS)

✔️create & activate venv (recommended)

python3 -m venv .venv
source .venv/bin/activate

install deps
python -m pip install --upgrade pip

Install runtime dependencies:
pip3 install requests polling deprecated

Install dev/test extras
pip3 install -e '.[dev,test]'

test deps
pip3 install pytest mock httpretty pytest-rerunfailures

✔️How do I run the relevant unit tests?

cd <PROJECT_DIRECTORY>/linode_api4-python
Unit tests: python -m pytest test/unit -q
377 passed, 18 warnings in 0.79s (as on 8Oct2025) new test cases may be added later

Unit test for all monitor: python -m pytest test/unit/groups/monitor_api_test.py -q -s
3 passed, 1 warning in 0.10s

Single unit: python -m pytest test/unit/groups/monitor_api_test.py::MonitorAlertDefinitionsTest -q -s
2 passed, 1 warning in 0.09s

What are the steps to reproduce the issue or verify the changes?
Its a new feature, so end to end integration should suffice

✔️How do I run the relevant integration tests?

Integration tests (E2E):
Note:
#if you have PAT token with write access only to Monitor and read for rest of the services for integration
export SKIP_E2E_FIREWALL=1 # optional: skip firewall autouse fixture

export LINODE_TOKEN="YOUR_REAL_TOKEN" # required for integration
export SKIP_E2E_FIREWALL=1 # optional: skip firewall autouse fixture
python -m pytest test/integration/models/monitor/test_monitor.py::test_integration_create_get_update_delete_alert_definition -q -s

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

project for new projects in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants