Module: check_mk
Branch: master
Commit: ceb097ce4c5f585e9e620fae89eba79681f6b78e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ceb097ce4c5f58…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Mon Mar 25 15:58:56 2019 +0100
k8s_pod_info: show information about a pod in the HW/SW inventory
CMK-1893
Change-Id: Ibcd38353be9edce9471750bbd077d9f48a2bd18f
---
cmk/gui/plugins/views/inventory.py | 9 +++++++
cmk/special_agents/agent_kubernetes.py | 25 +++++++++++++++++++
inventory/k8s_pod_info | 45 ++++++++++++++++++++++++++++++++++
3 files changed, 79 insertions(+)
diff --git a/cmk/gui/plugins/views/inventory.py b/cmk/gui/plugins/views/inventory.py
index d9e337f..5bd54e9 100644
--- a/cmk/gui/plugins/views/inventory.py
+++ b/cmk/gui/plugins/views/inventory.py
@@ -1106,6 +1106,15 @@ inventory_displayhints.update({
".software.applications.kubernetes.pod_container:*.ready":
{"title": _("Ready"), "paint":
"container_ready"},
".software.applications.kubernetes.pod_container:*.restart_count":
{"title": _("Restart count")},
".software.applications.kubernetes.pod_container:*.container_id":
{"title": _("Container ID")},
+ ".software.applications.kubernetes.pod_info.": {
+ "title": _("Pod"),
+ },
+ ".software.applications.kubernetes.pod_info.node": {"title":
_("Node")},
+ ".software.applications.kubernetes.pod_info.host_network":
{"title": _("Host network")},
+ ".software.applications.kubernetes.pod_info.dns_policy":
{"title": _("DNS policy")},
+ ".software.applications.kubernetes.pod_info.host_ip": {"title":
_("Host IP")},
+ ".software.applications.kubernetes.pod_info.pod_ip": {"title":
_("Pod IP")},
+ ".software.applications.kubernetes.pod_info.qos_class": {"title":
_("QOS class")},
".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 20eb247..e23b4f5 100644
--- a/cmk/special_agents/agent_kubernetes.py
+++ b/cmk/special_agents/agent_kubernetes.py
@@ -256,16 +256,26 @@ class Pod(Metadata):
spec = pod.spec
if spec:
self.node = spec.node_name
+ self.host_network = (spec.host_network if spec.host_network is not None else
False)
+ self.dns_policy = spec.dns_policy
self._containers = spec.containers
else:
self.node = None
+ self.host_network = False
+ self.dns_policy = None
self._containers = []
status = pod.status
if status:
+ self.host_ip = status.host_ip
+ self.pod_ip = status.pod_ip
+ self.qos_class = status.qos_class
self._container_statuses = (status.container_statuses
if status.container_statuses else [])
else:
+ self.host_ip = None
+ self.pod_ip = None
+ self.qos_class = None
self._container_statuses = []
@staticmethod
@@ -322,6 +332,17 @@ class Pod(Metadata):
data['image_id'] = container_status.image_id
return view
+ @property
+ def info(self):
+ return {
+ 'node': self.node,
+ 'host_network': self.host_network,
+ 'dns_policy': self.dns_policy,
+ 'host_ip': self.host_ip,
+ 'pod_ip': self.pod_ip,
+ 'qos_class': self.qos_class,
+ }
+
class Namespace(Metadata):
# TODO: namespaces may have resource quotas and limits
@@ -484,6 +505,9 @@ class PodList(ListLike[Pod]):
def pods_in_cluster(self):
return {'requests': {'pods': len(self)}}
+ def info(self):
+ return {pod.name: pod.info for pod in self}
+
def resources(self):
return {pod.name: pod.resources for pod in self}
@@ -825,6 +849,7 @@ class ApiData(object):
g = Group()
g.join('k8s_resources', self.pods.resources())
g.join('k8s_pod_container', self.pods.containers())
+ g.join('k8s_pod_info', self.pods.info())
return '\n'.join(g.output())
diff --git a/inventory/k8s_pod_info b/inventory/k8s_pod_info
new file mode 100644
index 0000000..f2818c2
--- /dev/null
+++ b/inventory/k8s_pod_info
@@ -0,0 +1,45 @@
+#!/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_pod_info(info, inventory_tree, status_data_tree):
+ parsed = parse_k8s(info)
+
+ path = "software.applications.kubernetes.pod_info."
+ inv_node = inventory_tree.get_dict(path)
+ status_node = status_data_tree.get_dict(path)
+
+ for key, value in sorted(parsed.iteritems()):
+ if key in {'node', 'host_network', 'dns_policy'}:
+ inv_node[key] = value
+ else:
+ status_node[key] = value
+
+
+inv_info['k8s_pod_info'] = {
+ 'inv_function': inv_k8s_pod_info,
+ 'includes': ['k8s.include'],
+}