## Summary of Changes ### Improved Filtering Logic - Changed filtering logic to use OR operations between filter types (team, users, regex) - Resources matching ANY filter are now included in the migration - Made filtering more intuitive and aligned with user expectations ### New `PAGERDUTY_FILTER_USERS` option for `add_users_to_grafana.py` script - This new config (environment variable) allows importing only a subset of users from your PagerDuty instance. - Added full test coverage for `add_users_to_grafana.py` - Updated documentation to reflect latest changes ### Added Verbose Logging Option - Added `PAGERDUTY_VERBOSE_LOGGING` environment variable to control output verbosity - When disabled, only shows summary counts without detailed per-resource output - Significantly reduces output for large PagerDuty instances ### Fixed User Handling - Properly skips user fetching and processing when `MIGRATE_USERS=false` - Marks schedules and escalation policies properly when not migrating users - When `MIGRATE_USERS=true` and `PAGERDUTY_FILTER_USERS` is set, only those specific users are migrated ### Added Migration Progress Summary - Shows counts of filtered resources and those eligible for migration - Provides better visibility into the migration process ### Updated Tests - Added comprehensive tests for the new OR-based filtering logic - Added tests for user filtering - Added tests for verbose and non-verbose logging modes ### Updated Documentation - Clearly documented the new filtering behavior - Explained the verbose logging option - Updated configuration descriptions to be more accurate These changes address issues with filtering behavior and user handling, making the PagerDuty migrator more intuitive, efficient, and flexible.
75 lines
2.9 KiB
Python
75 lines
2.9 KiB
Python
import os
|
|
|
|
from lib.base_config import * # noqa: F401,F403
|
|
|
|
PAGERDUTY_API_TOKEN = os.environ["PAGERDUTY_API_TOKEN"]
|
|
PAGERDUTY_TO_ONCALL_CONTACT_METHOD_MAP = {
|
|
"sms_contact_method": "notify_by_sms",
|
|
"phone_contact_method": "notify_by_phone_call",
|
|
"email_contact_method": "notify_by_email",
|
|
"push_notification_contact_method": "notify_by_mobile_app",
|
|
}
|
|
PAGERDUTY_TO_ONCALL_VENDOR_MAP = {
|
|
"Datadog": "datadog",
|
|
"Pingdom": "pingdom",
|
|
"Prometheus": "alertmanager",
|
|
"PRTG": "prtg",
|
|
"Stackdriver": "stackdriver",
|
|
"UptimeRobot": "uptimerobot",
|
|
"New Relic": "newrelic",
|
|
"Zabbix Webhook (for 5.0 and 5.2)": "zabbix",
|
|
"Elastic Alerts": "elastalert",
|
|
"Firebase": "fabric",
|
|
"Amazon CloudWatch": "amazon_sns",
|
|
}
|
|
|
|
# Experimental feature to migrate PD rulesets to OnCall integrations
|
|
EXPERIMENTAL_MIGRATE_EVENT_RULES = (
|
|
os.getenv("EXPERIMENTAL_MIGRATE_EVENT_RULES", "false").lower() == "true"
|
|
)
|
|
# Set to true to include service & integration names in the ruleset name
|
|
EXPERIMENTAL_MIGRATE_EVENT_RULES_LONG_NAMES = (
|
|
os.getenv("EXPERIMENTAL_MIGRATE_EVENT_RULES_LONG_NAMES", "false").lower() == "true"
|
|
)
|
|
|
|
# Set to true to migrate unsupported integrations to OnCall webhook integration
|
|
# https://grafana.com/docs/oncall/latest/integrations/available-integrations/configure-webhook/
|
|
UNSUPPORTED_INTEGRATION_TO_WEBHOOKS = (
|
|
os.getenv("UNSUPPORTED_INTEGRATION_TO_WEBHOOKS", "false").lower() == "true"
|
|
)
|
|
|
|
MIGRATE_USERS = os.getenv("MIGRATE_USERS", "true").lower() == "true"
|
|
|
|
# Whether to migrate PagerDuty services to Grafana's service model
|
|
PAGERDUTY_MIGRATE_SERVICES = (
|
|
os.getenv("PAGERDUTY_MIGRATE_SERVICES", "false").lower() == "true"
|
|
)
|
|
|
|
# Filter resources by team
|
|
PAGERDUTY_FILTER_TEAM = os.getenv("PAGERDUTY_FILTER_TEAM", "")
|
|
|
|
# Filter resources by users (comma-separated list of PagerDuty user IDs)
|
|
PAGERDUTY_FILTER_USERS = (
|
|
os.getenv("PAGERDUTY_FILTER_USERS", "").split(",")
|
|
if os.getenv("PAGERDUTY_FILTER_USERS")
|
|
else []
|
|
)
|
|
|
|
# Filter resources by name regex patterns
|
|
PAGERDUTY_FILTER_SCHEDULE_REGEX = os.getenv("PAGERDUTY_FILTER_SCHEDULE_REGEX", "")
|
|
PAGERDUTY_FILTER_ESCALATION_POLICY_REGEX = os.getenv(
|
|
"PAGERDUTY_FILTER_ESCALATION_POLICY_REGEX", ""
|
|
)
|
|
PAGERDUTY_FILTER_INTEGRATION_REGEX = os.getenv("PAGERDUTY_FILTER_INTEGRATION_REGEX", "")
|
|
|
|
# Filter services by name regex pattern. Only applies to services being migrated to Grafana's service model.
|
|
# This filter can be used to selectively migrate specific services based on their names.
|
|
PAGERDUTY_FILTER_SERVICE_REGEX = os.getenv("PAGERDUTY_FILTER_SERVICE_REGEX", "")
|
|
|
|
# Whether to preserve existing notification rules when migrating users
|
|
PRESERVE_EXISTING_USER_NOTIFICATION_RULES = (
|
|
os.getenv("PRESERVE_EXISTING_USER_NOTIFICATION_RULES", "true").lower() == "true"
|
|
)
|
|
|
|
# Environment variable to control verbose logging
|
|
VERBOSE_LOGGING = os.getenv("PAGERDUTY_VERBOSE_LOGGING", "false").lower() == "true"
|