Skip to content

Commit 1da295b

Browse files
authored
Merge pull request #36 from Zentrust/master
Add support for custom_details in the PagerDuty alerter v2 module
2 parents 168b2f8 + 62924c4 commit 1da295b

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

docs/source/ruletypes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,11 @@ See https://developer.pagerduty.com/docs/events-api-v2/trigger-events/
19261926

19271927
``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.
19281928

1929+
``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.
1930+
1931+
``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.
1932+
1933+
19291934
PagerTree
19301935
~~~~~~~~~
19311936

elastalert/alerts.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,8 @@ def __init__(self, rule):
12751275
self.pagerduty_v2_payload_severity = self.rule.get('pagerduty_v2_payload_severity', 'critical')
12761276
self.pagerduty_v2_payload_source = self.rule.get('pagerduty_v2_payload_source', 'ElastAlert')
12771277
self.pagerduty_v2_payload_source_args = self.rule.get('pagerduty_v2_payload_source_args', None)
1278+
self.pagerduty_v2_payload_custom_details = self.rule.get('pagerduty_v2_payload_custom_details', {})
1279+
self.pagerduty_v2_payload_include_all_info = self.rule.get('pagerduty_v2_payload_include_all_info', True)
12781280

12791281
if self.pagerduty_api_version == 'v2':
12801282
self.url = 'https://events.pagerduty.com/v2/enqueue'
@@ -1287,6 +1289,13 @@ def alert(self, matches):
12871289
# post to pagerduty
12881290
headers = {'content-type': 'application/json'}
12891291
if self.pagerduty_api_version == 'v2':
1292+
1293+
custom_details_payload = {'information': body} if self.pagerduty_v2_payload_include_all_info else {}
1294+
if self.pagerduty_v2_payload_custom_details:
1295+
for match in matches:
1296+
for custom_details_key, es_key in list(self.pagerduty_v2_payload_custom_details.items()):
1297+
custom_details_payload[custom_details_key] = lookup_es_key(match, es_key)
1298+
12901299
payload = {
12911300
'routing_key': self.pagerduty_service_key,
12921301
'event_action': self.pagerduty_event_type,
@@ -1307,9 +1316,7 @@ def alert(self, matches):
13071316
self.pagerduty_v2_payload_source_args,
13081317
matches),
13091318
'summary': self.create_title(matches),
1310-
'custom_details': {
1311-
'information': body,
1312-
},
1319+
'custom_details': custom_details_payload,
13131320
},
13141321
}
13151322
match_timestamp = lookup_es_key(matches[0], self.rule.get('timestamp_field', '@timestamp'))

0 commit comments

Comments
 (0)