Module: check_mk
Branch: master
Commit: 460ebc0534e90d92704936a88b9e38c467f6fba7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=460ebc0534e90d…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Mar 29 09:59:58 2019 +0100
k8s_selector: inventory plugin to show selectors
Change-Id: Iab0a82f7277fd1125e3a6c356557e99ccce8158e
---
cmk/gui/plugins/views/inventory.py | 3 +++
cmk/special_agents/agent_kubernetes.py | 5 ++++-
inventory/k8s_selector | 41 ++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/cmk/gui/plugins/views/inventory.py b/cmk/gui/plugins/views/inventory.py
index 8aa0629..100ed0d 100644
--- a/cmk/gui/plugins/views/inventory.py
+++ b/cmk/gui/plugins/views/inventory.py
@@ -1121,6 +1121,9 @@ inventory_displayhints.update({
".software.applications.kubernetes.service_info.type": {"title":
_("Type")},
".software.applications.kubernetes.service_info.cluster_ip":
{"title": _("Cluster IP")},
".software.applications.kubernetes.service_info.load_balancer_ip":
{"title": _("Load Balancer IP")},
+ ".software.applications.kubernetes.selector.": {
+ "title": _("Selectors"),
+ },
".software.applications.citrix.": {"title":
_("Citrix")},
".software.applications.citrix.controller.": {"title":
_("Controller")},
".software.applications.citrix.controller.controller_version": {
diff --git a/cmk/special_agents/agent_kubernetes.py
b/cmk/special_agents/agent_kubernetes.py
index aa93b47..122f601 100644
--- a/cmk/special_agents/agent_kubernetes.py
+++ b/cmk/special_agents/agent_kubernetes.py
@@ -290,7 +290,6 @@ class Service(Metadata):
def info(self):
return {
'type': self._type,
- 'selector': self._selector,
'cluster_ip': self._cluster_ip,
'load_balancer_ip': self._load_balancer_ip,
}
@@ -608,6 +607,9 @@ class ServiceList(K8sList[Service]):
def infos(self):
return {service.name: service.info for service in self}
+ def selector(self):
+ return {service.name: service.selector for service in self}
+
def ports(self):
return {service.name: service.ports for service in self}
@@ -1002,6 +1004,7 @@ class ApiData(object):
logging.info('Output service sections')
g = Group()
g.join('labels', self.services.labels())
+ g.join('k8s_selector', self.services.selector())
g.join('k8s_service_info', self.services.infos())
g.join('k8s_service_ports', self.services.ports())
return '\n'.join(g.output(piggyback_prefix="service_"))
diff --git a/inventory/k8s_selector b/inventory/k8s_selector
new file mode 100644
index 0000000..76e219f
--- /dev/null
+++ b/inventory/k8s_selector
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2019 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+
+def inv_k8s_selector(info, inventory_tree):
+ parsed = parse_k8s(info)
+
+ path = "software.applications.kubernetes.selector."
+ inv_node = inventory_tree.get_dict(path)
+
+ for key, value in sorted(parsed.iteritems()):
+ inv_node[key] = value
+
+
+inv_info['k8s_selector'] = {
+ 'inv_function': inv_k8s_selector,
+ 'includes': ['k8s.include'],
+}