diff --git a/check_monit.py b/check_monit.py index 96dc452..94bebfc 100755 --- a/check_monit.py +++ b/check_monit.py @@ -66,7 +66,7 @@ def commandline(args): def print_output(status, count_ok, count_all, items): s = icinga_status[status] - print(f"[{s}]: Monit Service Status {count_ok}/{count_all}") + print(f"[{s}]: Monit Service Status. {count_ok} of {count_all} are OK") if len(items): for item in items: @@ -85,7 +85,7 @@ def get_service_output(service_type, element): # Service Type Process if service_type == 3: status = element.find('status').text - return status + return 'status={0}'.format(status) # Service Type Host if service_type == 5: @@ -109,7 +109,8 @@ def get_service_output(service_type, element): # Service Type Program if service_type == 7: - return element.findall('program/output')[0].text + programoutput = element.findall('program/output')[0].text + return 'output={0}'.format(programoutput) return 'Service (type={0}) not implemented'.format(service_type) diff --git a/test_check_monit.py b/test_check_monit.py index 8034a65..01a86f1 100644 --- a/test_check_monit.py +++ b/test_check_monit.py @@ -36,13 +36,13 @@ def test_service_output(self): actual = get_service_output(-1, input_element) self.assertEqual(actual, 'Service (type=-1) not implemented') - input_element = ET.ElementTree(ET.fromstring("""unittest""")) + input_element = ET.ElementTree(ET.fromstring("""alright""")) actual = get_service_output(3, input_element) - self.assertEqual(actual, 'unittest') + self.assertEqual(actual, 'status=alright') input_element = ET.ElementTree(ET.fromstring("""foobar""")) actual = get_service_output(7, input_element) - self.assertEqual(actual, 'foobar') + self.assertEqual(actual, 'output=foobar') class UtilTesting(unittest.TestCase): @@ -50,7 +50,7 @@ class UtilTesting(unittest.TestCase): def test_return_plugin(self, mock_print): actual = print_output(1, 2, 3, [{'name': 'foo', 'output': 'bar', 'status': 1}]) - calls = [mock.call('[WARNING]: Monit Service Status 2/3'), + calls = [mock.call('[WARNING]: Monit Service Status. 2 of 3 are OK'), mock.call(' \\_ [CRITICAL]: foo'), mock.call(' bar')] @@ -116,7 +116,7 @@ def test_main_ok(self, mock_get, mock_print): self.assertEqual(actual, 0) - calls = [mock.call('[OK]: Monit Service Status 1/1'), + calls = [mock.call('[OK]: Monit Service Status. 1 of 1 are OK'), mock.call(' \\_ [OK]: scratch'), mock.call(' load=0.0,0.0,0.0;user=0.1%;system=0.1%;nice=0.0%;hardirq=0.0%;memory=10.6%')] @@ -135,7 +135,7 @@ def test_main_critical(self, mock_get, mock_print): self.assertEqual(actual, 2) - calls = [mock.call('[CRITICAL]: Monit Service Status 0/1'), + calls = [mock.call('[CRITICAL]: Monit Service Status. 0 of 1 are OK'), mock.call(' \\_ [CRITICAL]: scratch'), mock.call(' load=0.0,0.0,0.0;user=0.1%;system=0.1%;nice=0.0%;hardirq=0.0%;memory=10.6%')]