diff --git a/elastalert/alerters/datadog.py b/elastalert/alerters/datadog.py index 6ee8d9b3..2fd71be1 100644 --- a/elastalert/alerters/datadog.py +++ b/elastalert/alerters/datadog.py @@ -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'} diff --git a/tests/alerters/datadog_test.py b/tests/alerters/datadog_test.py index 2d61a669..e7032585 100644 --- a/tests/alerters/datadog_test.py +++ b/tests/alerters/datadog_test.py @@ -1,4 +1,5 @@ import json +import logging from unittest import mock import pytest @@ -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', @@ -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(): @@ -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():