Module: check_mk
Branch: master
Commit: 89d44cb6c4e58a992066def7460d34a70d567bcd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=89d44cb6c4e58a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 17 15:09:55 2017 +0100
4279 Performance snapins: Added site selection field to all performance snapins
Change-Id: I62a3830a20ffe21054eee402d0b6e4d18615af3e
---
.werks/4279 | 9 +++++++++
ChangeLog | 1 +
web/htdocs/config.py | 20 ++++++++++++++++++++
web/htdocs/sidebar.py | 6 ++----
web/htdocs/watolib.py | 22 +++-------------------
web/plugins/sidebar/mkeventd.py | 3 +--
web/plugins/sidebar/shipped.py | 27 +++++++++++++++++++++------
web/plugins/wato/mkeventd.py | 2 +-
8 files changed, 58 insertions(+), 32 deletions(-)
diff --git a/.werks/4279 b/.werks/4279
new file mode 100644
index 0000000..802d16e
--- /dev/null
+++ b/.werks/4279
@@ -0,0 +1,9 @@
+Title: Performance snapins: Added site selection field to all performance snapins
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.4.0i4
+Date: 1484662169
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index d9f331c..4d64795 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -61,6 +61,7 @@
* 4169 View action: Default values of sticky, notification and persistent options can
now be configured via global settings....
* 4229 New Web GUI logging configuration...
* 4011 Quicksearch: Introduced new filters tg, ad and al...
+ * 4279 Performance snapins: Added site selection field to all performance snapins
* 4143 FIX: Fixed possible log spam "MKAuthException: Invalid credentials"
in web.log...
* 4004 FIX: Fixed exception when viewing availability of BI aggregations...
* 4144 FIX: Sidebar: Bottom of last snapin was not 100% visible
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 26fef3a..cdd4f2f 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -695,6 +695,26 @@ def is_single_local_site():
sitename = sites.keys()[0]
return site_is_local(sitename)
+
+def site_choices(filter_func=None):
+ choices = []
+ for site_id, site in sites.items():
+ if filter_func and not filter_func(site_id, site):
+ continue
+
+ title = site_id
+ if site.get("alias"):
+ title += " - " + site["alias"]
+
+ choices.append((site_id, title))
+
+ return sorted(choices, key=lambda s: s[1])
+
+
+def get_event_console_site_choices():
+ return site_choices(filter_func=lambda site_id, site: site_is_local(site_id) or
site.get("replicate_ec"))
+
+
#.
# .--Plugins-------------------------------------------------------------.
# | ____ _ _ |
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index e61dd0a..e30c66f 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -144,8 +144,7 @@ def snapin_site_choice(ident, choices):
else:
only_sites = [site]
- import wato
- site_choices = wato.get_event_console_site_choices()
+ site_choices = config.get_event_console_site_choices()
if len(site_choices) <= 1:
return None
@@ -647,9 +646,8 @@ def ajax_set_snapin_site():
raise MKUserError(None, _("Invalid ident"))
site = html.var("site")
- import wato
site_choices = dict([ ("", _("All sites")), ] \
- + wato.get_event_console_site_choices())
+ + config.get_event_console_site_choices())
if site not in site_choices:
raise MKUserError(None, _("Invalid site"))
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index a0f2dd3..331cdd5 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -3545,27 +3545,11 @@ def get_login_sites():
# Returns a list of site ids which gets the Event Console configuration replicated
def get_event_console_sync_sites():
- return [ s[0] for s in get_event_console_site_choices() ]
+ return [ s[0] for s in config.get_event_console_site_choices() ]
-def get_event_console_site_choices():
- return site_choices(filter_func=lambda site_id, site: config.site_is_local(site_id)
or site.get("replicate_ec"))
-
-
-def site_choices(filter_func=None):
- choices = []
- for site_id, site in config.sites.items():
- if filter_func and not filter_func(site_id, site):
- continue
-
- title = site_id
- if site.get("alias"):
- title += " - " + site["alias"]
-
- choices.append((site_id, title))
-
- return sorted(choices, key=lambda s: s[1])
-
+# TODO: cleanup all call sites to this name
+site_choices = config.site_choices
def declare_site_attribute():
diff --git a/web/plugins/sidebar/mkeventd.py b/web/plugins/sidebar/mkeventd.py
index 8356011..7059740 100644
--- a/web/plugins/sidebar/mkeventd.py
+++ b/web/plugins/sidebar/mkeventd.py
@@ -83,8 +83,7 @@ def mkeventd_performance_entries(only_sites):
def render_mkeventd_performance():
only_sites = snapin_site_choice("mkeventd_performance",
- wato.get_event_console_site_choices())
-
+ config.get_event_console_site_choices())
try:
entries = mkeventd_performance_entries(only_sites)
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 1eae6be..b3155f0 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -856,6 +856,8 @@ sidebar_snapins["tactical_overview"] = {
# '----------------------------------------------------------------------'
def render_performance():
+ only_sites = snapin_site_choice("performance",
+ config.site_choices())
def write_line(left, right):
html.open_tr()
@@ -865,9 +867,15 @@ def render_performance():
html.open_table(class_=["content_center", "performance"])
- data = sites.live().query("GET status\nColumns: service_checks_rate
host_checks_rate "
- "external_commands_rate connections_rate forks_rate
"
- "log_messages_rate cached_log_messages\n")
+ try:
+ sites.live().set_only_sites(only_sites)
+ data = sites.live().query(
+ "GET status\nColumns: service_checks_rate host_checks_rate "
+ "external_commands_rate connections_rate forks_rate "
+ "log_messages_rate cached_log_messages\n")
+ finally:
+ sites.live().set_only_sites(None)
+
for what, col, format in \
[("Service checks", 0, "%.2f/s"),
("Host checks", 1, "%.2f/s"),
@@ -878,9 +886,12 @@ def render_performance():
("Cached log messages", 6, "%d")]:
write_line(what + ":", format % sum(row[col] for row in data))
- if len(config.allsites()) == 1:
- data = sites.live().query("GET status\nColumns:
external_command_buffer_slots "
- "external_command_buffer_max\n")
+ if only_sites is None and len(config.allsites()) == 1:
+ try:
+ data = sites.live().query("GET status\nColumns:
external_command_buffer_slots "
+ "external_command_buffer_max\n")
+ finally:
+ sites.live().set_only_sites(None)
size = sum([row[0] for row in data])
maxx = sum([row[1] for row in data])
write_line(_('Com. buf. max/total'), "%d / %d" % (maxx, size))
@@ -895,6 +906,10 @@ sidebar_snapins["performance"] = {
"render" : render_performance,
"allowed" : [ "admin", ],
"styles" : """
+#snapin_performance select {
+ margin-bottom: 2px;
+ width: 100%%;
+}
table.performance {
width: %dpx;
border-radius: 2px;
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 7c5b08a..983d0d8 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -889,7 +889,7 @@ vs_mkeventd_event = Dictionary(
)),
("site", DropdownChoice(
title = _("Simulate for site"),
- choices = get_event_console_site_choices,
+ choices = config.get_event_console_site_choices,
)),
])