add helper method to CheckResult to get a flat list of perf values
Message-ID: <5a3d2e78.LzSROzI62AwWmy8z%kb(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Module: check_mk
Branch: master
Commit: fe718466f95a3c822a77f712b4492dd30efb7965
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe718466f95a3c…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Fri Dec 22 17:03:56 2017 +0100
checktestlib: Make PerfValue objects comparable to each other, add helper method to
CheckResult to get a flat list of perf values
Change-Id: If4dbd8066d585090ea3eff7bfe91ec58487f6980
---
tests/checks/checktestlib.py | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tests/checks/checktestlib.py b/tests/checks/checktestlib.py
index 492f10b..ab1aa68 100644
--- a/tests/checks/checktestlib.py
+++ b/tests/checks/checktestlib.py
@@ -27,6 +27,19 @@ class PerfValue(object):
assert type(maximum) in [int, float, types.NoneType]
self.maximum = maximum
+ def __eq__(self, other_value):
+ return all([
+ self.key == other_value.key,
+ self.value == other_value.value,
+ self.warn == other_value.warn,
+ self.crit == other_value.crit,
+ self.minimum == other_value.minimum,
+ self.maximum == other_value.maximum,
+ ])
+
+ def __ne__(self, other_value):
+ return not self.__eq__(other_value)
+
class BasicCheckResult(object):
"""
@@ -76,3 +89,10 @@ class CheckResult(object):
self.subresults.append(BasicCheckResult(*subresult))
else:
self.subresults = [ BasicCheckResult(*result) ]
+
+ # TODO: @property this
+ def perfdata(self):
+ perfdata = []
+ for subresult in self.subresults:
+ perfdata += subresult.perfdata if subresult.perfdata else []
+ return perfdata