diff --git a/docs/source/ruletypes.rst b/docs/source/ruletypes.rst index 6ac59fb6..dd3d6a0f 100644 --- a/docs/source/ruletypes.rst +++ b/docs/source/ruletypes.rst @@ -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 "". diff --git a/elastalert/alerters/mattermost.py b/elastalert/alerters/mattermost.py index 1319d760..2da5b8c4 100644 --- a/elastalert/alerters/mattermost.py +++ b/elastalert/alerters/mattermost.py @@ -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', '') @@ -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 diff --git a/elastalert/schema.yaml b/elastalert/schema.yaml index bae822b0..9cee513e 100644 --- a/elastalert/schema.yaml +++ b/elastalert/schema.yaml @@ -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} diff --git a/tests/alerters/mattermost_test.py b/tests/alerters/mattermost_test.py index 18b39369..3a32000b 100644 --- a/tests/alerters/mattermost_test.py +++ b/tests/alerters/mattermost_test.py @@ -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' @@ -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' } ],