Skip to content
Merged
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: 3 additions & 4 deletions check_monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ def print_output(status, count_ok, count_all, items):

if len(items):
for item in items:
s = "OK" if item['status'] == 0 else "CRITICAL"
print(' \\_ [{0}]: {1}'.format(s, item['name']))
print(' ' + item['output'])

s = "OK" if item.get('status') == 0 else "CRITICAL"
print(' \\_ [{0}]: {1}'.format(s, item.get('name', 'No Name')))
print(' {}' .format(item.get('output', 'None')))

def get_service_output(service_type, element):
# Service Type Filesystem
Expand Down
18 changes: 18 additions & 0 deletions test_check_monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ def test_return_plugin(self, mock_print):

mock_print.assert_has_calls(calls)

@mock.patch('builtins.print')
def test_return_plugin_with_no_output(self, mock_print):
actual = print_output(1, 2, 3, [{'name': 'foo', 'output': None, 'status': 1}])

calls = [mock.call('[WARNING]: Monit Service Status 2/3'),
mock.call(' \\_ [CRITICAL]: foo'),
mock.call(' None')]

mock_print.assert_has_calls(calls)

actual = print_output(1, 2, 3, [{'name': 'foo', 'status': 1}])

calls = [mock.call('[WARNING]: Monit Service Status 2/3'),
mock.call(' \\_ [CRITICAL]: foo'),
mock.call(' None')]

mock_print.assert_has_calls(calls)

class MainTesting(unittest.TestCase):

@mock.patch('builtins.print')
Expand Down