[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:08:43 UTC 2012
The following commit has been merged in the debian/master branch:
commit 247baa7e24f80ce37518d6f3653e0367cda8386b
Author: Naparuba <naparuba at gmail.com>
Date: Wed Dec 14 13:49:45 2011 +0100
Fix : (reported by : sprudhomme) longoutput parsing and perfdata did not follow nagios way.
diff --git a/shinken/action.py b/shinken/action.py
index 22f654d..90c776d 100644
--- a/shinken/action.py
+++ b/shinken/action.py
@@ -78,10 +78,24 @@ class __Action(object):
# After | is perfdata, and strip it
if len(elts_line1) > 1:
self.perf_data = elts_line1[1].strip()
- # The others lines are long_output
- # but others are are not stripped
- if len(elts) > 1:
- self.long_output = '\n'.join(elts[1:])
+ # Now manage others lines. Before the | it's long_output
+ # And after it's all perf_data, \n join
+ long_output = []
+ in_perfdata = False
+ for line in elts[1:]:
+ # if already in perfdata, direct append
+ if in_perfdata:
+ self.perf_data += ' ' + line.strip()
+ else: # not already in? search for the | part :)
+ elts = line.split('|', 1)
+ # The first part will always be long_output
+ long_output.append(elts[0].strip())
+ if len(elts) > 1:
+ in_perfdata = True
+ self.perf_data += ' ' + elts[1].strip()
+ # long_output is all non output and perfline, join with \n
+ self.long_output = '\n'.join(long_output)
+
def check_finished(self, max_plugins_output_length):
diff --git a/shinken/objects/item.py b/shinken/objects/item.py
index a9fb8bb..c891b90 100644
--- a/shinken/objects/item.py
+++ b/shinken/objects/item.py
@@ -413,7 +413,7 @@ Like temporary attributes such as "imported_from", etc.. """
# Look if we got an ack that is too old with an expire date and should
# be delete
def check_for_expire_acknowledge(self):
- if self.acknowledgement and self.acknowledgement.end_time < time.time():
+ if self.acknowledgement and self.acknowledgement.end_time != 0 and self.acknowledgement.end_time < time.time():
self.unacknowledge_problem()
diff --git a/test/shinken_test.py b/test/shinken_test.py
index 80953e0..215126d 100755
--- a/test/shinken_test.py
+++ b/test/shinken_test.py
@@ -179,14 +179,7 @@ class ShinkenTest(unittest.TestCase):
# is a valid value in the future
ref.next_chk = now - 0.5
- elts_line1 = output.split('|')
- #First line before | is output
- check.output = elts_line1[0]
- #After | is perfdata
- if len(elts_line1) > 1:
- check.perf_data = elts_line1[1]
- else:
- check.perf_data = ''
+ check.get_outputs(output, 9000)
check.exit_status = exit_status
check.execution_time = 0.001
check.status = 'waitconsume'
diff --git a/test/test_commands_perfdata.py b/test/test_commands_perfdata.py
index 0b7aa30..bbeb1bf 100755
--- a/test/test_commands_perfdata.py
+++ b/test/test_commands_perfdata.py
@@ -96,5 +96,49 @@ class TestConfig(ShinkenTest):
self.assert_(self.count_actions() == 0)
+ def test_multiline_perfdata(self):
+ self.print_header()
+
+ #We want an eventhandelr (the perfdata command) to be put in the actions dict
+ #after we got a service check
+ now = time.time()
+ host = self.sched.hosts.find_by_name("test_host_0")
+ host.checks_in_progress = []
+ host.act_depend_of = [] # ignore the router
+ svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
+ svc.checks_in_progress = []
+ svc.act_depend_of = [] # no hostchecks on critical checkresults
+ #--------------------------------------------------------------
+ # initialize host/service state
+ #--------------------------------------------------------------
+ print "Service perfdata command", svc.__class__.perfdata_command, type(svc.__class__.perfdata_command)
+ #We do not want to be just a string but a real command
+ self.assert_(not isinstance(svc.__class__.perfdata_command, str))
+ print svc.__class__.perfdata_command.__class__.my_type
+ self.assert_(svc.__class__.perfdata_command.__class__.my_type == 'CommandCall')
+ output = """DISK OK - free space: / 3326 MB (56%); | /=2643MB;5948;5958;0;5968
+/ 15272 MB (77%);
+/boot 68 MB (69%);
+/home 69357 MB (27%);
+/var/log 819 MB (84%); | /boot=68MB;88;93;0;98
+/home=69357MB;253404;253409;0;253414
+/var/log=818MB;970;975;0;980
+ """
+ self.scheduler_loop(1, [[svc, 0, output]])
+ print "Actions", self.sched.actions
+ print 'Output',svc.output
+ print 'long', svc.long_output
+ print 'perf', svc.perf_data
+
+ self.assert_(svc.output.strip() == 'DISK OK - free space: / 3326 MB (56%);')
+ self.assert_(svc.perf_data.strip() == u'/=2643MB;5948;5958;0;5968 /boot=68MB;88;93;0;98 /home=69357MB;253404;253409;0;253414 /var/log=818MB;970;975;0;980')
+ print svc.long_output.split('\n')
+ self.assert_(svc.long_output == u"""/ 15272 MB (77%);
+/boot 68 MB (69%);
+/home 69357 MB (27%);
+/var/log 819 MB (84%);""")
+
+
+
if __name__ == '__main__':
unittest.main()
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list