From 70d9caf9a4e9b50906fe84e06dc51e331468328b Mon Sep 17 00:00:00 2001 From: Tal Date: Mon, 2 Dec 2024 16:44:48 +0200 Subject: [PATCH] fix: pagerduty to get single incident (#2726) --- .../pagerduty_provider/pagerduty_provider.py | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/keep/providers/pagerduty_provider/pagerduty_provider.py b/keep/providers/pagerduty_provider/pagerduty_provider.py index 991b146e0..c1ada8245 100644 --- a/keep/providers/pagerduty_provider/pagerduty_provider.py +++ b/keep/providers/pagerduty_provider/pagerduty_provider.py @@ -593,15 +593,10 @@ def _notify( ) def _query(self, incident_id: str = None): - incidents = self.__get_all_incidents_or_alerts() - return ( - next( - [incident for incident in incidents if incident.id == incident_id], - None, - ) - if incident_id - else incidents - ) + if incident_id: + return self._get_specific_incident(incident_id) + else: + return self.__get_all_incidents_or_alerts() @staticmethod def _format_alert( @@ -694,6 +689,28 @@ def _format_alert_old(event: dict) -> AlertDto: labels=metadata, ) + def _get_specific_incident(self, incident_id: str): + self.logger.info("Getting Incident", extra={"incident_id": incident_id}) + url = f"{self.BASE_API_URL}/incidents/{incident_id}" + params = { + "include[]": [ + "acknowledgers", + "agents", + "assignees", + "conference_bridge", + "custom_fields", + "escalation_policies", + "first_trigger_log_entries", + "priorities", + "services", + "teams", + "users", + ] + } + response = requests.get(url, headers=self.__get_headers(), params=params) + response.raise_for_status() + return response.json() + def __get_all_incidents_or_alerts(self, incident_id: str = None): self.logger.info( "Getting incidents or alerts", extra={"incident_id": incident_id}