Module: check_mk
Branch: master
Commit: 20805253fd8475692f9358e5a9788badb20fe3f4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=20805253fd8475…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 9 16:23:42 2019 +0200
7336 labels: New inventory script to discover generic host labels
A new HW/SW inventory script has been added that works on a generic
"<<<labels>>>" section.
It is used to discover host labels from this section.
The first agent that produces this section is the Kubernetes special agent. It creates
the
label sections for all kind of objects that are monitored by Check_MK. This makes
Check_MK
automatically import the labels configured in Kubernetes. You can now use them to filter
your views, dashboards and in the future also create rules in WATO based on them.
Change-Id: Ifb6b7179a02ff5d400e24f28d8e12cbd132c58c3
---
.werks/7336 | 16 ++++++++++++++++
inventory/labels | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/.werks/7336 b/.werks/7336
new file mode 100644
index 0000000..1c2c562
--- /dev/null
+++ b/.werks/7336
@@ -0,0 +1,16 @@
+Title: labels: New inventory script to discover generic host labels
+Level: 2
+Component: inv
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1554819594
+Class: feature
+
+A new HW/SW inventory script has been added that works on a generic
"<<<labels>>>" section.
+It is used to discover host labels from this section.
+
+The first agent that produces this section is the Kubernetes special agent. It creates
the
+label sections for all kind of objects that are monitored by Check_MK. This makes
Check_MK
+automatically import the labels configured in Kubernetes. You can now use them to filter
+your views, dashboards and in the future also create rules in WATO based on them.
diff --git a/inventory/labels b/inventory/labels
new file mode 100644
index 0000000..1a0c5e1
--- /dev/null
+++ b/inventory/labels
@@ -0,0 +1,45 @@
+#!/usr/bin/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.
+
+# Example outputs:
+# <<<labels:sep(0)>>>
+# {"tier": "control-plane", "component":
"kube-scheduler"}
+
+import json
+
+
+def inv_labels(info, discovered_host_labels):
+ for key, value in _parse_labels(info).items():
+ discovered_host_labels.add_label(key, value, plugin_name="labels")
+
+
+def _parse_labels(info):
+ return json.loads(info[0][0])
+
+
+inv_info['labels'] = {
+ "inv_function": inv_labels,
+}