Module: check_mk
Branch: master
Commit: c8076fb507d9af48b2105c3ca43cc2e946961ee8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c8076fb507d9af…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Mon Mar 25 13:07:56 2019 +0100
agent_kubernetes: make output for nodes and pods optional
CMK-1893
Change-Id: I91394ae75d2d2bd59886876677a858d8227a35db
---
checks/agent_kubernetes | 2 +
cmk/gui/plugins/wato/datasource_programs.py | 97 ++++++++++++++++++-----------
cmk/special_agents/agent_kubernetes.py | 12 +++-
3 files changed, 71 insertions(+), 40 deletions(-)
diff --git a/checks/agent_kubernetes b/checks/agent_kubernetes
index 9497ce1..1efc29f 100644
--- a/checks/agent_kubernetes
+++ b/checks/agent_kubernetes
@@ -28,6 +28,8 @@
def agent_kubernetes_arguments(params, _hostname, ipaddress):
args = ['--token', passwordstore_get_cmdline("%s",
params["token"])]
+ args += ['--infos', ','.join(params.get('infos',
['nodes']))]
+
if "port" in params:
args += ["--port", str(params["port"])]
diff --git a/cmk/gui/plugins/wato/datasource_programs.py
b/cmk/gui/plugins/wato/datasource_programs.py
index 5dc5ae0..b4c8290 100644
--- a/cmk/gui/plugins/wato/datasource_programs.py
+++ b/cmk/gui/plugins/wato/datasource_programs.py
@@ -139,46 +139,67 @@ class RulespecSpecialAgentsKubernetes(HostRulespec):
@property
def valuespec(self):
- return Dictionary(
- elements=[
- ("token", IndividualOrStoredPassword(
- title=_("Token"),
- allow_empty=False,
- )),
- ("port",
- Integer(
- title=_(u"Port"),
- help=_("If no port is given a default value of 443 will be
used."),
- default_value=443)),
- ("url-prefix",
- HTTPUrl(
- title=_("Custom URL prefix"),
- help=_("Defines the scheme (either HTTP or HTTPS) and host part
"
- "of Kubernetes API calls like e.g.
\"https://example.com\". "
- "If no prefix is specified HTTPS together with the IP of
"
- "the host will be used."),
- allow_empty=False)),
- ("path-prefix",
- TextAscii(
- title=_("Custom path prefix"),
- help=_(
- "Specifies a URL path prefix which is prepended to the path
in calls "
- "to the Kubernetes API. This is e.g. useful if Rancher is
used to "
- "manage Kubernetes clusters. If no prefix is given
\"/\" will be used."),
- allow_empty=False)),
- ("no-cert-check",
- Alternative(
- title=_("Disable certificate verification"),
- elements=[
- FixedValue(False, title=_("Deactivated"),
totext=""),
- FixedValue(True, title=_("Activated"),
totext=""),
- ],
- default_value=False)),
- ],
- optional_keys=["port", "url-prefix",
"path-prefix", "no-cert-check"],
- title=_(u"Kubernetes"),
+ return Transform(
+ Dictionary(
+ elements=[
+ ("token", IndividualOrStoredPassword(
+ title=_("Token"),
+ allow_empty=False,
+ )),
+ ("infos",
+ ListChoice(
+ choices=[
+ ("nodes", _("Nodes")),
+ ("pods", _("Pods")),
+ ],
+ default_value=[
+ "nodes",
+ ],
+ allow_empty=False,
+ title=_("Retrieve information about..."))),
+ ("port",
+ Integer(
+ title=_(u"Port"),
+ help=_("If no port is given a default value of 443 will be
used."),
+ default_value=443)),
+ ("url-prefix",
+ HTTPUrl(
+ title=_("Custom URL prefix"),
+ help=_("Defines the scheme (either HTTP or HTTPS) and host
part "
+ "of Kubernetes API calls like e.g.
\"https://example.com\". "
+ "If no prefix is specified HTTPS together with the
IP of "
+ "the host will be used."),
+ allow_empty=False)),
+ ("path-prefix",
+ TextAscii(
+ title=_("Custom path prefix"),
+ help=_(
+ "Specifies a URL path prefix which is prepended to the
path in calls "
+ "to the Kubernetes API. This is e.g. useful if Rancher
is used to "
+ "manage Kubernetes clusters. If no prefix is given
\"/\" will be used."
+ ),
+ allow_empty=False)),
+ ("no-cert-check",
+ Alternative(
+ title=_("Disable certificate verification"),
+ elements=[
+ FixedValue(False, title=_("Deactivated"),
totext=""),
+ FixedValue(True, title=_("Activated"),
totext=""),
+ ],
+ default_value=False)),
+ ],
+ optional_keys=["port", "url-prefix",
"path-prefix", "no-cert-check"],
+ title=_(u"Kubernetes"),
+ ),
+ forth=self._transform_infos,
)
+ def _transform_infos(self, value):
+ if 'infos' in value:
+ return value
+ value['infos'] = ['nodes']
+ return value
+
@rulespec_registry.register
class RulespecSpecialAgentsVsphere(HostRulespec):
diff --git a/cmk/special_agents/agent_kubernetes.py
b/cmk/special_agents/agent_kubernetes.py
index f150c8e..ac250ac 100644
--- a/cmk/special_agents/agent_kubernetes.py
+++ b/cmk/special_agents/agent_kubernetes.py
@@ -76,6 +76,12 @@ 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(
+ '--infos',
+ type=lambda x: x.split(','),
+ required=True,
+ help='Comma separated list of items that should be fetched',
+ )
p.add_argument('--url-prefix', help='Custom URL prefix for Kubernetes API
calls')
p.add_argument(
'--path-prefix',
@@ -853,9 +859,11 @@ def main(args=None):
api_client = get_api_client(arguments)
api_data = ApiData(api_client)
print(api_data.cluster_sections())
- print(api_data.node_sections())
print(api_data.custom_metrics_section())
- print(api_data.pod_sections())
+ if 'nodes' in arguments.infos:
+ print(api_data.node_sections())
+ if 'pods' in arguments.infos:
+ print(api_data.pod_sections())
except Exception as e:
if arguments.debug:
raise