Module: check_mk
Branch: master
Commit: 25acf6382d0ce04a695ba2990db9e866612ae74c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=25acf6382d0ce0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 22 12:56:53 2015 +0200
Normaly it is not allowed to have different hosts with equal name in Check_MK.
But it is possible to configure this, e.g. by creating hosts with an equal
name on different sites (we do not recommend to do this).
This change tries to fix handling of this situation in the GUIs views, where
a user clicks on a host/service which is present on multiple sites but the user intends
to get the host/service from a specific view. In the past this situation
was not handled clearly which lead to a view showing data of the two equal
named hosts where the user expected only data of one.
Conflicts:
ChangeLog
web/htdocs/views.py
web/htdocs/visuals.py
web/plugins/visuals/infos.py
---
.werks/2257 | 18 ++++++++++++++++++
ChangeLog | 1 +
web/htdocs/views.py | 38 ++++++++++++++++++++++++++------------
web/htdocs/visuals.py | 8 ++++++++
web/plugins/views/datasources.py | 14 ++++++++++++++
web/plugins/visuals/filters.py | 12 ------------
web/plugins/visuals/infos.py | 2 ++
7 files changed, 69 insertions(+), 24 deletions(-)
diff --git a/.werks/2257 b/.werks/2257
new file mode 100644
index 0000000..9b13859
--- /dev/null
+++ b/.werks/2257
@@ -0,0 +1,18 @@
+Title: Improved handling of duplicate hostnames across different sites
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1432288983
+
+Normaly it is not allowed to have different hosts with equal name in Check_MK.
+But it is possible to configure this, e.g. by creating hosts with an equal
+name on different sites (we do not recommend to do this).
+
+This change tries to fix handling of this situation in the GUIs views, where
+a user clicks on a host/service which is present on multiple sites but the user intends
+to get the host/service from a specific view. In the past this situation
+was not handled clearly which lead to a view showing data of the two equal
+named hosts where the user expected only data of one.
diff --git a/ChangeLog b/ChangeLog
index a62c7e2..b46855b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -455,6 +455,7 @@
* 2074 FIX: pnptemplate netapp_api_volume: fixed title
* 2251 FIX: Adding views to dashboards / reports is now respecing all set filters...
* 2253 FIX: Availability context button is now visible again for host- and
servicegroups
+ * 2257 FIX: Improved handling of duplicate hostnames across different sites...
WATO:
* 1760 Added search form to manual checks page
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index f26fef7..6feea46 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -976,17 +976,20 @@ def show_view(view, show_heading = False, show_buttons = True,
# we convert this to the visuals principle the we need to optimize
# this.
filterheaders = ""
- only_sites = None
all_active_filters = [ f for f in use_filters if f.available() ]
for filt in all_active_filters:
header = filt.filter(tablename)
- if header.startswith("Sites:"):
- only_sites = header.strip().split(" ")[1:]
- else:
- filterheaders += header
+ filterheaders += header
if filt.need_inventory():
need_inventory_data = True
+ # Apply the site hint / filter
+ if config.is_multisite():
+ if html.var("site"):
+ only_sites = [html.var("site")]
+ else:
+ only_sites = None
+
# Prepare limit:
# We had a problem with stats queries on the logtable where
# the limit was not applied on the resulting rows but on the
@@ -2099,7 +2102,7 @@ def url_to_view(row, view_name):
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
- vars = []
+ url_vars = []
datasource = multisite_datasources[view['datasource']]
for info_key in datasource['infos']:
if info_key in view['single_infos']:
@@ -2110,21 +2113,32 @@ def url_to_view(row, view_name):
filter_object = visuals.get_filter(filter_name)
# Get the list of URI vars to be set for that filter
new_vars = filter_object.variable_settings(row)
- vars += new_vars
+ url_vars += new_vars
# See get_link_filter_names() comment for details
for src_key, dst_key in visuals.get_link_filter_names(view,
datasource['infos'],
datasource.get('link_filters',
{})):
- vars += visuals.get_filter(src_key).variable_settings(row)
- vars += visuals.get_filter(dst_key).variable_settings(row)
+ url_vars += visuals.get_filter(src_key).variable_settings(row)
+ url_vars += visuals.get_filter(dst_key).variable_settings(row)
+
+ # 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
+
+ if add_site_hint:
+ url_vars.append(('site', row['site']))
do = html.var("display_options")
if do:
- vars.append(("display_options", do))
+ url_vars.append(("display_options", do))
filename = html.mobile and "mobile_view.py" or "view.py"
- return filename + "?" + html.urlencode_vars([("view_name",
view_name)] + vars)
- return None
+ uri = filename + "?" + html.urlencode_vars([("view_name",
view_name)] + url_vars)
+ content = "<a href=\"%s\">%s</a>" % (uri,
content)
+ return content
def link_to_view(content, row, view_name):
if 'I' not in html.display_options:
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 3b4cda3..39026a8 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1175,6 +1175,9 @@ def unpack_context_after_editing(packed_context):
def declare_info(infoname, info):
infos[infoname] = info
+def is_single_site_info(info_key):
+ return infos[info_key].get('single_site', True)
+
def single_infos_spec(single_infos):
return ('single_infos', FixedValue(single_infos,
title = _('Show information of single'),
@@ -1318,6 +1321,11 @@ 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']]):
+ vars_values.append(('site', html.var('site')))
+
if not skip:
# add context link to this visual. For reports we put in
# the *complete* context, even the non-single one.
diff --git a/web/plugins/views/datasources.py b/web/plugins/views/datasources.py
index 7aa06c1..99b8a22 100644
--- a/web/plugins/views/datasources.py
+++ b/web/plugins/views/datasources.py
@@ -84,6 +84,13 @@ 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"] = {
@@ -110,6 +117,13 @@ 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/web/plugins/visuals/filters.py b/web/plugins/visuals/filters.py
index a6bc303..54fe5f3 100644
--- a/web/plugins/visuals/filters.py
+++ b/web/plugins/visuals/filters.py
@@ -532,18 +532,6 @@ class FilterSite(Filter):
choices.append((sitename, config.site(sitename)["alias"]))
html.sorted_select("site", choices)
- def filter(self, infoname):
- if config.is_multisite():
- site = html.var("site")
- if site:
- return "Sites: %s\n" % (html.var("site",
""))
- elif not self.enforce:
- return ""
- else:
- return "Sites:\n" # no site at all
- else:
- return ""
-
def heading_info(self):
current_value = html.var("site")
if current_value:
diff --git a/web/plugins/visuals/infos.py b/web/plugins/visuals/infos.py
index 645c3b8..3c5f681 100644
--- a/web/plugins/visuals/infos.py
+++ b/web/plugins/visuals/infos.py
@@ -47,6 +47,7 @@ infos['service'] = {
infos['hostgroup'] = {
'title' : _('Host Group'),
'title_plural': _('Host Groups'),
+ 'single_site' : False, # spread over multiple sites
'single_spec' : [
('hostgroup', TextUnicode(
title = _('Host Group Name'),
@@ -57,6 +58,7 @@ infos['hostgroup'] = {
infos['servicegroup'] = {
'title' : _('Service Group'),
'title_plural': _('Service Groups'),
+ 'single_site' : False, # spread over multiple sites
'single_spec' : [
('servicegroup', TextUnicode(
title = _('Service Group Name'),