Module: check_mk
Branch: master
Commit: cea80ffb8d19e46c811ec843330e59e1880508c0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cea80ffb8d19e4…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Oct 8 16:05:18 2014 +0200
visuals: new helper function for getting filter headers
---
web/htdocs/visuals.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 689875b..ce9f581 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -912,6 +912,32 @@ def add_context_to_uri_vars(visual, only_infos=None,
only_count=False):
html.set_var(uri_varname, value)
+# Compute Livestatus-Filters based on a given context. Returns
+# the only_sites list and a string with the filter headers
+def get_filter_headers(datasource, context):
+ # Prepare Filter headers for Livestatus
+ filter_headers = ""
+ only_sites = None
+ html.stash_vars()
+ for filter_name, filter_vars in context.items():
+ # first set the HTML variables. Sorry - the filters need this
+ if type(filter_vars) == dict: # this is a multi-context filter
+ for uri_varname, value in filter_vars.items():
+ html.set_var(uri_varname, value)
+ else:
+ html.set_var(filter_name, filter_vars)
+
+ # Now compute filter headers for all infos of the used datasource
+ our_infos = datasource["infos"]
+ for filter_name, filter_object in multisite_filters.items():
+ if filter_object.info in our_infos:
+ header = filter_object.filter(datasource["table"])
+ if header.startswith("Sites:"):
+ only_sites = header.strip().split(" ")[1:]
+ else:
+ filter_headers += header
+ html.unstash_vars()
+ return filter_headers, only_sites
#.