Module: check_mk
Branch: master
Commit: aff06f54d44f73bc1b5775067c635c010d7605ca
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aff06f54d44f73…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue May 23 13:28:45 2017 +0200
4746 FIX Fixed using HW/SW inventory filters in views without inventory painters
When adding a HW/SW inventory related filter to a view without adding a sorter
or painter, this resulted in a KeyError exception.
Change-Id: I69e6666b22fa16744e1e3884bc77261eb0e80c6e
---
.werks/4746 | 12 ++++++++++++
web/htdocs/views.py | 20 ++++++++------------
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/.werks/4746 b/.werks/4746
new file mode 100644
index 0000000..8853a05
--- /dev/null
+++ b/.werks/4746
@@ -0,0 +1,12 @@
+Title: Fixed using HW/SW inventory filters in views without inventory painters
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1495538857
+
+When adding a HW/SW inventory related filter to a view without adding a sorter
+or painter, this resulted in a KeyError exception.
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 3ae10c5..0bcf0a8 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1508,10 +1508,6 @@ def show_view(view, show_heading = False, show_buttons = True,
# Check that all needed information for configured single contexts are available
visuals.verify_single_contexts('views', view,
datasource.get('link_filters', {}))
- # Af any painter, sorter or filter needs the information about the host's
- # inventory, then we load it and attach it as column "host_inventory"
- need_inventory_data = False
-
# Prepare Filter headers for Livestatus
# TODO: When this is used by the reporting then *all* filters are
# active. That way the inventory data will always be loaded. When
@@ -1522,8 +1518,6 @@ def show_view(view, show_heading = False, show_buttons = True,
for filt in all_active_filters:
header = filt.filter(tablename)
filterheaders += header
- if filt.need_inventory():
- need_inventory_data = True
# Apply the site hint / filter
if html.var("site"):
@@ -1578,9 +1572,6 @@ def show_view(view, show_heading = False, show_buttons = True,
columns = get_needed_regular_columns(group_cells + cells, sorters, datasource)
join_columns = get_needed_join_columns(join_cells, sorters, datasource)
- # Inventory data needed to render the view?
- need_inventory_data = is_inventory_data_needed(group_cells, cells, sorters)
-
# Fetch data. Some views show data only after pressing [Search]
if (only_count or (not view.get("mustsearch")) or
html.var("filled_in") in ["filter", 'actions',
'confirm', 'painteroptions']):
# names for additional columns (through Stats: headers)
@@ -1604,8 +1595,9 @@ def show_view(view, show_heading = False, show_buttons = True,
if join_cells:
do_table_join(datasource, rows, filterheaders, join_cells, join_columns,
only_sites)
- # Add inventory data if one of the painters or filters needs it
- if need_inventory_data:
+ # If any painter, sorter or filter needs the information about the host's
+ # inventory, then we load it and attach it as column "host_inventory"
+ if is_inventory_data_needed(group_cells, cells, sorters, all_active_filters):
for row in rows:
if "host_name" in row:
row["host_inventory"] =
inventory.host(row["host_name"])
@@ -1737,7 +1729,7 @@ def get_needed_join_columns(join_cells, sorters, datasource):
return list(join_columns)
-def is_inventory_data_needed(group_cells, cells, sorters):
+def is_inventory_data_needed(group_cells, cells, sorters, all_active_filters):
for cell in cells:
if cell.has_tooltip():
if cell.tooltip_painter_name().startswith("inv_"):
@@ -1751,6 +1743,10 @@ def is_inventory_data_needed(group_cells, cells, sorters):
if cell.painter().get("load_inv"):
return True
+ for filt in all_active_filters:
+ if filt.need_inventory():
+ return True
+
return False