Module: check_mk
Branch: master
Commit: 7f81c5f81492a9b74536d902f2e04614e7cbdf1e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7f81c5f81492a9…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Tue Jan 8 10:13:49 2019 +0100
agent_kubernetes: add option to specify a custom URL prefix
CMK-1478
Change-Id: I900735df01f3ab45d5cf685019cded6be6c0d1e3
---
agents/special/agent_kubernetes | 6 +++++-
checks/agent_kubernetes | 5 ++++-
cmk/gui/plugins/wato/datasource_programs.py | 3 ++-
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/agents/special/agent_kubernetes b/agents/special/agent_kubernetes
index 49e3600..a974f9b 100755
--- a/agents/special/agent_kubernetes
+++ b/agents/special/agent_kubernetes
@@ -66,6 +66,7 @@ def parse(args):
p.add_argument('host', metavar='HOST', help='Kubernetes host to
connect to')
p.add_argument('--port', type=int, default=443, help='Port to connect
to')
p.add_argument('--token', required=True, help='Token for that user')
+ p.add_argument('--url-prefix', help='Custom URL prefix for Kubernetes API
calls')
p.add_argument('--no-cert-check', action='store_true',
help='Disable certificate verification')
p.add_argument(
'--profile',
@@ -648,7 +649,10 @@ def get_api_client(arguments):
logging.info('Constructing API client')
config = client.Configuration()
- config.host = 'https://%s:%s' % (arguments.host, arguments.port)
+ if arguments.url_prefix:
+ config.host = '%s:%s' % (arguments.url_prefix, arguments.port)
+ else:
+ config.host = 'https://%s:%s' % (arguments.host, arguments.port)
config.api_key_prefix['authorization'] = 'Bearer'
config.api_key['authorization'] = arguments.token
diff --git a/checks/agent_kubernetes b/checks/agent_kubernetes
index 6fedf8c..a439ed4 100644
--- a/checks/agent_kubernetes
+++ b/checks/agent_kubernetes
@@ -31,9 +31,12 @@ def agent_kubernetes_arguments(params, _hostname, ipaddress):
if "port" in params:
args += ["--port", str(params["port"])]
- if params.get("no-cert-check"):
+ if "no-cert-check" in params:
args += ["--no-cert-check"]
+ if "url-prefix" in params:
+ args += ["--url-prefix", params["url-prefix"]]
+
args += [ipaddress]
return args
diff --git a/cmk/gui/plugins/wato/datasource_programs.py
b/cmk/gui/plugins/wato/datasource_programs.py
index da8d74e..b0f8e4c 100644
--- a/cmk/gui/plugins/wato/datasource_programs.py
+++ b/cmk/gui/plugins/wato/datasource_programs.py
@@ -116,6 +116,7 @@ register_rule(
allow_empty=False,
)),
("port", Integer(title=_(u"Port"), default_value=443)),
+ ("url-prefix", HTTPUrl(title=_("Custom URL prefix"),
allow_empty=False)),
("no-cert-check",
Alternative(
title=_("Disable certificate verification"),
@@ -125,7 +126,7 @@ register_rule(
],
default_value=False)),
],
- optional_keys=["port", "no-cert-check"],
+ optional_keys=["port", "url-prefix",
"no-cert-check"],
),
match="first",
title=_(u"Kubernetes"),