Module: check_mk
Branch: master
Commit: c070cb27586ea9e644e5ef3c5576019e69ccea45
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c070cb27586ea9…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jun 14 09:31:08 2018 +0200
Consistently use dictionaries for contexts when loading checks/plugins.
The previous list/dict mix was simply confusing. In addition, it was even
less efficient.
Change-Id: If1130f31409f72c9186b083c8aeede3e87a23abf
---
cmk_base/check_api.py | 8 ++++++--
cmk_base/checks.py | 11 +++--------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index 6470c4b..c3f0caf 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -104,7 +104,7 @@ import cmk_base.prediction as _prediction
def _get_check_context():
"""This is called from cmk_base code to get the Check API things.
Don't
use this from checks."""
- return [ (k, v) for k, v in globals().items() if k[0] != "_" ]
+ return {k: v for k, v in globals().iteritems() if not k.startswith("_")}
#.
# .--Check API-----------------------------------------------------------.
@@ -499,4 +499,8 @@ def _agent_cache_file_age(hostname, check_plugin_name):
return None
-__all__ = dict(_get_check_context()).keys()
+# NOTE: Currently this is not really needed, it is just here to keep any start
+# import in sync with our intended API.
+# TODO: Do we really need this? Is there code which uses a star import for this
+# module?
+__all__ = _get_check_context().keys()
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index 2ab106d..ebdcd93 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -249,14 +249,9 @@ def new_check_context():
"active_check_info" : active_check_info,
"special_agent_info" : special_agent_info,
}
-
- # Add the Check API
- #
- # For better separation it would be better to copy the check API objects, but
- # this might consume too much memory. So we simply reference it.
- for k, v in check_api._get_check_context():
- context[k] = v
-
+ # NOTE: For better separation it would be better to copy the values, but
+ # this might consume too much memory, so we simply reference them.
+ context.update(check_api._get_check_context())
return context