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

Fix Datadog Alerter #268

Merged
merged 2 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion elastalert/alerters/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def alert(self, matches):
response.raise_for_status()
except RequestException as e:
raise EAException('Error posting event to Datadog: %s' % e)
elastalert_logger.info('Alert sent to Datadog')
elastalert_logger.info('Alert sent to Datadog')

def get_info(self):
return {'type': 'datadog'}
10 changes: 7 additions & 3 deletions tests/alerters/datadog_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging

from unittest import mock
import pytest
Expand All @@ -9,7 +10,8 @@
from elastalert.util import EAException


def test_datadog_alerter():
def test_datadog_alerter(caplog):
caplog.set_level(logging.INFO)
rule = {
'name': 'Test Datadog Event Alerter',
'type': 'any',
Expand Down Expand Up @@ -43,6 +45,7 @@ def test_datadog_alerter():
)
actual_data = json.loads(mock_post_request.call_args_list[0][1]['data'])
assert expected_data == actual_data
assert ('elastalert', logging.INFO, 'Alert sent to Datadog') == caplog.record_tuples[0]


def test_datadog_alerterea_exception():
Expand All @@ -65,8 +68,9 @@ def test_datadog_alerterea_exception():
mock_run = mock.MagicMock(side_effect=RequestException)
with mock.patch('requests.post', mock_run), pytest.raises(RequestException):
alert.alert([match])
except EAException:
assert True
assert False
except EAException as ea:
assert 'Error posting event to Datadog:' in str(ea)


def test_datadog_getinfo():
Expand Down