Skip to content

Commit

Permalink
Merge pull request #140 from nsano-rururu/add_slack_and_mattermost_se…
Browse files Browse the repository at this point in the history
…tting

Added settings for slack and mattermost
  • Loading branch information
jertel authored May 8, 2021
2 parents 13ec5d6 + 75223b2 commit db15272
Show file tree
Hide file tree
Showing 4 changed files with 1,032 additions and 251 deletions.
28 changes: 28 additions & 0 deletions docs/source/ruletypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,22 @@ Example mattermost_msg_fields::
value: static field
short: false

``mattermost_title_link``: You can add a link in your Slack notification by setting this to a valid URL. Requires mattermost_title to be set. Defaults to "".

``mattermost_footer``: Add a static footer text for alert. Defaults to "".

``mattermost_footer_icon``: A Public Url for a footer icon. Defaults to "".

``mattermost_image_url``: An optional URL to an image file (GIF, JPEG, PNG, BMP, or SVG). Defaults to "".

``mattermost_thumb_url``: An optional URL to an image file (GIF, JPEG, PNG, BMP, or SVG) that is displayed as thumbnail. Defaults to "".

``mattermost_author_name``: An optional name used to identify the author. . Defaults to "".

``mattermost_author_link``: An optional URL used to hyperlink the author_name. Defaults to "".

``mattermost_author_icon``: An optional URL used to display a 16x16 pixel icon beside the author_name. Defaults to "".

Microsoft Teams
~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -2457,6 +2473,18 @@ Example slack_alert_fields::

``slack_footer_icon``: A Public Url for a footer icon. Defaults to "".

``slack_image_url``: An optional URL to an image file (GIF, JPEG, PNG, BMP, or SVG). Defaults to "".

``slack_thumb_url``: An optional URL to an image file (GIF, JPEG, PNG, BMP, or SVG) that is displayed as thumbnail. Defaults to "".

``slack_author_name``: An optional name used to identify the author. Defaults to "".

``slack_author_link``: An optional URL used to hyperlink the author_name. Defaults to "".

``slack_author_icon``: An optional URL used to display a 16x16 pixel icon beside the author_name. Defaults to "".

``slack_msg_pretext``: You can set the message attachment pretext using this option. Defaults to "".

Splunk On-Call (Formerly VictorOps)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
69 changes: 64 additions & 5 deletions elastalert/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,14 @@ def __init__(self, rule):
self.slack_attach_kibana_discover_url = self.rule.get('slack_attach_kibana_discover_url', False)
self.slack_kibana_discover_color = self.rule.get('slack_kibana_discover_color', '#ec4b98')
self.slack_kibana_discover_title = self.rule.get('slack_kibana_discover_title', 'Discover in Kibana')
self.footer = self.rule.get('slack_footer', '')
self.footer_icon = self.rule.get('slack_footer_icon', '')
self.slack_footer = self.rule.get('slack_footer', '')
self.slack_footer_icon = self.rule.get('slack_footer_icon', '')
self.slack_image_url = self.rule.get('slack_image_url', '')
self.slack_thumb_url = self.rule.get('slack_thumb_url', '')
self.slack_author_name = self.rule.get('slack_author_name', '')
self.slack_author_link = self.rule.get('slack_author_link', '')
self.slack_author_icon = self.rule.get('slack_author_icon', '')
self.slack_msg_pretext = self.rule.get('slack_msg_pretext', '')

def format_body(self, body):
# https://api.slack.com/docs/formatting
Expand Down Expand Up @@ -1124,9 +1130,29 @@ def alert(self, matches):
if self.slack_title_link != '':
payload['attachments'][0]['title_link'] = self.slack_title_link

if self.footer != '' and self.footer_icon != '':
payload['attachments'][0]['footer'] = self.footer
payload['attachments'][0]['footer_icon'] = self.footer_icon
if self.slack_footer != '':
payload['attachments'][0]['footer'] = self.slack_footer

if self.slack_footer_icon != '':
payload['attachments'][0]['footer_icon'] = self.slack_footer_icon

if self.slack_image_url != '':
payload['attachments'][0]['image_url'] = self.slack_image_url

