Module: check_mk
Branch: master
Commit: 95067fbc512018595dfba6b1d812464949e90aac
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=95067fbc512018…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Mar 29 14:18:19 2019 +0100
k8s_assigned_pods: show pods of services in the HW/SW inventory
Change-Id: I873a5127afb7f5228b43d8b098de7a772bb582f1
---
cmk/gui/plugins/views/inventory.py | 4 ++++
cmk/special_agents/agent_kubernetes.py | 6 +++++
inventory/k8s_assigned_pods | 42 ++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/cmk/gui/plugins/views/inventory.py b/cmk/gui/plugins/views/inventory.py
index 100ed0d..4165f92 100644
--- a/cmk/gui/plugins/views/inventory.py
+++ b/cmk/gui/plugins/views/inventory.py
@@ -1124,6 +1124,10 @@ inventory_displayhints.update({
".software.applications.kubernetes.selector.": {
"title": _("Selectors"),
},
+ ".software.applications.kubernetes.assigned_pods:": {
+ "title": _("Pods"),
+ },
+ ".software.applications.kubernetes.assigned_pods:*.name":
{"title": _("Name")},
".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 01b995b..036c08d 100644
--- a/cmk/special_agents/agent_kubernetes.py
+++ b/cmk/special_agents/agent_kubernetes.py
@@ -1033,6 +1033,12 @@ class ApiData(object):
g.join('k8s_selector', self.services.selector())
g.join('k8s_service_info', self.services.infos())
g.join('k8s_service_ports', self.services.ports())
+ pod_names = {
+ service_name: {
+ 'names': [pod.name for pod in pods]
+ } for service_name, pods in
self.pods.group_by(self.services.selector()).iteritems()
+ }
+ g.join('k8s_assigned_pods', pod_names)
return '\n'.join(g.output(piggyback_prefix="service_"))
def deployment_sections(self):
diff --git a/inventory/k8s_assigned_pods b/inventory/k8s_assigned_pods
new file mode 100644
index 0000000..3d9cdc0
--- /dev/null
+++ b/inventory/k8s_assigned_pods
@@ -0,0 +1,42 @@
+#!/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_assigned_pods(info, _inventory_tree, status_data_tree):
+ parsed = parse_k8s(info)
+ path = "software.applications.kubernetes.assigned_pods:"
+ status_node = status_data_tree.get_list(path)
+
+ for pod_name in sorted(parsed['names']):
+ status_node.append({
+ 'name': pod_name,
+ })
+
+
+inv_info['k8s_assigned_pods'] = {
+ 'inv_function': inv_k8s_assigned_pods,
+ 'includes': ['k8s.include'],
+}
\ No newline at end of file