Skip to content

Commit

Permalink
Merge pull request #246 from nsano-rururu/mattermost_title
Browse files Browse the repository at this point in the history
add mattermost_title in mattermost alerts
  • Loading branch information
jertel authored Jun 7, 2021
2 parents 05368b4 + 128b6b9 commit 748889c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/source/ruletypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,9 @@ Example mattermost_msg_fields::
value: static field
short: false

``mattermost_title_link``: You can add a link in your Mattermost notification by setting this to a valid URL. Defaults to "".
``mattermost_title``: Sets a title for the message, this shows up as a blue text at the start of the message. Defaults to "".

``mattermost_title_link``: You can add a link in your Mattermost 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 "".

Expand Down
4 changes: 4 additions & 0 deletions elastalert/alerters/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, rule):
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 = self.rule.get('mattermost_title', '')
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', '')
Expand Down Expand Up @@ -107,6 +108,9 @@ def alert(self, matches):
if self.mattermost_channel_override != '':
payload['channel'] = self.mattermost_channel_override

if self.mattermost_title != '':
payload['attachments'][0]['title'] = self.mattermost_title

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

Expand Down
1 change: 1 addition & 0 deletions elastalert/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ properties:
mattermost_msg_pretext: {type: string}
mattermost_msg_color: {enum: [good, warning, danger]}
mattermost_msg_fields: *arrayOfMattermostField
mattermost_title: {type: string}
mattermost_title_link: {type: string}
mattermost_footer: {type: string}
mattermost_footer_icon: {type: string}
Expand Down
3 changes: 2 additions & 1 deletion tests/alerters/mattermost_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def test_mattermost_title_link():
'mattermost_webhook_url': 'http://xxxxx',
'mattermost_msg_pretext': 'aaaaa',
'mattermost_msg_color': 'danger',
'mattermost_title': 'mattermost.title',
'mattermost_title_link': 'http://title.url',
'alert': [],
'alert_subject': 'Test Mattermost'
Expand All @@ -384,10 +385,10 @@ def test_mattermost_title_link():
{
'fallback': 'Test Mattermost: aaaaa',
'color': 'danger',
'title': 'Test Mattermost',
'pretext': 'aaaaa',
'fields': [],
'text': 'Test Mattermost Rule\n\n',
'title': 'mattermost.title',
'title_link': 'http://title.url'
}
],
Expand Down

0 comments on commit 748889c

Please sign in to comment.