diff --git a/minitor/main.py b/minitor/main.py index cbd0268..f71218b 100644 --- a/minitor/main.py +++ b/minitor/main.py @@ -209,7 +209,11 @@ class Alert(object): def alert(self, monitor): """Calls the alert command for the provided monitor""" output, ex = call_output( - self._formated_command(monitor_name=monitor.name), + self._formated_command( + alert_count=monitor.alert_count, + monitor_name=monitor.name, + failure_count=monitor.total_failure_count, + ), shell=isinstance(self.command, str), ) self.logger.error(maybe_decode(output)) diff --git a/tests/alert_test.py b/tests/alert_test.py index 22e43eb..76566bd 100644 --- a/tests/alert_test.py +++ b/tests/alert_test.py @@ -19,10 +19,22 @@ class TestAlert(object): def echo_alert(self): return Alert( 'log', - {'command': ['echo', '{monitor_name} has failed!']} + { + 'command': [ + 'echo', ( + '{monitor_name} has failed {failure_count} time(s)!\n' + 'We have alerted {alert_count} time(s)' + ) + ] + } ) def test_simple_alert(self, monitor, echo_alert): + monitor.total_failure_count = 1 + monitor.alert_count = 1 with patch.object(echo_alert.logger, 'error') as mock_error: echo_alert.alert(monitor) - mock_error.assert_called_once_with('Dummy Monitor has failed!') + mock_error.assert_called_once_with( + 'Dummy Monitor has failed 1 time(s)!\n' + 'We have alerted 1 time(s)' + )