Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PagerDuty Migrator: Add filtering capabilities and fix user notification rule preservation #5454

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

joeyorlando
Copy link
Contributor

@joeyorlando joeyorlando commented Feb 14, 2025

This PR adds filtering capabilities to the PagerDuty migrator tool and fixes user notification rule preservation behavior.

Closes https://github.com/grafana/irm/issues/612

Changes

1. Added Resource Filtering

Added the ability to filter PagerDuty resources during migration based on:

  • Team membership
  • User association
  • Name patterns (using regex)

New environment variables for filtering:

PAGERDUTY_FILTER_TEAM
PAGERDUTY_FILTER_USERS
PAGERDUTY_FILTER_SCHEDULE_REGEX
PAGERDUTY_FILTER_ESCALATION_POLICY_REGEX
PAGERDUTY_FILTER_INTEGRATION_REGEX

Example Usage

Filter by team:

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="plan" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
-e PAGERDUTY_FILTER_TEAM="SRE Team" \
oncall-migrator

Filter by specific users:

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="plan" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
-e PAGERDUTY_FILTER_USERS="P123ABC,P456DEF" \
oncall-migrator

Filter schedules by name pattern:

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="plan" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
-e PAGERDUTY_FILTER_SCHEDULE_REGEX="^(Primary|Secondary)" \
oncall-migrator

Filter escalation policies by name pattern:

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="plan" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
-e PAGERDUTY_FILTER_ESCALATION_POLICY_REGEX="^Prod" \
oncall-migrator

Filter integrations by name pattern:

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="plan" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
-e PAGERDUTY_FILTER_INTEGRATION_REGEX="Prometheus$" \
oncall-migrator

2. Fixed User Notification Rule Preservation

Introduces a PRESERVE_EXISTING_USER_NOTIFICATION_RULES config (default of true). The migrator now:

  • does not delete user notification rules in Grafana OnCall, if the Grafana user already has some defined, AND PRESERVE_EXISTING_USER_NOTIFICATION_RULES is True
    • if the Grafana user has no personal notification rules defined in OnCall, we will create them
  • deletes existing user notification rules, and creates new ones, in Grafana OnCall, if PRESERVE_EXISTING_USER_NOTIFICATION_RULES is False
    • basically make sure that the state in Grafana OnCall matches the latest state in PagerDuty
  • Improves logging to clearly indicate when rules are being preserved

Example Usage

Preserve existing notification policies (default):

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="migrate" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
oncall-migrator

Replace existing notification policies:

docker run --rm \
-e MIGRATING_FROM="pagerduty" \
-e MODE="migrate" \
-e ONCALL_API_URL="<your-oncall-api-url>" \
-e ONCALL_API_TOKEN="<your-oncall-api-token>" \
-e PAGERDUTY_API_TOKEN="<your-pd-api-token>" \
-e PRESERVE_EXISTING_USER_NOTIFICATION_RULES="false" \
oncall-migrator

3. Improved Testing

Added comprehensive test coverage for filtering functionality and updated user notification rule preservation tests

Testing Done

  • Manual testing of filtering capabilities in both plan and migrate modes
  • Verified notification policy preservation behavior

- Add filtering by team, users, and regex patterns for schedules, escalation policies, and integrations
- Fix notification policy preservation behavior
- Add comprehensive test coverage for new features
- Add filter_schedules, filter_escalation_policies, and filter_integrations functions
- Add comprehensive test coverage for filtering functionality
- Add dedicated notification rules tests
- Fix notification rules preservation behavior
- Add dedicated test file for notification rules
- Improve test coverage for notification policy scenarios
@@ -20,6 +20,7 @@
"Zabbix Webhook (for 5.0 and 5.2)": "zabbix",
"Elastic Alerts": "elastalert",
"Firebase": "fabric",
"Amazon CloudWatch": "amazon_sns",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was a request to map Amazon CloudWatch Integration in PagerDuty to our Amazon SNS Integration (apparently these are essentially the same thing?)

@joeyorlando joeyorlando changed the title PagerDuty Migrator: Add filtering capabilities and fix notification policy preservation PagerDuty Migrator: Add filtering capabilities and fix user notification rule preservation Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant