Skip to content

Commit 56b2aaa

Browse files
committed
Merge github.com:Yelp/elastalert into fix_497
2 parents 1e7082b + 325f1df commit 56b2aaa

File tree

5 files changed

+521
-1
lines changed

5 files changed

+521
-1
lines changed

docs/source/ruletypes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,15 @@ Optional:
16481648

16491649
``opsgenie_priority``: Set the OpsGenie priority level. Possible values are P1, P2, P3, P4, P5.
16501650

1651+
``opsgenie_details``: Map of custom key/value pairs to include in the alert's details. The value can sourced from either fields in the first match, environment variables, or a constant value.
1652+
1653+
Example usage::
1654+
1655+
opsgenie_details:
1656+
Author: 'Bob Smith' # constant value
1657+
Environment: '$VAR' # environment variable
1658+
Message: { field: message } # field in the first match
1659+
16511660
SNS
16521661
~~~
16531662

@@ -1781,6 +1790,12 @@ Provide absolute address of the pciture, for example: http://some.address.com/im
17811790

17821791
``slack_timeout``: You can specify a timeout value, in seconds, for making communicating with Slac. The default is 10. If a timeout occurs, the alert will be retried next time elastalert cycles.
17831792

1793+
``slack_attach_kibana_discover_url``: Enables the attachment of the ``kibana_discover_url`` to the slack notification. The config ``generate_kibana_discover_url`` must also be ``True`` in order to generate the url. Defaults to ``False``.
1794+
1795+
``slack_kibana_discover_color``: The color of the Kibana Discover url attachment. Defaults to ``#ec4b98``.
1796+
1797+
``slack_kibana_discover_title``: The title of the Kibana Discover url attachment. Defaults to ``Discover in Kibana``.
1798+
17841799
Mattermost
17851800
~~~~~~~~~~
17861801

elastalert/alerts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,9 @@ def __init__(self, rule):
11291129
self.slack_ignore_ssl_errors = self.rule.get('slack_ignore_ssl_errors', False)
11301130
self.slack_timeout = self.rule.get('slack_timeout', 10)
11311131
self.slack_ca_certs = self.rule.get('slack_ca_certs')
1132+
self.slack_attach_kibana_discover_url = self.rule.get('slack_attach_kibana_discover_url', False)
1133+
self.slack_kibana_discover_color = self.rule.get('slack_kibana_discover_color', '#ec4b98')
1134+
self.slack_kibana_discover_title = self.rule.get('slack_kibana_discover_title', 'Discover in Kibana')
11321135

11331136
def format_body(self, body):
11341137
# https://api.slack.com/docs/formatting
@@ -1191,6 +1194,15 @@ def alert(self, matches):
11911194
if self.slack_title_link != '':
11921195
payload['attachments'][0]['title_link'] = self.slack_title_link
11931196

1197+
if self.slack_attach_kibana_discover_url:
1198+
kibana_discover_url = lookup_es_key(matches[0], 'kibana_discover_url')
1199+
if kibana_discover_url:
1200+
payload['attachments'].append({
1201+
'color': self.slack_kibana_discover_color,
1202+
'title': self.slack_kibana_discover_title,
1203+
'title_link': kibana_discover_url
1204+
})
1205+
11941206
for url in self.slack_webhook_url:
11951207
for channel_override in self.slack_channel_override:
11961208
try:

elastalert/opsgenie.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import json
33
import logging
4-
4+
import os.path
55
import requests
66

77
from .alerts import Alerter
@@ -33,6 +33,7 @@ def __init__(self, *args):
3333
self.alias = self.rule.get('opsgenie_alias')
3434
self.opsgenie_proxy = self.rule.get('opsgenie_proxy', None)
3535
self.priority = self.rule.get('opsgenie_priority')
36+
self.opsgenie_details = self.rule.get('opsgenie_details', {})
3637

3738
def _parse_responders(self, responders, responder_args, matches, default_responders):
3839
if responder_args:
@@ -97,6 +98,10 @@ def alert(self, matches):
9798
if self.alias is not None:
9899
post['alias'] = self.alias.format(**matches[0])
99100

101+
details = self.get_details(matches)
102+
if details:
103+
post['details'] = details
104+
100105
logging.debug(json.dumps(post))
101106

102107
headers = {
@@ -162,3 +167,19 @@ def get_info(self):
162167
if self.teams:
163168
ret['teams'] = self.teams
164169
return ret
170+
171+
def get_details(self, matches):
172+
details = {}
173+
174+
for key, value in self.opsgenie_details.items():
175+
176+
if type(value) is dict:
177+
if 'field' in value:
178+
field_value = lookup_es_key(matches[0], value['field'])
179+
if field_value is not None:
180+
details[key] = str(field_value)
181+
182+
elif type(value) is str:
183+
details[key] = os.path.expandvars(value)
184+
185+
return details

elastalert/schema.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ properties:
286286
slack_text_string: {type: string}
287287
slack_ignore_ssl_errors: {type: boolean}
288288
slack_ca_certs: {type: string}
289+
slack_attach_kibana_discover_url {type: boolean}
290+
slack_kibana_discover_color {type: string}
291+
slack_kibana_discover_title {type: string}
289292

290293
### Mattermost
291294
mattermost_webhook_url: *arrayOfString
@@ -298,6 +301,20 @@ properties:
298301
mattermost_msg_pretext: {type: string}
299302
mattermost_msg_fields: *mattermostField
300303

304+
## Opsgenie
305+
opsgenie_details:
306+
type: object
307+
minProperties: 1
308+
patternProperties:
309+
"^.+$":
310+
oneOf:
311+
- type: string
312+
- type: object
313+
additionalProperties: false
314+
required: [field]
315+
properties:
316+
field: {type: string, minLength: 1}
317+
301318
### PagerDuty
302319
pagerduty_service_key: {type: string}
303320
pagerduty_client_name: {type: string}

0 commit comments

Comments
 (0)