PD migrator: add support for email notifications (#839)

This commit is contained in:
Vadim Stepanov 2022-11-11 13:40:43 +00:00 committed by GitHub
parent 5143393e4b
commit 41f8d4afb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 7 deletions

View file

@ -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)

View file

@ -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

View file

@ -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 = {

View file

@ -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:

View file

@ -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",