Skip to content

Commit 11a6e3d

Browse files
authored
Merge pull request #15 from chri2/service_type=7
service_type 7 && monitor all states !0
2 parents 951e7c8 + cc0a432 commit 11a6e3d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

check_monit.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ def get_service_output(service_type, element):
109109

110110
# Service Type Program
111111
if service_type == 7:
112-
return element.findall('program/output')[0].text
112+
return_value = None
113+
for output_item in element.findall('program/output'):
114+
# type( output_item ) is <class 'xml.etree.ElementTree.Element'>
115+
return_value = output_item.text if return_value is None else f"{return_value}; {output_item.text}"
116+
if return_value is None:
117+
return_value = 'no command output available'
118+
119+
return return_value
113120

114121
return 'Service (type={0}) not implemented'.format(service_type)
115122

@@ -121,8 +128,8 @@ def get_service_states(services):
121128
for service in services:
122129
# Get the monitor state for the service (0: Not, 1: Yes, 2: Init, 4: Waiting)
123130
monitor = int(service.find('monitor').text)
124-
# if the monitor is yes or initialize, check its status
125-
if monitor in (1, 2):
131+
# ignore 'Monitor_not' (0)
132+
if monitor != 0:
126133
status = int(service.find('status').text)
127134
if status == 0:
128135
count_ok += 1

test_check_monit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ def test_service_output(self):
4040
actual = get_service_output(3, input_element)
4141
self.assertEqual(actual, 'unittest')
4242

43+
input_element = ET.ElementTree(ET.fromstring("""<doc><program><output></output></program></doc>"""))
44+
actual = get_service_output(7, input_element)
45+
self.assertEqual(actual, 'no command output available')
46+
4347
input_element = ET.ElementTree(ET.fromstring("""<doc><program><output>foobar</output></program></doc>"""))
4448
actual = get_service_output(7, input_element)
4549
self.assertEqual(actual, 'foobar')
4650

51+
input_element = ET.ElementTree(ET.fromstring("""<doc><program><output>foot</output><output>bath</output></program></doc>"""))
52+
actual = get_service_output(7, input_element)
53+
self.assertEqual(actual, 'foot; bath')
54+
4755
class UtilTesting(unittest.TestCase):
4856

4957
@mock.patch('builtins.print')

0 commit comments

Comments
 (0)