Module: check_mk
Branch: master
Commit: 254dd6086a1f56fe3e77fe4ac4399e1a70cc6b34
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=254dd6086a1f56…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jun 14 09:49:38 2018 +0200
Cleaned up and simplified include path calculation.
Change-Id: I7fdb3aaf66465aa87eda9f0d75f1b61048532da2
---
cmk_base/checks.py | 7 ++-----
cmk_base/inventory_plugins.py | 28 +++++++++++++---------------
2 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index ebdcd93..e5beb95 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -275,13 +275,10 @@ def load_check_includes(check_file_path, check_context):
def check_include_file_path(include_file_name):
- include_file_path = os.path.join(cmk.paths.checks_dir, include_file_name)
-
local_path = os.path.join(cmk.paths.local_checks_dir, include_file_name)
if os.path.exists(local_path):
- include_file_path = local_path
-
- return include_file_path
+ return local_path
+ return os.path.join(cmk.paths.checks_dir, include_file_name)
def cached_includes_of_plugin(check_file_path):
diff --git a/cmk_base/inventory_plugins.py b/cmk_base/inventory_plugins.py
index 2b87058..8f4614b 100644
--- a/cmk_base/inventory_plugins.py
+++ b/cmk_base/inventory_plugins.py
@@ -99,27 +99,25 @@ def _new_inv_context(get_inventory_context):
# Working with imports when specifying the includes would be much cleaner,
# sure. But we need to deal with the current check API.
def _load_plugin_includes(check_file_path, plugin_context):
- for include_file_name in checks.includes_of_plugin(check_file_path):
- include_file_path = os.path.join(cmk.paths.inventory_dir, include_file_name)
-
- local_path = os.path.join(cmk.paths.local_inventory_dir, include_file_name)
- if os.path.exists(local_path):
- include_file_path = local_path
-
- # inventory plugins may also use check includes. Try to find one.
- if not os.path.exists(include_file_path):
- include_file_path = checks.check_include_file_path(include_file_name)
-
+ for name in checks.includes_of_plugin(check_file_path):
+ path = _include_file_path(name)
try:
- execfile(include_file_path, plugin_context)
+ execfile(path, plugin_context)
except Exception, e:
- console.error("Error in include file %s: %s\n", include_file_path,
e)
+ console.error("Error in include file %s: %s\n", path, e)
if cmk.debug.enabled():
raise
- else:
- continue
+def _include_file_path(name):
+ local_path = os.path.join(cmk.paths.local_inventory_dir, name)
+ if os.path.exists(local_path):
+ return local_path
+ shared_path = os.path.join(cmk.paths.inventory_dir, name)
+ if os.path.exists(shared_path):
+ return shared_path
+ return checks.check_include_file_path(name)
+
def is_snmp_plugin(plugin_type):
section_name = cmk_base.check_utils.section_name_of(plugin_type)