Add formatting for failure_count and alert_count

Fixes #3
This commit is contained in:
IamTheFij 2018-04-10 21:58:01 -07:00
parent eadaf17d91
commit 0b0636b701
2 changed files with 19 additions and 3 deletions

View File

@ -209,7 +209,11 @@ class Alert(object):
def alert(self, monitor): def alert(self, monitor):
"""Calls the alert command for the provided monitor""" """Calls the alert command for the provided monitor"""
output, ex = call_output( 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), shell=isinstance(self.command, str),
) )
self.logger.error(maybe_decode(output)) self.logger.error(maybe_decode(output))

View File

@ -19,10 +19,22 @@ class TestAlert(object):
def echo_alert(self): def echo_alert(self):
return Alert( return Alert(
'log', '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): 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: with patch.object(echo_alert.logger, 'error') as mock_error:
echo_alert.alert(monitor) 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)'
)