Module: check_mk
Branch: master
Commit: 6036c73df07859214bbd4595e079b56b06812269
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6036c73df07859…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Jan 23 14:42:24 2019 +0100
mk_jolokia: input validation to fail early
Change-Id: I1fc0e73d3d0145cadc06792297ccf6ea82f64ca1
---
agents/plugins/mk_jolokia.py | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/agents/plugins/mk_jolokia.py b/agents/plugins/mk_jolokia.py
index f3c4156..e2a2524 100755
--- a/agents/plugins/mk_jolokia.py
+++ b/agents/plugins/mk_jolokia.py
@@ -190,10 +190,33 @@ def cached(function):
def sanitize_config(config):
- if not config["instance"]:
+ instance = config.get("instance")
+ err_msg = "%s in configuration"
+ if instance:
+ err_msg += " for %s" % instance
+
+ required_keys = {"protocol", "server", "port",
"suburi"}
+ auth_mode = config.get("mode")
+ if auth_mode in ("digest", "basic",
"basic_preemtive"):
+ required_keys |= {"user", "password"}
+ elif auth_mode == "https":
+ required_keys |= {"client_cert", "client_key"}
+ if config.get("service_url") is not None and
config.get("service_user") is not None:
+ required_keys.add("service_password")
+ missing_keys = required_keys - set(config.keys())
+ if missing_keys:
+ raise ValueError(err_msg % ("Missing keys " % ",
".join(missing_keys)))
+
+ if not instance:
config["instance"] = str(config["port"])
config["instance"] = config["instance"].replace(" ",
"_")
+ # port must be (or look like) an integer
+ try:
+ config["port"] = int(config["port"])
+ except ValueError:
+ raise ValueError(err_msg % ("Invalid port %r" %
config["port"]))
+
if config.get("server") == "use fqdn":
config["server"] = socket.getfqdn()