Module: check_mk
Branch: master
Commit: 9c161578d42e67896d3228555820a3b110ac6f3c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9c161578d42e67…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Jan 23 15:41:56 2018 +0100
Fixed not existing inventory tree handling
Change-Id: I765bbc40a3aa2e55b4cf2024f2ff0c00ddca9406
---
web/htdocs/inventory.py | 8 +++++---
web/plugins/views/inventory.py | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/web/htdocs/inventory.py b/web/htdocs/inventory.py
index e2709f0..a42de0e 100644
--- a/web/htdocs/inventory.py
+++ b/web/htdocs/inventory.py
@@ -105,18 +105,18 @@ def sort_children(children):
def load_tree(hostname):
# Load data of a host, cache it in the current HTTP request
if not hostname:
- return {}
+ return None
inventory_tree_cache = html.get_cached("inventory")
if not inventory_tree_cache:
- inventory_tree_cache = {}
+ inventory_tree_cache = StructuredDataTree()
html.set_cache("inventory", inventory_tree_cache)
if hostname in inventory_tree_cache:
inventory_tree = inventory_tree_cache[hostname]
else:
if '/' in hostname:
- return StructuredDataTree() # just for security reasons
+ return None # just for security reasons
cache_path = "%s/inventory/%s" % (cmk.paths.var_dir, hostname)
inventory_tree = StructuredDataTree().load_from(cache_path)
inventory_tree_cache[hostname] = inventory_tree
@@ -238,6 +238,8 @@ def _inventory_of_host(host_name, request):
raise MKAuthException(_("Sorry, you are not allowed to access the host
%s.") % host_name)
inventory_tree = load_tree(host_name)
+ if not inventory_tree:
+ return {}
if "paths" in request:
parsed_paths = []
for path in request["paths"]:
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index 55f1a87..c05cafb 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -977,6 +977,8 @@ def _create_view_enabled_check_func(invpath):
if context["host"] == "":
return False
struct_tree = inventory.load_tree(context["host"])
+ if not struct_tree:
+ return False
if struct_tree.is_empty():
return False
parsed_path, unused_key = inventory.parse_tree_path(invpath)