Module: check_mk
Branch: master
Commit: b16e33bf8f6c027211ed7393990df39e558c3296
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b16e33bf8f6c02…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jul 12 09:10:23 2018 +0200
Moved helper function to fetch groups from livestatus to more generic place
Change-Id: I85f6bb7a90adea0e471f4f6b4b69d5f00e289574
---
cmk/gui/availability.py | 2 +-
cmk/gui/plugins/sidebar/shipped.py | 6 +-----
cmk/gui/sites.py | 10 ++++++++++
web/plugins/visuals/filters.py | 12 +++---------
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/cmk/gui/availability.py b/cmk/gui/availability.py
index c08ceef..da661d5 100644
--- a/cmk/gui/availability.py
+++ b/cmk/gui/availability.py
@@ -1050,7 +1050,7 @@ def compute_availability_groups(what, av_data, avoptions):
# 2. Compute names for the groups and sort according to these names
if grouping != "host":
- group_titles = dict(visuals.all_groups(grouping[:-7]))
+ group_titles = dict(sites.all_groups(grouping[:-7]))
titled_groups = []
for group_id in all_group_ids:
diff --git a/cmk/gui/plugins/sidebar/shipped.py b/cmk/gui/plugins/sidebar/shipped.py
index bbc391b..01c360f 100644
--- a/cmk/gui/plugins/sidebar/shipped.py
+++ b/cmk/gui/plugins/sidebar/shipped.py
@@ -207,12 +207,8 @@ sidebar_snapins["dashboards"] = {
# '----------------------------------------------------------------------'
def render_groups(what):
- data = sites.live().query("GET %sgroups\nColumns: name alias\n" % what)
- name_to_alias = dict(data)
- groups = [(name_to_alias[name].lower(), name_to_alias[name], name) for name in
name_to_alias.keys()]
- groups.sort() # sort by Alias in lowercase
html.open_ul()
- for alias_lower, alias, name in groups:
+ for name, alias in sites.all_groups(what):
url = "view.py?view_name=%sgroup&%sgroup=%s" % (what, what,
html.urlencode(name))
bulletlink(alias or name, url)
html.close_ul()
diff --git a/cmk/gui/sites.py b/cmk/gui/sites.py
index 008c8cd..e588414 100644
--- a/cmk/gui/sites.py
+++ b/cmk/gui/sites.py
@@ -102,6 +102,16 @@ def cores_by_site():
return cores
+
+def all_groups(what):
+ # type: (str) -> List[Tuple[str, str]]
+ """Returns a list of host/service/contact groups (pairs of
name/alias)
+
+ Groups are collected via livestatus from all sites. In case no alias is defined
+ the name is used as second element. The list is sorted by lower case alias in the
first place."""
+ groups = live().query("GET %sgroups\nCache: reload\nColumns: name alias\n"
% what)
+ return sorted([ (name, alias or name) for name, alias in groups ], key=lambda e:
e[1].lower())
+
#.
# .--Internal------------------------------------------------------------.
# | ___ _ _ |
diff --git a/web/plugins/visuals/filters.py b/web/plugins/visuals/filters.py
index 9d44ec1..44ef7a8 100644
--- a/web/plugins/visuals/filters.py
+++ b/web/plugins/visuals/filters.py
@@ -256,12 +256,6 @@ class FilterAddressFamilies(Filter):
declare_filter(103, FilterAddressFamilies())
-# Helper that retrieves the list of host/service/contactgroups via Livestatus
-# use alias by default but fallback to name if no alias defined
-def all_groups(what):
- groups = dict(sites.live().query("GET %sgroups\nCache: reload\nColumns: name
alias\n" % what))
- return [ (name, groups[name] or name) for name in groups.keys() ]
-
class FilterMultigroup(Filter):
def __init__(self, what, title, negateable=False):
self.htmlvar = what + "groups"
@@ -281,7 +275,7 @@ class FilterMultigroup(Filter):
def valuespec(self):
return DualListChoice(
- choices = all_groups(self.what),
+ choices = sites.all_groups(self.what),
rows=3 if self.negateable else 4,
enlarge_active=True
)
@@ -340,7 +334,7 @@ class FilterGroupCombo(Filter):
return True
def display(self):
- choices = all_groups(self.what.split("_")[-1])
+ choices = sites.all_groups(self.what.split("_")[-1])
if not self.enforce:
choices = [("", "")] + choices
html.dropdown(self.htmlvars[0], choices, sorted=True)
@@ -418,7 +412,7 @@ class FilterGroupSelection(Filter):
self.what = infoname
def display(self):
- choices = all_groups(self.what[:-5]) # chop off "group", leaves host or
service
+ choices = sites.all_groups(self.what[:-5]) # chop off "group", leaves
host or service
html.dropdown(self.htmlvars[0], choices, sorted=True)
def current_value(self):