Skip to content

Commit

Permalink
Make PD plugin aware of escalation policy rule types (#1499)
Browse files Browse the repository at this point in the history
* Make PD plugin aware of escalation policy rule types

* Update src/dispatch/plugins/dispatch_pagerduty/service.py

* Update src/dispatch/plugins/dispatch_pagerduty/service.py

Co-authored-by: Yurii Matsiuk <[email protected]>
Co-authored-by: kevgliss <[email protected]>
Co-authored-by: Marc Vilanova <[email protected]>
  • Loading branch information
4 people authored Aug 3, 2021
1 parent dce6036 commit e22eb9d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/dispatch/plugins/dispatch_pagerduty/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ def get_oncall_email(client, service: dict) -> str:
"""Fetches the oncall's email for a given service."""
escalation_policy_id = service["escalation_policy"]["id"]
escalation_policy = client.rget(f"/escalation_policies/{escalation_policy_id}")
schedule_id = escalation_policy["escalation_rules"][0]["targets"][0]["id"]
filter_name = (
f"{escalation_policy['escalation_rules'][0]['targets'][0]['type'].split('_')[0]}_ids[]"
)
filter_value = escalation_policy["escalation_rules"][0]["targets"][0]["id"]

oncalls = list(
client.iter_all(
"oncalls", # method
{
# "include[]": "users", # including users doesn't give us the contact details
"schedule_ids[]": [schedule_id],
filter_name: [filter_value],
"escalation_policy_ids[]": [escalation_policy_id],
}, # params
)
Expand Down

0 comments on commit e22eb9d

Please sign in to comment.