Module: check_mk
Branch: master
Commit: 0b3ea32976e604bd2e45455b5d07acc0731ae7b5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0b3ea32976e604…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Feb 15 12:53:34 2019 +0100
7145 jolokia_info: Also discover if server is not responding
Every instance that is contacted has been explicitly configured by the user.
We can assume they want to monitor it, even if an error occurs at the time
of discovery.
Change-Id: I36b557bfe15ac1c13065652a6837f540091d418f
---
.werks/7145 | 13 ++++++
agents/plugins/mk_jolokia.py | 8 ++--
checks/jolokia_info | 37 ++++++++--------
.../datasets/jolokia_info_regression.py | 50 ++++++++++++++++++++++
4 files changed, 85 insertions(+), 23 deletions(-)
diff --git a/.werks/7145 b/.werks/7145
new file mode 100644
index 0000000..aee988e
--- /dev/null
+++ b/.werks/7145
@@ -0,0 +1,13 @@
+Title: jolokia_info: Also discover if server is not responding
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1550231470
+Class: feature
+
+Every instance that is contacted has been explicitly configured by the user.
+We can assume they want to monitor it, even if an error occurs at the time
+of discovery.
+
diff --git a/agents/plugins/mk_jolokia.py b/agents/plugins/mk_jolokia.py
index a8dc71b..df8ca52 100755
--- a/agents/plugins/mk_jolokia.py
+++ b/agents/plugins/mk_jolokia.py
@@ -37,8 +37,8 @@ try:
except ImportError as import_error:
sys.stdout.write(
"<<<jolokia_info>>>\n"
- "Error: mk_jolokia requires either the json or simplejson library.\n"
- "Please either use a Python version that contains the json library or
install the"
+ "Error: mk_jolokia requires either the json or simplejson library."
+ " Please either use a Python version that contains the json library or
install the"
" simplejson library on the monitored system.")
sys.exit(1)
@@ -47,8 +47,8 @@ try:
from requests.auth import HTTPDigestAuth
except ImportError as import_error:
sys.stdout.write("<<<jolokia_info>>>\n"
- "Error: mk_jolokia requires the requests library.\n"
- "Please install it on the monitored system.")
+ "Error: mk_jolokia requires the requests library."
+ " Please install it on the monitored system.")
sys.exit(1)
VERBOSE = '--verbose' in sys.argv
diff --git a/checks/jolokia_info b/checks/jolokia_info
index cfc37e5..93a696a 100644
--- a/checks/jolokia_info
+++ b/checks/jolokia_info
@@ -25,34 +25,33 @@
# Boston, MA 02110-1301 USA.
-def inventory_jolokia_info(info):
- return [(line[0], None) for line in info if line[1] != 'ERROR']
+def parse_jolokia_info(info):
+ parsed = {}
+ for line in info:
+ parsed.setdefault(line[0], []).append(line[1:])
+ return parsed
-def check_jolokia_info(item, _no_params, info):
+@get_parsed_item_data
+def check_jolokia_info(item, _no_params, data):
+ line = data[0]
# Inform user of non-working agent plugin, eg. missing json library
- if info[0][0] == "Error:":
- return 3, " ".join(info[0])
-
- for line in info:
- if line[0] == item:
- if line[1] == 'ERROR' or len(line) < 4:
- return (2, "Jolokia not running")
+ if item == "Error:":
+ return 3, ' '.join(line)
- if len(line) > 4:
- product = line[1]
- jolokia_version = line[-1]
- version = " ".join(line[2:-1])
- else:
- product, version, jolokia_version = line[1:]
- return (0, "%s %s (Jolokia version %s)" % (product.title(),
version, jolokia_version))
+ if line[0] == 'ERROR' or len(line) < 3:
+ return 2, ' '.join(line) or "Unknown error in plugin"
- return (3, "No data from agent, server might be down")
+ product = line[0]
+ jolokia_version = line[-1]
+ version = " ".join(line[1:-1])
+ return 0, "%s %s (Jolokia version %s)" % (product.title(), version,
jolokia_version)
check_info["jolokia_info"] = {
+ "parse_function": parse_jolokia_info,
"service_description": "JVM %s",
"check_function": check_jolokia_info,
- "inventory_function": inventory_jolokia_info,
+ "inventory_function": discover(),
}
diff --git a/tests/unit/checks/generictests/datasets/jolokia_info_regression.py
b/tests/unit/checks/generictests/datasets/jolokia_info_regression.py
new file mode 100644
index 0000000..613e375
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/jolokia_info_regression.py
@@ -0,0 +1,50 @@
+
+
+checkname = 'jolokia_info'
+
+
+info = [['Error:',
+ 'mk_jolokia',
+ 'requires',
+ 'either',
+ 'the',
+ 'json',
+ 'or',
+ 'simplejson',
+ 'library.',
+ 'Please',
+ 'either',
+ 'use',
+ 'a',
+ 'Python',
+ 'version',
+ 'that',
+ 'contains',
+ 'the',
+ 'json',
+ 'library',
+ 'or',
+ 'install',
+ 'the',
+ 'simplejson',
+ 'library',
+ 'on',
+ 'the',
+ 'monitored',
+ 'system.'],
+ ['INSTANCE1', 'ERROR', 'HTTP404 No response from server or
whatever'],
+ ['INSTANCE2', 'tomcat', '3.141592', '42.23']]
+
+
+discovery = {'': [('Error:', {}), ('INSTANCE1', {}),
('INSTANCE2', {})]}
+
+
+checks = {'': [('Error:',
+ {},
+ [(3,
+ 'mk_jolokia requires either the json or simplejson library. Please
either use a Python version that contains the json library or install the simplejson
library on the monitored system.',
+ [])]),
+ ('INSTANCE1',
+ {},
+ [(2, 'ERROR HTTP404 No response from server or whatever', [])]),
+ ('INSTANCE2', {}, [(0, 'Tomcat 3.141592 (Jolokia version
42.23)', [])])]}