From 41f8d4afb19ef1217663bbd94180602d9b3767eb Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Fri, 11 Nov 2022 13:40:43 +0000 Subject: [PATCH] PD migrator: add support for email notifications (#839) --- README.md | 2 +- tools/pagerduty-migrator/README.md | 3 +-- tools/pagerduty-migrator/migrator/config.py | 4 ++-- .../migrator/resources/notification_rules.py | 9 +++++++-- tools/pagerduty-migrator/migrator/tests/test_matching.py | 7 +++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b97cd250..23a8176e 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ See [Grafana docs](https://grafana.com/docs/grafana/latest/administration/plugin ## Further Reading -- _Migration from the PagerDuty_ - [Migrator](https://github.com/grafana/oncall/tree/dev/tools/pagerduty-migrator) +- _Migration from PagerDuty_ - [Migrator](https://github.com/grafana/oncall/tree/dev/tools/pagerduty-migrator) - _Documentation_ - [Grafana OnCall](https://grafana.com/docs/grafana-cloud/oncall/) - _Overview Webinar_ - [YouTube](https://www.youtube.com/watch?v=7uSe1pulgs8) - _How To Add Integration_ - [How to Add Integration](https://github.com/grafana/oncall/tree/dev/engine/config_integrations/README.md) diff --git a/tools/pagerduty-migrator/README.md b/tools/pagerduty-migrator/README.md index 0399bb2c..c3e2f4e9 100644 --- a/tools/pagerduty-migrator/README.md +++ b/tools/pagerduty-migrator/README.md @@ -12,7 +12,6 @@ Resources that can be migrated using this tool: ## Limitations * Not all integration types are supported (e.g. inbound email is not supported) -* Not all notification methods are supported (e.g. emails are not supported) * Migrated on-call schedules in Grafana OnCall will use ICalendar files from PagerDuty * Delays between migrated notification/escalation rules could be slightly different from original. E.g. if you have a 4-minute delay between rules in PagerDuty, the resulting delay in Grafana OnCall will be 5 minutes @@ -78,7 +77,7 @@ docker run --rm \ pd-oncall-migrator ``` -It's possible to specify a default contact method type for user notification rules that cannot be migrated as-is by changing the `ONCALL_DEFAULT_CONTACT_METHOD` env variable. Options are: `sms`, `phone_call`, `slack`, `telegram` (default is `sms`). +It's possible to specify a default contact method type for user notification rules that cannot be migrated as-is by changing the `ONCALL_DEFAULT_CONTACT_METHOD` env variable. Options are: `email`, `sms`, `phone_call`, `slack`, `telegram` (default is `email`). ### After migration diff --git a/tools/pagerduty-migrator/migrator/config.py b/tools/pagerduty-migrator/migrator/config.py index a30804cc..93d2cd68 100644 --- a/tools/pagerduty-migrator/migrator/config.py +++ b/tools/pagerduty-migrator/migrator/config.py @@ -15,12 +15,12 @@ ONCALL_API_URL = urljoin( ONCALL_DELAY_OPTIONS = [1, 5, 15, 30, 60] ONCALL_DEFAULT_CONTACT_METHOD = "notify_by_" + os.getenv( - "ONCALL_DEFAULT_CONTACT_METHOD", default="sms" + "ONCALL_DEFAULT_CONTACT_METHOD", default="email" ) PAGERDUTY_TO_ONCALL_CONTACT_METHOD_MAP = { "sms_contact_method": "notify_by_sms", "phone_contact_method": "notify_by_phone_call", - "email_contact_method": ONCALL_DEFAULT_CONTACT_METHOD, + "email_contact_method": "notify_by_email", "push_notification_contact_method": ONCALL_DEFAULT_CONTACT_METHOD, } PAGERDUTY_TO_ONCALL_VENDOR_MAP = { diff --git a/tools/pagerduty-migrator/migrator/resources/notification_rules.py b/tools/pagerduty-migrator/migrator/resources/notification_rules.py index 39b7a39a..7a26d71f 100644 --- a/tools/pagerduty-migrator/migrator/resources/notification_rules.py +++ b/tools/pagerduty-migrator/migrator/resources/notification_rules.py @@ -1,7 +1,10 @@ import copy from migrator import oncall_api_client -from migrator.config import PAGERDUTY_TO_ONCALL_CONTACT_METHOD_MAP +from migrator.config import ( + ONCALL_DEFAULT_CONTACT_METHOD, + PAGERDUTY_TO_ONCALL_CONTACT_METHOD_MAP, +) from migrator.utils import remove_duplicates, transform_wait_delay @@ -74,7 +77,9 @@ def transform_notification_rule( ) -> list[dict]: contact_method_type = notification_rule["contact_method"]["type"] - oncall_type = PAGERDUTY_TO_ONCALL_CONTACT_METHOD_MAP[contact_method_type] + oncall_type = PAGERDUTY_TO_ONCALL_CONTACT_METHOD_MAP.get( + contact_method_type, ONCALL_DEFAULT_CONTACT_METHOD + ) notify_rule = {"user_id": user_id, "type": oncall_type, "important": False} if not delay: diff --git a/tools/pagerduty-migrator/migrator/tests/test_matching.py b/tools/pagerduty-migrator/migrator/tests/test_matching.py index 7ae8b6dc..4f74e003 100644 --- a/tools/pagerduty-migrator/migrator/tests/test_matching.py +++ b/tools/pagerduty-migrator/migrator/tests/test_matching.py @@ -1233,6 +1233,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR1", "html_url": None, }, + "vendor_name": "Datadog", "service": { "id": "TESTSERVICE1", "summary": "Service", @@ -1294,6 +1295,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR2", "html_url": None, }, + "vendor_name": "Amazon CloudWatch", "service": { "id": "TESTSERVICE1", "summary": "Service", @@ -1338,6 +1340,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR1", "html_url": None, }, + "vendor_name": "Datadog", "service": { "id": "TESTSERVICE2", "summary": "My Application Service", @@ -1382,6 +1385,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR2", "html_url": None, }, + "vendor_name": "Amazon CloudWatch", "service": { "id": "TESTSERVICE2", "summary": "My Application Service", @@ -1426,6 +1430,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR1", "html_url": None, }, + "vendor_name": "Datadog", "service": { "id": "TESTSERVICE2", "summary": "My Application Service", @@ -1470,6 +1475,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR2", "html_url": None, }, + "vendor_name": "Amazon CloudWatch", "service": { "id": "TESTSERVICE2", "summary": "My Application Service", @@ -1514,6 +1520,7 @@ expected_integrations_result = [ "self": "https://api.pagerduty.com/vendors/TESTVENDOR3", "html_url": None, }, + "vendor_name": "Email", "service": { "id": "TESTSERVICE1", "summary": "My Application Service",