Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mattermost_title in mattermost alerts #246

Merged
merged 1 commit into from
Jun 7, 2021
Merged
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
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