Module: check_mk
Branch: master
Commit: 6f48926edbb8eae9a746f8727cf9d9cf2236cad7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6f48926edbb8ea…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Feb 15 07:41:49 2019 +0100
docker deprecation: quick fix
Change-Id: Idc68724e5e669759f4a2709319727cbab23418ce
---
checks/docker_container_status | 36 ++++++++++++++++++++++++++++++++++++
checks/docker_node_disk_usage | 36 ++++++++++++++++++++++++++++++++++++
checks/docker_node_info | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 108 insertions(+)
diff --git a/checks/docker_container_status b/checks/docker_container_status
index 69649fa..13e7b3a 100644
--- a/checks/docker_container_status
+++ b/checks/docker_container_status
@@ -25,6 +25,42 @@
# Boston, MA 02110-1301 USA.
+# TODO: see why it's not enough to have it in legacy_docker.include
+def append_deprecation_warning(check_function):
+ '''A wrapper to WARN if legacy code is used
+
+ If the parse result is of one of the legacy Types the decorated
+ check function will yield an additional WARNING state.
+
+ These legacy parse results correspond to agents/plugins from version
+ 1.5.0b1 to 1.5.0p12
+ '''
+
+ @functools.wraps(check_function)
+ def wrapper(item, params, parsed):
+
+ is_deprecated = isinstance(parsed, (DeprecatedDict, DeprecatedList))
+ catch_these = Exception if is_deprecated else ()
+
+ try:
+ results = check_function(item, params, parsed)
+ if isinstance(results, tuple):
+ yield results
+ else:
+ for result in results:
+ yield result
+ except catch_these:
+ yield 3, "Could not handle data"
+ finally:
+ if is_deprecated:
+ yield 1, ("Deprecated plugin/agent (see long output)(!)\n"
+ "You are using legacy code, which may lead to crashes
and/or"
+ " incomplete information. Please upgrade the monitored
host to"
+ " use the plugin 'mk_docker.py'.")
+
+ return wrapper
+
+
def parse_docker_container_status(info):
'''process the first line to a JSON object
diff --git a/checks/docker_node_disk_usage b/checks/docker_node_disk_usage
index d5355e2..a4be887 100644
--- a/checks/docker_node_disk_usage
+++ b/checks/docker_node_disk_usage
@@ -25,6 +25,42 @@
# Boston, MA 02110-1301 USA.
+# TODO: see why it's not enough to have it in legacy_docker.include
+def append_deprecation_warning(check_function):
+ '''A wrapper to WARN if legacy code is used
+
+ If the parse result is of one of the legacy Types the decorated
+ check function will yield an additional WARNING state.
+
+ These legacy parse results correspond to agents/plugins from version
+ 1.5.0b1 to 1.5.0p12
+ '''
+
+ @functools.wraps(check_function)
+ def wrapper(item, params, parsed):
+
+ is_deprecated = isinstance(parsed, (DeprecatedDict, DeprecatedList))
+ catch_these = Exception if is_deprecated else ()
+
+ try:
+ results = check_function(item, params, parsed)
+ if isinstance(results, tuple):
+ yield results
+ else:
+ for result in results:
+ yield result
+ except catch_these:
+ yield 3, "Could not handle data"
+ finally:
+ if is_deprecated:
+ yield 1, ("Deprecated plugin/agent (see long output)(!)\n"
+ "You are using legacy code, which may lead to crashes
and/or"
+ " incomplete information. Please upgrade the monitored
host to"
+ " use the plugin 'mk_docker.py'.")
+
+ return wrapper
+
+
def parse_docker_node_disk_usage(info):
version = docker_get_version(info) # pylint: disable=undefined-variable
diff --git a/checks/docker_node_info b/checks/docker_node_info
index 3d193d1..f560f9e 100644
--- a/checks/docker_node_info
+++ b/checks/docker_node_info
@@ -25,6 +25,42 @@
# Boston, MA 02110-1301 USA.
+# TODO: see why it's not enough to have it in legacy_docker.include
+def append_deprecation_warning(check_function):
+ '''A wrapper to WARN if legacy code is used
+
+ If the parse result is of one of the legacy Types the decorated
+ check function will yield an additional WARNING state.
+
+ These legacy parse results correspond to agents/plugins from version
+ 1.5.0b1 to 1.5.0p12
+ '''
+
+ @functools.wraps(check_function)
+ def wrapper(item, params, parsed):
+
+ is_deprecated = isinstance(parsed, (DeprecatedDict, DeprecatedList))
+ catch_these = Exception if is_deprecated else ()
+
+ try:
+ results = check_function(item, params, parsed)
+ if isinstance(results, tuple):
+ yield results
+ else:
+ for result in results:
+ yield result
+ except catch_these:
+ yield 3, "Could not handle data"
+ finally:
+ if is_deprecated:
+ yield 1, ("Deprecated plugin/agent (see long output)(!)\n"
+ "You are using legacy code, which may lead to crashes
and/or"
+ " incomplete information. Please upgrade the monitored
host to"
+ " use the plugin 'mk_docker.py'.")
+
+ return wrapper
+
+
def parse_docker_node_info(info):
version = docker_get_version(info) # pylint: disable=undefined-variable