Module: check_mk
Branch: master
Commit: a461ae2f4841877fdbeaf423cfe3f4c01547b7e6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a461ae2f484187…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Mar 31 18:10:18 2011 +0200
BI: error handling of unused variables
---
ChangeLog | 3 ---
web/htdocs/bi.py | 13 +++++++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6b2c7fe..b23ebd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,9 +17,6 @@
BI:
* Added new component BI to Multisite.
- * New third argument for worst and best: the worst possible
- state (see docu)
- * Make PENDING be slightly worst than OK
WATO:
* Allow moving hosts from one to another config file
diff --git a/web/htdocs/bi.py b/web/htdocs/bi.py
index c032fc3..b7a036a 100644
--- a/web/htdocs/bi.py
+++ b/web/htdocs/bi.py
@@ -272,10 +272,13 @@ def compile_aggregation(rule, args, lvl = 0):
# value for all SINGLE arguments
groups = {}
+ used_parameters = set([])
single_names = [ varname for (varname, (expansion, value)) in arginfo.items() if
expansion == SINGLE ]
for instargs, node in elements:
# Honor that some variables might be unused and thus not contained in instargs
key = tuple([ (varname, instargs[varname]) for varname in single_names if varname
in instargs ])
+ for var in instargs:
+ used_parameters.add(var)
nodes = groups.get(key, [])
nodes.append(node)
groups[key] = nodes
@@ -375,6 +378,7 @@ def compile_aggregation(rule, args, lvl = 0):
while bilateral_mergegroups(groups):
pass
+
# Check for unmergeable entries, fill up missing values
# from parameters (assuming they are not regexes)
for ikey, inodes in groups.items():
@@ -386,6 +390,15 @@ def compile_aggregation(rule, args, lvl = 0):
newkey = tuple(d.items())
groups[newkey] = inodes
del groups[ikey]
+
+ # track unused parameters - if we are not empty anyway
+ if len(groups) > 0:
+ for var in single_names:
+ if var not in used_parameters:
+ raise MKConfigError("<h1>Invalid rule</h1>"
+ "The rule '<tt>%s</tt>' never uses the
variable '<tt>%s</tt>'.<br>"
+ "This is not allowed. All singleton parameters must be used in
the rule." \
+ % (description, var))
# now sort groups after instantiations
def cmp_group(a, b):