Module: check_mk
Branch: master
Commit: 7d3e0726d1fb43aa916dd1a15d24d897a4148519
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7d3e0726d1fb43…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 18 15:19:28 2013 +0100
FIX WATO BI editor now supports percentages for count_ok
The WATO module for BI aggregates now can correctly show and edit aggregation
functions of the type <tt>count_ok</tt> that are using percentages instead
of explicit numbers, e.g. <tt>count_ok!60%!30%</tt>.
---
.werks/400 | 12 ++++++++++++
ChangeLog | 1 +
web/htdocs/bi.py | 2 --
web/htdocs/lib.py | 6 ++++++
web/htdocs/wato.py | 2 +-
web/plugins/wato/bi.py | 34 ++++++++++++++++++++++++++--------
6 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/.werks/400 b/.werks/400
new file mode 100644
index 0000000..76da29c
--- /dev/null
+++ b/.werks/400
@@ -0,0 +1,12 @@
+Title: WATO BI editor now supports percentages for count_ok
+Level: 2
+Component: wato
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1387376299
+Targetversion: future
+
+The WATO module for BI aggregates now can correctly show and edit aggregation
+functions of the type <tt>count_ok</tt> that are using percentages instead
+of explicit numbers, e.g. <tt>count_ok!60%!30%</tt>.
diff --git a/ChangeLog b/ChangeLog
index f56a379..567a1aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -106,6 +106,7 @@
* 0346 FIX: Fix folder visibility in WATO for unpriviledged users...
* 0385 FIX: Better error handling for invalid service regex in rule conditions...
* 0389 FIX: Showing LDAP settings on site specific global settings page now...
+ * 0400 FIX: WATO BI editor now supports percentages for count_ok...
Notifications:
* 0362 sms: now searching PATH for sendsms and smssend commands...
diff --git a/web/htdocs/bi.py b/web/htdocs/bi.py
index 85a841c..a463750 100644
--- a/web/htdocs/bi.py
+++ b/web/htdocs/bi.py
@@ -1245,8 +1245,6 @@ def aggr_countok(nodes, needed_for_ok=2, needed_for_warn=1):
# 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 >= aggr_countok_convert(needed_for_warn, len(states)):
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 7b8d205..7b53b2a 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -289,6 +289,12 @@ def saveint(x):
except:
return 0
+def tryint(x):
+ try:
+ return int(x)
+ except:
+ return x
+
def set_is_disjoint(a, b):
for elem in a:
if elem in b:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b4fc2e2..bb10448 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -13347,7 +13347,7 @@ def convert_rule_from_bi(rule, ruleid):
crule.update(rule)
crule["nodes"] = map(convert_node_from_bi, rule["nodes"])
parts = rule["aggregation"].split("!")
- crule["aggregation"] = (parts[0], tuple(map(saveint, parts[1:])))
+ crule["aggregation"] = (parts[0], tuple(map(tryint, parts[1:])))
crule["id"] = ruleid
return crule
diff --git a/web/plugins/wato/bi.py b/web/plugins/wato/bi.py
index c8662a1..1b45ff5 100644
--- a/web/plugins/wato/bi.py
+++ b/web/plugins/wato/bi.py
@@ -68,18 +68,36 @@ bi_aggregation_functions["best"] = {
]),
}
+def vs_count_ok_count(title, defval, defvalperc):
+ return Alternative(
+ title = title,
+ style = "dropdown",
+ match = lambda x: str(x).endswith("%") and 1 or 0,
+ elements = [
+ Integer(
+ title = _("Explicit number"),
+ label=_("Number of OK-nodes"),
+ min_value = 0,
+ default_value = defval
+ ),
+ Transform(
+ Percentage(
+ label=_("Percent of OK-nodes"),
+ display_format = "%.0f",
+ default_value = defvalperc),
+ title = _("Percentage"),
+ forth = lambda x: float(x[:-1]),
+ back = lambda x: "%d%%" % x,
+ ),
+ ]
+ )
+
bi_aggregation_functions["count_ok"] = {
"title" : _("Count the number of nodes in state OK"),
"valuespec" : Tuple(
elements = [
- Integer(
- label = _("Required number of OK-nodes for a total state of
OK:"),
- default_value = 2,
- min_value = 0),
- Integer(
- label = _("Required number of OK-nodes for a total state of
WARN:"),
- default_value = 1,
- min_value = 0),
+ vs_count_ok_count(_("Required number of OK-nodes for a total state of
OK:"), 2, 50),
+ vs_count_ok_count(_("Required number of OK-nodes for a total state of
WARN:"), 1, 25),
]),
}