Module: check_mk
Branch: master
Commit: eed5a817bc1e59d20eb04149b3b0e17408ca0d4e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eed5a817bc1e59…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jun 26 18:01:00 2012 +0200
count_ok: allow percentages, e.g. "count_ok!70%!50%"
---
ChangeLog | 1 +
web/htdocs/bi.py | 15 +++++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b182927..5f2eb05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,7 @@
* New logical datatable for aggregations that have the same name
as a host. Converted view "BI Boxes" to this new table. This allows
for Host-Aggregations containing data of other hosts as well.
+ * count_ok: allow percentages, e.g. "count_ok!70%!50%"
1.2.0p1:
Core:
diff --git a/web/htdocs/bi.py b/web/htdocs/bi.py
index 000d8ca..c758b95 100644
--- a/web/htdocs/bi.py
+++ b/web/htdocs/bi.py
@@ -888,12 +888,23 @@ def aggr_best(nodes, n = 1, worst_state = CRIT):
config.aggregation_functions["worst"] = aggr_worst
config.aggregation_functions["best"] = aggr_best
+def aggr_countok_convert(num, count):
+ if num.endswith('%'):
+ return int(num[:-1]) / 100.0 * count
+ else:
+ return int(num)
+
def aggr_countok(nodes, needed_for_ok=2, needed_for_warn=1):
states = [ i[0]["state"] for i in nodes ]
num_ok = len([s for s in states if s == 0 ])
- if num_ok >= int(needed_for_ok):
+
+ # counts can be specified as integer (e.g. '2') or
+ # as percentages (e.g. '70%').
+
+
+ if num_ok >= aggr_countok_convert(needed_for_ok, len(states)):
return { "state" : 0, "output" : "" }
- elif num_ok >= int(needed_for_warn):
+ elif num_ok >= aggr_countok_convert(needed_for_warn, len(states)):
return { "state" : 1, "output" : "" }
else:
return { "state" : 2, "output" : "" }