I have a python program that generates Pagerduty(PD) alerts using pdpyras libraries. I have a case where i need to resolve the PD alerts automatically if the issue is not found in next run. When creating alert, I am passing dedup_key
and title
. The title
varies according to state of infra (offline, broken, down). I want to resolve the alerts using dedup_key
. There is a library function for resolving alert but i have too many items in good state that if I send blind resolve api for each of them, I will get a 429 (too many request) from Pagerduty.
What I want to do is to search for alert matching the dedup_key (if exists) and resolve only those alerts but there is no v2 search api. I am struggling to get pagerduty incident dedup key using API.
I also attempted to add a string same as dedup_key in custom_details
field of the trigger(…) function in pdpyras as workaround and i see the fields in PD UI but when I retrieve the open incidents via API, I don’t see the custom_details field in api response.
Need some help here.
Code snippet
def search_alert(self, dedup_key):
self.all_active_incidents = self.session.list_all(
'incidents',
params={'statuses[]': ['triggered', 'acknowledged']}
)
for incident in self.all_active_incidents:
if incident['dedup_key'] == dedup_key:
return incident
return None
def resolve_alert(self ,dedup_key):
'''
Resolve incident in pagerduty
:param dedup_key: dedup key of the incident
:return: dedup key of the resolved incident
'''
return self.v2_session.resolve(dedup_key=dedup_key)
def create_alert(self, title, dedup_key, source="..."):
dedup_key = self.v2_session.trigger(title, source=source, dedup_key=dedup_key)
return dedup_key