Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions check_monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions test_check_monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ 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("""<doc><status>unittest</status></doc>"""))
input_element = ET.ElementTree(ET.fromstring("""<doc><status>alright</status></doc>"""))
actual = get_service_output(3, input_element)
self.assertEqual(actual, 'unittest')
self.assertEqual(actual, 'status=alright')

input_element = ET.ElementTree(ET.fromstring("""<doc><program><output>foobar</output></program></doc>"""))
actual = get_service_output(7, input_element)
self.assertEqual(actual, 'foobar')
self.assertEqual(actual, 'output=foobar')

class UtilTesting(unittest.TestCase):

@mock.patch('builtins.print')
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')]

Expand Down Expand Up @@ -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%')]

Expand All @@ -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%')]

Expand Down