Skip to content

Commit

Permalink
fix: pagerduty to get single incident (#2726)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Dec 2, 2024
1 parent f976451 commit 70d9caf
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions keep/providers/pagerduty_provider/pagerduty_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 70d9caf

Please sign in to comment.