if self.slack_thumb_url != '':
payload['attachments'][0]['thumb_url'] = self.slack_thumb_url

if self.slack_author_name != '':
payload['attachments'][0]['author_name'] = self.slack_author_name

if self.slack_author_link != '':
payload['attachments'][0]['author_link'] = self.slack_author_link

if self.slack_author_icon != '':
payload['attachments'][0]['author_icon'] = self.slack_author_icon

if self.slack_msg_pretext != '':
payload['attachments'][0]['pretext'] = self.slack_msg_pretext

if self.slack_attach_kibana_discover_url:
kibana_discover_url = lookup_es_key(matches[0], 'kibana_discover_url')
Expand Down Expand Up @@ -1186,6 +1212,15 @@ def __init__(self, rule):
self.mattermost_msg_pretext = self.rule.get('mattermost_msg_pretext', '')
self.mattermost_msg_color = self.rule.get('mattermost_msg_color', 'danger')
self.mattermost_msg_fields = self.rule.get('mattermost_msg_fields', '')
self.mattermost_image_url = self.rule.get('mattermost_image_url', '')
self.mattermost_title_link = self.rule.get('mattermost_title_link', '')
self.mattermost_footer = self.rule.get('mattermost_footer', '')
self.mattermost_footer_icon = self.rule.get('mattermost_footer_icon', '')
self.mattermost_image_url = self.rule.get('mattermost_image_url', '')
self.mattermost_thumb_url = self.rule.get('mattermost_thumb_url', '')
self.mattermost_author_name = self.rule.get('mattermost_author_name', '')
self.mattermost_author_link = self.rule.get('mattermost_author_link', '')
self.mattermost_author_icon = self.rule.get('mattermost_author_icon', '')

def get_aggregation_summary_text__maximum_width(self):
width = super(MattermostAlerter, self).get_aggregation_summary_text__maximum_width()
Expand Down Expand Up @@ -1250,6 +1285,30 @@ def alert(self, matches):
if self.mattermost_channel_override != '':
payload['channel'] = self.mattermost_channel_override

if self.mattermost_title_link != '':
payload['attachments'][0]['title_link'] = self.mattermost_title_link

if self.mattermost_footer != '':
payload['attachments'][0]['footer'] = self.mattermost_footer

if self.mattermost_footer_icon != '':
payload['attachments'][0]['footer_icon'] = self.mattermost_footer_icon

if self.mattermost_image_url != '':
payload['attachments'][0]['image_url'] = self.mattermost_image_url

if self.mattermost_thumb_url != '':
payload['attachments'][0]['thumb_url'] = self.mattermost_thumb_url

if self.mattermost_author_name != '':
payload['attachments'][0]['author_name'] = self.mattermost_author_name

if self.mattermost_author_link != '':
payload['attachments'][0]['author_link'] = self.mattermost_author_link

if self.mattermost_author_icon != '':
payload['attachments'][0]['author_icon'] = self.mattermost_author_icon

for url in self.mattermost_webhook_url:
try:
if self.mattermost_ignore_ssl_errors:
Expand Down
14 changes: 14 additions & 0 deletions elastalert/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ properties:
slack_kibana_discover_title: {type: string}
slack_footer: {type: string}
slack_footer_icon: {type: string}
slack_image_url: {type: string}
slack_thumb_url: {type: string}
slack_author_name: {type: string}
slack_author_link: {type: string}
slack_author_icon: {type: string}
slack_msg_pretext: {type: string}

### Mattermost
mattermost_webhook_url: *arrayOfString
Expand All @@ -295,6 +301,14 @@ properties:
mattermost_msg_color: {enum: [good, warning, danger]}
mattermost_msg_pretext: {type: string}
mattermost_msg_fields: *mattermostField
mattermost_title_link: {type: string}
mattermost_footer: {type: string}
mattermost_footer_icon: {type: string}
mattermost_image_url: {type: string}
mattermost_thumb_url: {type: string}
mattermost_author_name: {type: string}
mattermost_author_link: {type: string}
mattermost_author_icon: {type: string}

## Opsgenie
opsgenie_details:
Expand Down
Loading

0 comments on commit db15272

Please sign in to comment.