Module: check_mk
Branch: master
Commit: 987b23c86ed07fa9fc25987718501291511d21e4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=987b23c86ed07f…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Mar 14 11:37:13 2017 +0100
quicksearch: removed last hardcoded plugin code
Change-Id: I3f64b829174edcefc471a48ed3474faff0f184c4
---
web/htdocs/sidebar.py | 36 +++++++++++++-----------------------
web/plugins/sidebar/search.py | 18 ++++++++++++------
2 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index c574800..252ab22 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -856,34 +856,24 @@ class LivestatusSearchConductor(object):
# Hostgroups -> Hosts -> Services
# Servicegroups -> Services
- # TODO: This is currently hardcoded
- # So whenever a new filter is introduced this block
- # requires an update too..
- table_to_query = ""
-
- if "hg" in self._used_filters:
- table_to_query = "hostgroups"
-
- if "h" in self._used_filters:
- table_to_query = "hosts"
-
- if "ad" in self._used_filters:
- table_to_query = "hosts"
-
- if "al" in self._used_filters:
- table_to_query = "hosts"
+ preferred_tables = []
+ for shortname in self._used_filters.keys():
+ plugin = self._get_plugin_with_shortname(shortname)
+ preferred_tables.append(plugin.get_preferred_livestatus_table())
- if "tg" in self._used_filters:
- table_to_query = "hosts"
- if "sg" in self._used_filters:
- if table_to_query in ["hosts", "hostgroups"]:
+ table_to_query = ""
+ if "services" in preferred_tables:
+ table_to_query = "services"
+ elif "servicegroups" in preferred_tables:
+ if "hosts" in preferred_tables or "hostgroups" in
preferred_tables:
table_to_query = "services"
else:
table_to_query = "servicegroups"
-
- if "s" in self._used_filters:
- table_to_query = "services"
+ elif "hosts" in preferred_tables:
+ table_to_query = "hosts"
+ elif "hostgroups" in preferred_tables:
+ table_to_query = "hostgroups"
self._livestatus_table = table_to_query
diff --git a/web/plugins/sidebar/search.py b/web/plugins/sidebar/search.py
index c437f85..5bc00d1 100644
--- a/web/plugins/sidebar/search.py
+++ b/web/plugins/sidebar/search.py
@@ -142,9 +142,10 @@ sidebar_snapins["search"] = {
class QuicksearchMatchPlugin(object):
- def __init__(self, livestatus_tables, filter_shortname):
+ def __init__(self, supported_livestatus_tables, preferred_livestatus_table,
filter_shortname):
self._filter_shortname = filter_shortname
- self._livestatus_tables = livestatus_tables
+ self._supported_livestatus_tables = supported_livestatus_tables
+ self._preferred_livestatus_table = preferred_livestatus_table
super(QuicksearchMatchPlugin, self).__init__()
@@ -152,13 +153,17 @@ class QuicksearchMatchPlugin(object):
return self._filter_shortname
+ def get_preferred_livestatus_table(self):
+ return self._preferred_livestatus_table
+
+
def is_filter_set(self, used_filters):
return self.get_filter_shortname() in used_filters
def is_used_for_table(self, livestatus_table, used_filters):
# Check if this filters handles the table at all
- if livestatus_table not in self._livestatus_tables:
+ if livestatus_table not in self._supported_livestatus_tables:
return False
if self.get_filter_shortname() not in used_filters:
@@ -199,6 +204,7 @@ class QuicksearchMatchPlugin(object):
class GroupMatchPlugin(QuicksearchMatchPlugin):
def __init__(self, group_type = None, filter_shortname = None):
super(GroupMatchPlugin, self).__init__(["%sgroups" % group_type,
"%ss" % group_type, "services"],
+ "%sgroups" % group_type,
filter_shortname)
self._group_type = group_type
@@ -271,7 +277,7 @@ class GroupMatchPlugin(QuicksearchMatchPlugin):
class ServiceMatchPlugin(QuicksearchMatchPlugin):
def __init__(self):
- super(ServiceMatchPlugin, self).__init__(["services"], "s")
+ super(ServiceMatchPlugin, self).__init__(["services"],
"services", "s")
def get_match_topic(self):
@@ -309,7 +315,7 @@ class ServiceMatchPlugin(QuicksearchMatchPlugin):
class HostMatchPlugin(QuicksearchMatchPlugin):
def __init__(self, livestatus_field = None, filter_shortname = None):
- super(HostMatchPlugin, self).__init__(["hosts", "services"],
filter_shortname)
+ super(HostMatchPlugin, self).__init__(["hosts", "services"],
"hosts", filter_shortname)
self._livestatus_field = livestatus_field # address, name or alias
@@ -386,7 +392,7 @@ class HostMatchPlugin(QuicksearchMatchPlugin):
class HosttagMatchPlugin(QuicksearchMatchPlugin):
def __init__(self):
- super(HosttagMatchPlugin, self).__init__(["hosts",
"services"], "tg")
+ super(HosttagMatchPlugin, self).__init__(["hosts",
"services"], "hosts", "tg")
def _get_hosttag_dict(self):