Module: check_mk
Branch: master
Commit: 237f7f7477d458a38eaea759ac95db99a2616803
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=237f7f7477d458…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 14 10:13:04 2017 +0100
CME: Extended the site filter to be able to handle customers
Change-Id: I7b17aa7f7a6741ea15a0684d802683de70faab3a
---
livestatus/api/python/livestatus.py | 9 ++++++--
web/htdocs/sites.py | 9 +++++++-
web/htdocs/visuals.py | 3 +++
web/plugins/visuals/filters.py | 41 ++++++++++++++++++++++++++-----------
4 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/livestatus/api/python/livestatus.py b/livestatus/api/python/livestatus.py
index 45f521a..7a5a6d2 100644
--- a/livestatus/api/python/livestatus.py
+++ b/livestatus/api/python/livestatus.py
@@ -601,8 +601,13 @@ class MultiSiteConnection(Helpers):
def set_prepend_site(self, p):
self.prepend_site = p
- def set_only_sites(self, os = None):
- self.only_sites = os
+ def set_only_sites(self, sites=None):
+ """Make future queries only contact the given sites.
+
+ Provide a list of site IDs to not contact all configured sites, but only the
listed
+ site IDs. In case None is given, the limitation is removed.
+ """
+ self.only_sites = sites
# Impose Limit on number of returned datasets (distributed amoung sites)
def set_limit(self, limit = None):
diff --git a/web/htdocs/sites.py b/web/htdocs/sites.py
index 0e7844d..003cd7d 100644
--- a/web/htdocs/sites.py
+++ b/web/htdocs/sites.py
@@ -24,6 +24,8 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+import cmk
+
import config
import livestatus
@@ -106,7 +108,12 @@ def _connect_multiple_sites():
global _live
enabled_sites, disabled_sites = _get_enabled_and_disabled_sites()
_set_initial_site_states(enabled_sites, disabled_sites)
- _live = livestatus.MultiSiteConnection(enabled_sites, disabled_sites)
+
+ if cmk.is_managed_edition():
+ import managed
+ _live = managed.CMEMultiSiteConnection(enabled_sites, disabled_sites)
+ else:
+ _live = livestatus.MultiSiteConnection(enabled_sites, disabled_sites)
# Fetch status of sites by querying the version of Nagios and livestatus
# This may be cached by a proxy for up to the next configuration reload.
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 8be6f07..3c18941 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -83,6 +83,8 @@ def load_plugins(force):
global ubiquitary_filters ; ubiquitary_filters = [] # Always show these filters
load_web_plugins('visuals', globals())
+ declare_site_filters()
+
loaded_with_language = current_language
#.
@@ -850,6 +852,7 @@ def show_filter(f):
except Exception, e:
#TODO: html.plugged_text = ''
#TODO: html.unplug()
+ log_exception()
tb = sys.exc_info()[2]
tbs = ['Traceback (most recent call last):\n']
tbs += traceback.format_tb(tb)
diff --git a/web/plugins/visuals/filters.py b/web/plugins/visuals/filters.py
index 77a9a65..60128b5 100644
--- a/web/plugins/visuals/filters.py
+++ b/web/plugins/visuals/filters.py
@@ -689,21 +689,27 @@ class FilterSite(Filter):
Filter.__init__(self, name, _("Site") + (enforce and _( "
(enforced)") or ""), 'host', ["site"], [])
self.enforce = enforce
+
def visible(self):
return config.is_multisite()
+
def display(self):
- if not config.is_multisite():
- choices = [("", _("(local)"))]
+ html.select("site", self._choices())
+
+
+ def _choices(self):
+ if self.enforce:
+ choices = []
else:
- if self.enforce:
- choices = []
- else:
- choices = [("","")]
- for sitename, state in sites.states().items():
- if state["state"] == "online":
- choices.append((sitename, config.site(sitename)["alias"]))
- html.sorted_select("site", choices)
+ choices = [("","")]
+
+ for sitename, state in sites.states().items():
+ if state["state"] == "online":
+ choices.append((sitename, config.site(sitename)["alias"]))
+
+ return sorted(choices, key=lambda a: a[1].lower())
+
def heading_info(self):
current_value = html.var("site")
@@ -711,11 +717,22 @@ class FilterSite(Filter):
alias = config.site(current_value)["alias"]
return alias
+
def variable_settings(self, row):
return [("site", row["site"])]
-declare_filter(500, FilterSite("siteopt", False), _("Optional selection of
a site"))
-declare_filter(501, FilterSite("site", True), _("Selection of site is
enforced, use this filter for joining"))
+
+
+def declare_site_filters():
+ if cmk.is_managed_edition():
+ cls = FilterCMESite
+ else:
+ cls = FilterSite
+
+ declare_filter(500, cls("siteopt", False),
+ _("Optional selection of a site"))
+ declare_filter(501, cls("site", True),
+ _("Selection of site is enforced, use this filter for
joining"))
# name: internal id of filter
# title: user displayed title of the filter