Skip to content

feat: add maintenance window lifecycle workflow triggers#6615

Open
aditya-786 wants to merge 2 commits into
keephq:mainfrom
aditya-786:feat/maintenance-window-workflow-triggers
Open

feat: add maintenance window lifecycle workflow triggers#6615
aditya-786 wants to merge 2 commits into
keephq:mainfrom
aditya-786:feat/maintenance-window-workflow-triggers

Conversation

@aditya-786

Copy link
Copy Markdown
Contributor

Summary

Adds a maintenance workflow trigger so workflows can run when a maintenance window changes. This is the lifecycle-events feature requested in #6532, useful for notifying stakeholders (Slack, PagerDuty, email, etc.) when maintenance is scheduled or removed.

A workflow subscribes to the actions it cares about:

triggers:
  - type: maintenance
    events:
      - created
      - updated
      - deleted

The window is exposed to the workflow through a maintenance context, so steps can template values like {{ maintenance.name }}, {{ maintenance.cel_query }}, {{ maintenance.start_time }} and {{ maintenance.end_time }}.

How it works

This mirrors the existing incident trigger end to end:

  • MaintenanceWindowDto is the event object passed to the workflow (in keep/api/models/db/maintenance_window.py).
  • WorkflowManager.insert_maintenance enqueues every enabled workflow subscribed to the fired action, reusing a small get_maintenance_events helper for the trigger matching (mirrors insert_incident).
  • The maintenance CRUD routes call it after commit, wrapped in a try/except so a workflow failure can never break the maintenance API (mirrors IncidentBl.send_workflow_event).
  • WorkflowScheduler and ContextManager route the new DTO through the same paths already used for alerts and incidents (metrics trigger_type, triggered_by label, event_type, and the maintenance context key).

No schema migration and no new background job are required.

Scope

This PR covers the created / updated / deleted actions, which are one-shot hooks on the CRUD routes. The time-based started / ended transitions from the issue are intentionally left for a follow-up, since they need a persisted notified-state and a periodic check and are better reviewed on their own.

Tests

tests/test_maintenance_workflow_trigger.py:

  • get_maintenance_events filters by trigger type and flattens the subscribed actions.
  • insert_maintenance enqueues a matching workflow with triggered_by="maintenance:created" and the window as the event.
  • insert_maintenance skips a workflow when the fired action is not one it subscribed to.

Relates to #6532

Fire workflows when a maintenance window is created, updated, or
deleted, mirroring the existing incident trigger. The maintenance
window is exposed to the workflow through the `maintenance` context.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. Documentation Improvements or additions to documentation Feature A new feature labels Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

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

Labels

Documentation Improvements or additions to documentation Feature A new feature size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant