Module: check_mk
Branch: master
Commit: 60e94e65a1b629c968e8e187b921ca9a1c3f62a0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=60e94e65a1b629…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Aug 3 10:49:58 2016 +0200
3752 FIX Fixed loosing site configuration when editing hosts in WATO slave sites
When having a distributed setup where WATO is enabled on slaves and hosts were
editied, the hosts in the folder of that host were resetting the site attribute
so that they are being monitored by the remote site, even when they were configured
to be monitored on another site.
The slave sites are now checking for the configured unknown sites and warning you
about that fact. To override the configured site attributes, you have to explicitly
change the value of the site attribute.
---
.werks/3752 | 16 +++++++++++++
web/htdocs/config.py | 1 +
web/htdocs/valuespec.py | 13 ++++++++--
web/htdocs/watolib.py | 61 ++++++++++++++++++++++++++++++-----------------
4 files changed, 67 insertions(+), 24 deletions(-)
diff --git a/.werks/3752 b/.werks/3752
new file mode 100644
index 0000000..015dd13
--- /dev/null
+++ b/.werks/3752
@@ -0,0 +1,16 @@
+Title: Fixed loosing site configuration when editing hosts in WATO slave sites
+Level: 2
+Component: wato
+Compatible: compat
+Version: 1.2.8p9
+Date: 1470213362
+Class: fix
+
+When having a distributed setup where WATO is enabled on slaves and hosts were
+editied, the hosts in the folder of that host were resetting the site attribute
+so that they are being monitored by the remote site, even when they were configured
+to be monitored on another site.
+
+The slave sites are now checking for the configured unknown sites and warning you
+about that fact. To override the configured site attributes, you have to explicitly
+change the value of the site attribute.
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 0335e2c..90fb6f6 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -578,6 +578,7 @@ def default_site():
return None
+
def is_multisite():
# TODO: Remove all calls of this function
return True
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 8181c8b..6440e81 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1282,7 +1282,7 @@ class DropdownChoice(ValueSpec):
# In complain mode: Use the value received from the HTML variable
if self._invalid_choice == "complain" and value != None and
self._value_is_invalid(value):
defval = value
- options.append((value, "%s (%s)" % (value,
self._invalid_choice_title)))
+ options.append((defval, self._get_invalid_choice_title(value)))
if value == None and not options:
html.write(self._empty_text)
@@ -1298,6 +1298,14 @@ class DropdownChoice(ValueSpec):
else:
html.sorted_select(varprefix, options, defval, onchange=self._on_change)
+
+ def _get_invalid_choice_title(self, value):
+ if "%s" in self._invalid_choice_title:
+ return self._invalid_choice_title % value
+ else:
+ return self._invalid_choice_title
+
+
def value_to_text(self, value):
for entry in self.choices():
val, title = entry[:2]
@@ -1306,7 +1314,8 @@ class DropdownChoice(ValueSpec):
return title.split(self._help_separator, 1)[0].strip()
else:
return title
- return _("(other: %s)" % html.attrencode(value))
+ return html.attrencode(self._get_invalid_choice_title(value))
+
def from_html_vars(self, varprefix):
sel = html.var(varprefix)
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 80364b8..d32e7df 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -1246,7 +1246,7 @@ class Folder(BaseFolder):
elif self.has_parent():
return self.parent().site_id()
else:
- return config.default_site()
+ return default_site()
def all_site_ids(self):
@@ -3429,6 +3429,20 @@ def is_distributed(sites = None):
return False
+# Returns the ID of the default site. This is the site the main folder has
+# configured by default. It inherits to all folders and hosts which don't have
+# a site set on their own.
+# In standalone and master sites this defaults to the local site. In distributed
+# slave sites, we don't know the site ID of the master site. We set this explicit
+# to false to configure that this host is monitored by another site (that we don't
+# know about).
+def default_site():
+ if is_wato_slave_site():
+ return False
+ else:
+ return config.default_site()
+
+
def is_wato_slave_site():
return has_distributed_wato_file() and not has_wato_slave_sites()
@@ -3443,38 +3457,41 @@ def wato_slave_sites():
def declare_site_attribute():
undeclare_host_attribute("site")
- if is_distributed():
- declare_host_attribute(SiteAttribute(), show_in_table = True, show_in_folder =
True)
+ declare_host_attribute(SiteAttribute(), show_in_table = True, show_in_folder = True)
-class SiteAttribute(Attribute):
+class SiteAttribute(ValueSpecAttribute):
def __init__(self):
# Default is is the local one, if one exists or
# no one if there is no local site
- self._choices = []
+ choices = []
for id, site in config.sites.items():
title = id
if site.get("alias"):
title += " - " + site["alias"]
- self._choices.append((id, title))
-
- self._choices.sort(cmp=lambda a,b: cmp(a[1], b[1]))
- self._choices_dict = dict(self._choices)
- Attribute.__init__(self, "site", _("Monitored on site"),
- _("Specify the site that should monitor this host."),
- default_value = config.default_site())
-
- def paint(self, value, hostname):
- return "", self._choices_dict.get(value, value)
-
- def render_input(self, varprefix, value):
- html.select(varprefix + "site", self._choices, value)
-
- def from_html_vars(self, varprefix):
- return html.var(varprefix + "site")
+ choices.append((id, title))
+
+ choices.sort(cmp=lambda a,b: cmp(a[1], b[1]))
+
+ ValueSpecAttribute.__init__(self, "site", DropdownChoice(
+ title=_("Monitored on site"),
+ help=_("Specify the site that should monitor this host."),
+ default_value = default_site(),
+ choices = choices,
+ invalid_choice = "complain",
+ invalid_choice_title = _("Unknown site (%s)"),
+ invalid_choice_error = _("The configured site is not known to this site.
In case you "
+ "are configuring in a distributed slave, this
may be a host "
+ "monitored by another site. If you want to
modify this "
+ "host, you will have to change the site
attribute to the "
+ "local site. But this may make the host be
monitored from "
+ "multiple sites.")
+ ))
def get_tag_list(self, value):
- if value != None:
+ if value == False:
+ return [ "site:" ]
+ elif value != None:
return [ "site:" + value ]
else:
return []