Module: check_mk
Branch: master
Commit: 5805e66f78fc816b23512621c1f4ed418238e758
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5805e66f78fc81…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Feb 11 17:44:13 2016 +0100
#2992 New visual filter: "Hostname or Alias"
Previously you could either search for the hostname or the hostalias
with distinct filters. This new filter returns both matches, e.g
any hosts starting with 'server7' and any hostaliases with 'server7'.
The <i>Quicksearch</i> sidebar snapin also supports this new filter.
If you want to use it you need to edit the target view of the quicksearch,
usually <i>searchhost</i>, and replace the <i>Hostname</i> filter
with the
<i>Hostname or Alias</i> filter. If both filters are active, you will only
get the hostnames on the quicksearch.<br>
Reason: <i>Hostname</i> AND <i>Hostname and Alias</i>: Just the
hostname...
---
.werks/2992 | 19 +++++++++++++++++++
ChangeLog | 1 +
web/htdocs/sidebar.py | 27 ++++++++++++++++++++-------
web/plugins/visuals/filters.py | 26 +++++++++++++++++++++++++-
4 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/.werks/2992 b/.werks/2992
new file mode 100644
index 0000000..9eecf6f
--- /dev/null
+++ b/.werks/2992
@@ -0,0 +1,19 @@
+Title: New visual filter: "Hostname or Alias"
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.7i4
+Date: 1455208441
+Class: feature
+
+Previously you could either search for the hostname or the hostalias
+with distinct filters. This new filter returns both matches, e.g
+any hosts starting with 'server7' and any hostaliases with 'server7'.
+
+The <i>Quicksearch</i> sidebar snapin also supports this new filter.
+If you want to use it you need to edit the target view of the quicksearch,
+usually <i>searchhost</i>, and replace the <i>Hostname</i> filter
with the
+<i>Hostname or Alias</i> filter. If both filters are active, you will only
+get the hostnames on the quicksearch.<br>
+
+Reason: <i>Hostname</i> AND <i>Hostname and Alias</i>: Just the
hostname...
diff --git a/ChangeLog b/ChangeLog
index 9d6d3b5..da12669 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -275,6 +275,7 @@
* 2769 Verifying that the Check_MK GUI is not used with Apache threaded MPM (e.g.
worker)
* 2880 Automatically detect changes in local web/plugins, no Apache restart needed
anymore...
* 2929 Show all metrics of a service in a nicely formatted table in the service
details
+ * 2992 New visual filter: "Hostname or Alias"...
* 2680 FIX: LDAP: Fixed exception when syncing groups using configurations from
previous versions...
* 2435 FIX: New graphing system: fixed broken graphs for iSCSI checks...
* 2696 FIX: Fixed broken perfometer for update checks
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index bb5575e..b6658ac 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -691,7 +691,14 @@ def plugin_matches_filters(plugin, used_filters):
return False
return True
-def search_url_tmpl(used_filters, row, exact = True):
+def search_url_tmpl(used_filters, matched_instances):
+ exact = True
+ if matched_instances and len(matched_instances) == 1:
+ row = matched_instances[0]
+ else:
+ row = matched_instances and matched_instances[0] or None
+ exact = False
+
if not row:
def find_plugin(filters):
for entry in search_plugins:
@@ -763,6 +770,15 @@ def search_url_tmpl(used_filters, row, exact = True):
'site' : site,
}
+ # This little 'adjustment' adds an extra url parameter for an optional
hostnameoralias filter in the target view.
+ # If this filter is not activated it won't have any impact. The search_url_templ
function is currently not designed
+ # to handle matches of multiple filter types and probably requires a complete
revision to support this.
+ if not exact and matched_instances:
+ found_plugins = set(map(lambda instances: instances[0]["id"],
matched_instances))
+ # Only add this extra parameter if there are solely hosts and host_alias matches
+ if "hosts" in found_plugins or "host_alias" in
found_plugins:
+ url_tmpl += "&hostnameoralias=%s" % used_filters[0][1]
+
return url_tmpl
@@ -909,7 +925,7 @@ def render_search_results(used_filters, objects, format_func =
format_result):
# Find missing urls
name = get_row_name(row)
if "url" not in row_options:
- row_options["url"] = search_url_tmpl(used_filters, row)
+ row_options["url"] = search_url_tmpl(used_filters, [row])
obj_id = (row_options["url"], name)
if obj_id not in unique:
@@ -952,14 +968,11 @@ def search_open():
if not q:
return
- data, used_filters = process_search(q)
+ matched_instances, used_filters = process_search(q)
if not used_filters:
return
- if data and len(data) == 1:
- url = search_url_tmpl(used_filters, data[0])
- else:
- url = search_url_tmpl(used_filters, data and data[0] or None, exact = False)
+ url = search_url_tmpl(used_filters, matched_instances)
html.set_http_header('Location', url)
from mod_python import apache
diff --git a/web/plugins/visuals/filters.py b/web/plugins/visuals/filters.py
index bbe1d96..b7e915f 100644
--- a/web/plugins/visuals/filters.py
+++ b/web/plugins/visuals/filters.py
@@ -32,7 +32,8 @@ class FilterText(Filter):
htmlvars = [htmlvar]
if negateable:
htmlvars.append("neg_" + htmlvar)
- Filter.__init__(self, name, title, info, htmlvars, [column])
+ link_columns = type(column) == list and column or [column]
+ Filter.__init__(self, name, title, info, htmlvars, link_columns)
self.op = op
self.column = column
self.negateable = negateable
@@ -79,6 +80,25 @@ class FilterUnicode(FilterText):
htmlvar = self.htmlvars[0]
return html.get_unicode_input(htmlvar, "")
+class FilterHostnameOrAlias(FilterUnicode):
+ def __init__(self, *args):
+ FilterUnicode.__init__(self, *args)
+
+ def filter(self, infoname):
+ current_value = self._current_value()
+
+ if self.negateable and html.get_checkbox(self.htmlvars[1]):
+ negate = "!"
+ else:
+ negate = ""
+
+ if current_value:
+ if type(current_value) == unicode:
+ current_value = current_value.encode("utf-8")
+ return "Filter: host_name %s%s %s\nFilter: alias %s%s %s\nOr: 2\n"
% ((negate, self.op, lqencode(current_value)) * 2)
+ else:
+ return ""
+
# filter title info column
htmlvar
declare_filter(100, FilterText("hostregex", _("Hostname"),
"host", "host_name", "host_regex", "~~"
, True),
_("Search field allowing regular expressions and partial
matches"))
@@ -100,6 +120,10 @@ declare_filter(202, FilterUnicode("service_display_name",
_("Service alternative
declare_filter(202, FilterUnicode("output", _("Status detail"),
"service", "service_plugin_output", "service_output",
"~~"))
+declare_filter(102, FilterHostnameOrAlias("hostnameoralias", _("Hostname
or Alias"), "host", ["host_alias", "host_name"],
"hostnameoralias", "~~", False),
+ _("Search field allowing regular expressions and partial
matches"))
+
+
class FilterIPAddress(Filter):
def __init__(self, what):
self._what = what