Module: check_mk
Branch: master
Commit: 955eea032a8b3ab6718190f744dc227d5b78685e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=955eea032a8b3a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 12 16:47:03 2016 +0200
Cleaned up code for host unmonitored service view
---
web/plugins/views/datasources.py | 70 ++++++++++++++++------------------------
web/plugins/visuals/filters.py | 57 ++++++++++++++++++++------------
web/plugins/visuals/infos.py | 12 ++-----
3 files changed, 66 insertions(+), 73 deletions(-)
diff --git a/web/plugins/views/datasources.py b/web/plugins/views/datasources.py
index eb03361..b08e594 100644
--- a/web/plugins/views/datasources.py
+++ b/web/plugins/views/datasources.py
@@ -241,59 +241,45 @@ multisite_datasources["alert_stats"] = {
"time_filters" : [ "logtime" ],
}
+# The livestatus query constructed by the filters of the view may
+# contain filters that are related to the discovery info and should only be
+# handled here. We need to extract them from the query, hand over the regular
+# filters to the host livestatus query and apply the others during the discovery
+# service query.
def query_service_discovery(columns, query, only_sites, limit, all_active_filters):
- # query contains combined filters, some of which may refer to an actual livestatus
- # column, others to the dynamic one generated here. fun fun fun
- filters = query.split("\n")
- view_filters = [filt for filt in filters if filt.startswith("ViewFilter")]
+ # Hard code the discovery service filter
+ query += "Filter: check_command = check-mk-inventory\n"
- lq_filters =\
- ["Filter: check_command = check-mk-inventory"] +\
- [filt for filt in filters if not filt.startswith("ViewFilter")]
-
- rows = do_query_data(
- "GET services\n",
+ service_rows = do_query_data("GET services\n",
["host_state", "host_has_been_checked",
"long_plugin_output", "host_name"], [], [],
- "\n".join(lq_filters), only_sites, limit, "read")
-
- # convert list of strings "ViewFilter: var = value" to list of tuples (var,
value)
- view_filters = [map(lambda s: s.strip(),
filt.split(":")[1].split("="))
- for filt in view_filters]
- # convert list of (var, value) tuples to dictionary {var: [val1, val2, val3] ... }
- view_filters = dict([(filt[0], [inner[1] for inner in view_filters
- if inner[0] == filt[0]])
- for filt in view_filters])
+ query, only_sites, limit, "read")
- result = []
- # one row per host
- for row in rows:
+ rows = []
+ for row in service_rows:
for service_line in row["long_plugin_output"].split("\n"):
- if service_line:
- state, check, service = map(lambda s: s.strip(),
service_line.split(":", 2))
- include = True
- for var, varname in [(state, "state"), (check,
"check")]:
- if varname in view_filters and var not in view_filters[varname]:
- include = False
- if include:
- result.append({
- "site" : row["site"],
- "host_name" : row["host_name"],
- "host_state" : row["host_state"],
- "host_has_been_checked" :
row["host_has_been_checked"],
- "discovery_state" : state,
- "discovery_check" : check,
- "discovery_service" : service
- })
+ if not service_line:
+ continue
+
+ state, check, service_description = map(lambda s: s.strip(),
service_line.split(":", 2))
+
+ rows.append({
+ "site" : row["site"],
+ "host_name" : row["host_name"],
+ "host_state" : row["host_state"],
+ "host_has_been_checked" :
row["host_has_been_checked"],
+ "discovery_state" : state,
+ "discovery_check" : check,
+ "discovery_service" : service_description
+ })
- return result
+ return rows
multisite_datasources["service_discovery"] = {
"title" : _("Service discovery"),
"table" : query_service_discovery,
"add_columns" : [ "discovery_state", "discovery_check",
"discovery_service" ],
- "add_headers" : "Filter: check_command = check-mk-inventory",
- "infos" : [ "host", "long_plugin_output" ],
+ "infos" : [ "host", "host_discovery" ],
"keys" : [],
- "idkeys" : [ 'host_name' ]
+ "idkeys" : [ "host_name" ]
}
diff --git a/web/plugins/visuals/filters.py b/web/plugins/visuals/filters.py
index 2514833..fccf0c3 100644
--- a/web/plugins/visuals/filters.py
+++ b/web/plugins/visuals/filters.py
@@ -1177,31 +1177,46 @@ class FilterStarred(FilterTristate):
declare_filter(501, FilterStarred("host"))
declare_filter(501, FilterStarred("service"))
-class FilterViewMultiselect(Filter):
- def __init__(self, name, title, options, info, varname):
- Filter.__init__(self, name, title,
- info, ["%s_var%d" % (name, idx) for idx, option in
enumerate(options)], [])
- self.__options = options
- self.__varname = varname
+class FilterDiscoveryState(Filter):
+ def __init__(self):
+ self.__options = [
+ ("discovery_state_ignored", _("Hidden")),
+ ("discovery_state_vanished", _("Vanished")),
+ ("discovery_state_unmonitored", _("New")),
+ ]
+ Filter.__init__(self, "discovery_state", _("Discovery
state"), "discovery_state",
+ [ o[0] for o in self.__options ], [])
+ self.__varname = "discovery_state"
+
def display(self):
html.begin_checkbox_group()
- for idx, option in enumerate(self.__options):
- html.checkbox("%s_var%d" % (self.name, idx), True,
label=option[1])
+ for varname, title in self.__options:
+ html.checkbox(varname, True, label=title)
html.end_checkbox_group()
+
+ def value(self):
+ val = {}
+ for varname in self.htmlvars:
+ value = html.get_checkbox(varname)
+ if value == None:
+ value = True # Default setting for filter: all checked!
+ val[varname] = value
+ return val
+
+
def filter(self, infoname):
- filters = []
- for idx, option in enumerate(self.__options):
- if html.get_checkbox("%s_var%d" % (self.name, idx)):
- filters.append("ViewFilter: %s = %s" % (self.__varname,
option[0]))
- if filters:
- return "\n".join(filters) + "\n"
- else:
- return ""
+ return ""
+
+
+ def filter_table(self, rows):
+ new_rows = []
+ filter_options = self.value()
+ for row in rows:
+ if filter_options["discovery_state_" +
row["discovery_state"]]:
+ new_rows.append(row)
+ return new_rows
+
-declare_filter(601, FilterViewMultiselect("discovery_state", _("Discovery
state"),
- [("ignored", "Hidden"),
- ("vanished", "Vanished"),
- ("unmonitored", "New")],
"long_plugin_output",
- "state"))
+declare_filter(601, FilterDiscoveryState())
diff --git a/web/plugins/visuals/infos.py b/web/plugins/visuals/infos.py
index c1c8fd6..3504805 100644
--- a/web/plugins/visuals/infos.py
+++ b/web/plugins/visuals/infos.py
@@ -132,16 +132,8 @@ infos['aggr_group'] = {
],
}
-# long_plugin_output can of course exist in every service, but the datasource
-# is (currently) limited to return only the output of the discovery service and
-# works per-host, not per-service
-infos['long_plugin_output'] = {
+infos['discovery'] = {
'title' : _('Discovery Output'),
'title_plural': _('Discovery Outputs'),
- 'single_spec' : [
- ('long_plugin_output', TextUnicode(
- title = _('Output'),
- )),
- ]
+ 'single_spec' : None,
}
-