Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/ruletypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,11 @@ See https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

``pagerduty_v2_payload_source_args``: If set, and ``pagerduty_v2_payload_source`` is a formattable string, Elastalert will format the source based on the provided array of fields from the rule or match.

``pagerduty_v2_payload_custom_details``: List of keys:values to use as the content of the custom_details payload. Example - ip:clientip will map the value from the clientip index of Elasticsearch to JSON key named ip.

``pagerduty_v2_payload_include_all_info``: If True, this will include the entire Elasticsearch document as a custom detail field called "information" in the PagerDuty alert.


PagerTree
~~~~~~~~~

Expand Down
13 changes: 10 additions & 3 deletions elastalert/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,8 @@ def __init__(self, rule):
self.pagerduty_v2_payload_severity = self.rule.get('pagerduty_v2_payload_severity', 'critical')
self.pagerduty_v2_payload_source = self.rule.get('pagerduty_v2_payload_source', 'ElastAlert')
self.pagerduty_v2_payload_source_args = self.rule.get('pagerduty_v2_payload_source_args', None)
self.pagerduty_v2_payload_custom_details = self.rule.get('pagerduty_v2_payload_custom_details', {})
self.pagerduty_v2_payload_include_all_info = self.rule.get('pagerduty_v2_payload_include_all_info', True)

if self.pagerduty_api_version == 'v2':
self.url = 'https://events.pagerduty.com/v2/enqueue'
Expand All @@ -1369,6 +1371,13 @@ def alert(self, matches):
# post to pagerduty
headers = {'content-type': 'application/json'}
if self.pagerduty_api_version == 'v2':

custom_details_payload = {'information': body} if self.pagerduty_v2_payload_include_all_info else {}
if self.pagerduty_v2_payload_custom_details:
for match in matches:
for custom_details_key, es_key in list(self.pagerduty_v2_payload_custom_details.items()):
custom_details_payload[custom_details_key] = lookup_es_key(match, es_key)

payload = {
'routing_key': self.pagerduty_service_key,
'event_action': self.pagerduty_event_type,
Expand All @@ -1389,9 +1398,7 @@ def alert(self, matches):
self.pagerduty_v2_payload_source_args,
matches),
'summary': self.create_title(matches),
'custom_details': {
'information': body,
},
'custom_details': custom_details_payload,
},
}
match_timestamp = lookup_es_key(matches[0], self.rule.get('timestamp_field', '@timestamp'))
Expand Down