Module: check_mk
Branch: master
Commit: 7a26ecbbfe800de1842d2ab4674149fb1bf3c10c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7a26ecbbfe800d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 12 13:52:40 2018 +0200
6561 FIX Fixed invalid context button links to "Service globally" and
"Graphs globally"
When having a service detail page open, e.g. of a "CPU load" service a user may
want to
click on the context button "Service globally" to get a list of all "CPU
load" services
in the whole Check_MK setup.
Previous versions were only showing the "CPU load" services of the site the
origin service
was located on. The links on the "Service description" worked as intended.
We have now fixed the context button links by removing the "site" filter from
the URL.
Change-Id: Id9901ca0b210523c9f402ef862709e2923e55e13
---
.werks/6561 | 18 ++++++++++++++++++
cmk/gui/plugins/views/datasources.py | 14 --------------
cmk/gui/plugins/views/utils.py | 17 ++++-------------
cmk/gui/plugins/visuals/infos.py | 12 ++++++++++++
cmk/gui/visuals.py | 29 ++++++++++++++++++++++++++---
5 files changed, 60 insertions(+), 30 deletions(-)
diff --git a/.werks/6561 b/.werks/6561
new file mode 100644
index 0000000..e8b8781
--- /dev/null
+++ b/.werks/6561
@@ -0,0 +1,18 @@
+Title: Fixed invalid context button links to "Service globally" and
"Graphs globally"
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1536672914
+
+When having a service detail page open, e.g. of a "CPU load" service a user may
want to
+click on the context button "Service globally" to get a list of all "CPU
load" services
+in the whole Check_MK setup.
+
+Previous versions were only showing the "CPU load" services of the site the
origin service
+was located on. The links on the "Service description" worked as intended.
+
+We have now fixed the context button links by removing the "site" filter from
the URL.
diff --git a/cmk/gui/plugins/views/datasources.py b/cmk/gui/plugins/views/datasources.py
index 19f68aa..95063b9 100644
--- a/cmk/gui/plugins/views/datasources.py
+++ b/cmk/gui/plugins/views/datasources.py
@@ -97,13 +97,6 @@ multisite_datasources["hosts"] = {
# to handle the data provided by the single_spec value of the "hostgroup"
# info, which is in fact the name of the wanted hostgroup
"link_filters" : { "hostgroup": "opthostgroup" },
- # When these filters are set, the site hint will not be added to urls
- # which link to views using this datasource, because the resuling view
- # should show the objects spread accross the sites
- "multiple_site_filters" : [
- "hostgroup",
- "servicegroup",
- ],
}
multisite_datasources["hostsbygroup"] = {
@@ -130,13 +123,6 @@ multisite_datasources["services"] = {
"hostgroup" : "opthostgroup",
"servicegroup" : "optservicegroup",
},
- # When these filters are set, the site hint will not be added to urls
- # which link to views using this datasource, because the resuling view
- # should show the objects spread accross the sites
- "multiple_site_filters" : [
- "hostgroup",
- "servicegroup",
- ],
}
multisite_datasources["servicesbygroup"] = {
diff --git a/cmk/gui/plugins/views/utils.py b/cmk/gui/plugins/views/utils.py
index 531b593..3a69ad5 100644
--- a/cmk/gui/plugins/views/utils.py
+++ b/cmk/gui/plugins/views/utils.py
@@ -359,11 +359,12 @@ def link_to_view(content, row, view_name):
return content
+# TODO: There is duplicated logic with visuals.collect_context_links_of()
def url_to_view(row, view_name):
if display_options.disabled(display_options.I):
return None
- view = get_permitted_views(load_all_views()).get(view_name)
+ view = get_permitted_views(load_all_views())
if view:
# Get the context type of the view to link to, then get the parameters of this
# context type and try to construct the context from the data of the row
@@ -393,18 +394,8 @@ def url_to_view(row, view_name):
except KeyError:
pass
- # Some special handling for the site filter which is meant as optional hint
- # Always add the site filter var when some useful information is available
- add_site_hint = True
- for filter_key in datasource.get('multiple_site_filters', []):
- if filter_key in dict(url_vars):
- add_site_hint = False
-
- # Hack for servicedesc view which is meant to show all services with the given
- # description: Don't add the site filter for this view.
- if view_name == "servicedesc":
- add_site_hint = False
-
+ add_site_hint = visuals.may_add_site_hint(view_name,
info_keys=datasource["infos"],
+
single_info_keys=view["single_infos"], filter_names=dict(url_vars).keys())
if add_site_hint and row.get('site'):
url_vars.append(('site', row['site']))
diff --git a/cmk/gui/plugins/visuals/infos.py b/cmk/gui/plugins/visuals/infos.py
index e567013..91d041f 100644
--- a/cmk/gui/plugins/visuals/infos.py
+++ b/cmk/gui/plugins/visuals/infos.py
@@ -39,6 +39,12 @@ declare_info('host', {
title = _('Hostname'),
)),
],
+ # When these filters are set, the site hint will not be added to urls
+ # which link to views using this datasource, because the resuling view
+ # should show the objects spread accross the sites
+ "multiple_site_filters" : [
+ "hostgroup",
+ ],
})
declare_info('service', {
@@ -49,6 +55,12 @@ declare_info('service', {
title = _('Service Description'),
)),
],
+ # When these filters are set, the site hint will not be added to urls
+ # which link to views using this datasource, because the resuling view
+ # should show the objects spread accross the sites
+ "multiple_site_filters" : [
+ "servicegroup",
+ ],
})
declare_info('hostgroup', {
diff --git a/cmk/gui/visuals.py b/cmk/gui/visuals.py
index 17ef328..de060b2 100644
--- a/cmk/gui/visuals.py
+++ b/cmk/gui/visuals.py
@@ -1417,9 +1417,10 @@ def collect_context_links_of(visual_type_name, this_visual,
active_filter_vars,
break
vars_values.append((var, val))
- # When all infos of the target visual are showing single site data, add
- # the site hint when available
- if html.var('site') and all([ is_single_site_info(info_key)for info_key
in visual['single_infos']]):
+ add_site_hint = may_add_site_hint(name, info_keys=infos.keys(),
single_info_keys=visual["single_infos"],
+ filter_names=dict(vars_values).keys())
+
+ if add_site_hint and html.var('site'):
vars_values.append(('site', html.var('site')))
# Optional feature of visuals: Make them dynamically available as links or not.
@@ -1447,6 +1448,28 @@ def collect_context_links_of(visual_type_name, this_visual,
active_filter_vars,
return context_links
+
+def may_add_site_hint(visual_name, info_keys, single_info_keys, filter_names):
+ """Whether or not the site hint may be set when linking to a visual
with the given details"""
+ # When there is one non single site info used don't add the site hint
+ if [ info_key for info_key in single_info_keys if not is_single_site_info(info_key)
]:
+ return False
+
+ # Alternatively when the infos allow a site hint it is also needed to skip the site
hint based
+ # on the filters used by the target visual
+ for info_key in info_keys:
+ for filter_key in infos[info_key].get('multiple_site_filters', []):
+ if filter_key in filter_names:
+ return False
+
+ # Hack for servicedesc view which is meant to show all services with the given
+ # description: Don't add the site filter for this view.
+ if visual_name in [ "servicedesc", "servicedescpnp" ]:
+ return False
+
+ return True
+
+
def transform_old_visual(visual):
if 'context_type' in visual:
if visual['context_type'] in [ 'host', 'service',
'hostgroup', 'servicegroup' ]: