From 6ccde4a5e2dd1ee5773e6018fffc5ea1ad488dce Mon Sep 17 00:00:00 2001 From: Innokentii Konstantinov Date: Wed, 12 Apr 2023 21:53:38 +0800 Subject: [PATCH] Migrate unsupported integrations to webhook (#1737) ## Which issue(s) this PR fixes https://github.com/grafana/oncall/issues/1718 --- tools/pagerduty-migrator/migrator/config.py | 6 ++++++ tools/pagerduty-migrator/migrator/report.py | 9 ++++++++- .../migrator/resources/integrations.py | 8 +++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/pagerduty-migrator/migrator/config.py b/tools/pagerduty-migrator/migrator/config.py index 21c2013d..e9d65736 100644 --- a/tools/pagerduty-migrator/migrator/config.py +++ b/tools/pagerduty-migrator/migrator/config.py @@ -50,3 +50,9 @@ EXPERIMENTAL_MIGRATE_EVENT_RULES = ( 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" +) diff --git a/tools/pagerduty-migrator/migrator/report.py b/tools/pagerduty-migrator/migrator/report.py index d63dbd0e..f863e71c 100644 --- a/tools/pagerduty-migrator/migrator/report.py +++ b/tools/pagerduty-migrator/migrator/report.py @@ -1,6 +1,7 @@ TAB = " " * 4 SUCCESS_SIGN = "✅" ERROR_SIGN = "❌" +WARNING_SIGN = "⚠️" # TODO: warning sign does not renders properly def format_user(user: dict) -> str: @@ -73,7 +74,13 @@ def format_integration(integration: dict) -> str: ERROR_SIGN, result, policy_name ) else: - result = "{} {}".format(SUCCESS_SIGN, result) + # check if integration not supported, but UNSUPPORTED_INTEGRATION_TO_WEBHOOKS set + if integration.get("converted_to_webhook", False): + result = "{} {} – Webhook integration will be created, Grafana OnCall not support this type directly ".format( + WARNING_SIGN, result + ) + else: + result = "{} {}".format(SUCCESS_SIGN, result) return result diff --git a/tools/pagerduty-migrator/migrator/resources/integrations.py b/tools/pagerduty-migrator/migrator/resources/integrations.py index 9230e9b1..ee7c1281 100644 --- a/tools/pagerduty-migrator/migrator/resources/integrations.py +++ b/tools/pagerduty-migrator/migrator/resources/integrations.py @@ -1,5 +1,8 @@ from migrator import oncall_api_client -from migrator.config import PAGERDUTY_TO_ONCALL_VENDOR_MAP +from migrator.config import ( + PAGERDUTY_TO_ONCALL_VENDOR_MAP, + UNSUPPORTED_INTEGRATION_TO_WEBHOOKS, +) from migrator.utils import find_by_id @@ -36,6 +39,9 @@ def match_integration_type(integration: dict, vendors: list[dict]) -> None: integration["vendor_name"] = vendor_name integration["oncall_type"] = PAGERDUTY_TO_ONCALL_VENDOR_MAP.get(vendor_name) + if UNSUPPORTED_INTEGRATION_TO_WEBHOOKS and integration["oncall_type"] is None: + integration["oncall_type"] = "webhook" + integration["converted_to_webhook"] = True def migrate_integration(integration: dict, escalation_policies: list[dict]) -> None: