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

Changed required items of msteams alerter #228

Merged
merged 2 commits into from
Jun 4, 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: 2 additions & 2 deletions docs/source/ruletypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2233,10 +2233,10 @@ The alerter requires the following options:
``ms_teams_webhook_url``: The webhook URL that includes your auth data and the ID of the channel you want to post to. Go to the Connectors
menu in your channel and configure an Incoming Webhook, then copy the resulting URL. You can use a list of URLs to send to multiple channels.

``ms_teams_alert_summary``: Summary should be configured according to `MS documentation <https://docs.microsoft.com/en-us/outlook/actionable-messages/card-reference>`_, although it seems not displayed by Teams currently.

Optional:

``ms_teams_alert_summary``: Summary should be configured according to `MS documentation <https://docs.microsoft.com/en-us/outlook/actionable-messages/card-reference>`_, although it seems not displayed by Teams currently, defaults to ``ElastAlert Message``.

``ms_teams_theme_color``: By default the alert will be posted without any color line. To add color, set this attribute to a HTML color value e.g. ``#ff0000`` for red.

``ms_teams_proxy``: By default ElastAlert will not use a network proxy to send notifications to MS Teams. Set this option using ``hostname:port`` if you need to use a proxy.
Expand Down
2 changes: 1 addition & 1 deletion elastalert/alerters/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class MsTeamsAlerter(Alerter):
""" Creates a Microsoft Teams Conversation Message for each alert """
required_options = frozenset(['ms_teams_webhook_url', 'ms_teams_alert_summary'])
required_options = frozenset(['ms_teams_webhook_url'])

def __init__(self, rule):
super(MsTeamsAlerter, self).__init__(rule)
Expand Down
50 changes: 50 additions & 0 deletions tests/alerters/teams_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,53 @@ def test_ms_teams_ea_exception():
alert.alert([match])
except EAException:
assert True


def test_ms_teams_getinfo():
rule = {
'name': 'Test Rule',
'type': 'any',
'ms_teams_webhook_url': 'http://test.webhook.url',
'alert_subject': 'Cool subject',
'alert': []
}
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = MsTeamsAlerter(rule)

expected_data = {
'type': 'ms_teams',
'ms_teams_webhook_url': ['http://test.webhook.url']
}
actual_data = alert.get_info()
assert expected_data == actual_data


@pytest.mark.parametrize('ms_teams_webhook_url, expected_data', [
('', True),
('http://test.webhook.url',
{
'type': 'ms_teams',
'ms_teams_webhook_url': ['http://test.webhook.url']
})
])
def test_ms_teams_key_error(ms_teams_webhook_url, expected_data):
try:
rule = {
'name': 'Test Rule',
'type': 'any',
'alert_subject': 'Cool subject',
'alert': []
}

if ms_teams_webhook_url != '':
rule['ms_teams_webhook_url'] = ms_teams_webhook_url

rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = MsTeamsAlerter(rule)

actual_data = alert.get_info()
assert expected_data == actual_data
except KeyError:
assert expected_data