Module: check_mk
Branch: master
Commit: b7f97f5bc85fc41dad70c73b054afbdd2a24bc8f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b7f97f5bc85fc4…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Dec 5 16:21:24 2018 +0100
k8s.include: Add common parse_function
CMK-511
Change-Id: I3c9ce96070fa9c00804939466ce9d7e16c336e59
---
checks/k8s.include | 30 ++++++++++++++++++++++++++++++
checks/k8s_component_statuses | 8 ++------
checks/k8s_conditions | 8 ++------
checks/k8s_namespaces | 8 ++------
checks/k8s_nodes | 8 ++------
checks/k8s_persistent_volume_claims | 8 ++------
checks/k8s_persistent_volumes | 8 ++------
checks/k8s_resources | 8 ++------
checks/k8s_roles | 8 ++------
checks/k8s_storage_classes | 8 ++------
10 files changed, 48 insertions(+), 54 deletions(-)
diff --git a/checks/k8s.include b/checks/k8s.include
new file mode 100644
index 0000000..1f76a9b
--- /dev/null
+++ b/checks/k8s.include
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2018 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 parse_k8s(info):
+ import json
+ return json.loads(info[0][0])
diff --git a/checks/k8s_component_statuses b/checks/k8s_component_statuses
index f441feb..99f754c 100644
--- a/checks/k8s_component_statuses
+++ b/checks/k8s_component_statuses
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_component_statuses(info):
- import json
- return json.loads(info[0][0])
-
-
@get_parsed_item_data
def check_k8s_component_statuses(item, _no_params, conditions):
for condition in conditions:
@@ -42,8 +37,9 @@ def check_k8s_component_statuses(item, _no_params, conditions):
check_info['k8s_component_statuses'] = {
- 'parse_function': parse_k8s_component_statuses,
+ 'parse_function': parse_k8s,
'inventory_function': discover(),
'check_function': check_k8s_component_statuses,
'service_description': 'Component %s',
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_conditions b/checks/k8s_conditions
index fb6007b..6306dd1 100644
--- a/checks/k8s_conditions
+++ b/checks/k8s_conditions
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_conditions(info):
- import json
- return json.loads(info[0][0])
-
-
@discover
def inventory_k8s_conditions(condition, _value):
return condition in {
@@ -57,8 +52,9 @@ def check_k8s_conditions(item, _no_params, value):
check_info['k8s_conditions'] = {
- 'parse_function': parse_k8s_conditions,
+ 'parse_function': parse_k8s,
'inventory_function': inventory_k8s_conditions,
'check_function': check_k8s_conditions,
'service_description': 'Condition %s',
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_namespaces b/checks/k8s_namespaces
index 0df4bf6..365c59b 100644
--- a/checks/k8s_namespaces
+++ b/checks/k8s_namespaces
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_namespaces(info):
- import json
- return json.loads(info[0][0])
-
-
@discover
def inventory_k8s_namespaces(_namespace, status):
return status.get('status', {}).get('phase', '') ==
'Active'
@@ -45,8 +40,9 @@ def check_k8s_namespaces(item, _no_params, status):
check_info['k8s_namespaces'] = {
- 'parse_function': parse_k8s_namespaces,
+ 'parse_function': parse_k8s,
'inventory_function': inventory_k8s_namespaces,
'check_function': check_k8s_namespaces,
'service_description': 'Namespace %s',
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_nodes b/checks/k8s_nodes
index 0a5a55b..23acd6c 100644
--- a/checks/k8s_nodes
+++ b/checks/k8s_nodes
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_nodes(info):
- import json
- return json.loads(info[0][0])
-
-
def inventory_k8s_nodes(parsed):
return [(None, {})]
@@ -40,9 +35,10 @@ def check_k8s_nodes(_no_item, _no_params, parsed):
check_info['k8s_nodes'] = {
- 'parse_function': parse_k8s_nodes,
+ 'parse_function': parse_k8s,
'inventory_function': inventory_k8s_nodes,
'check_function': check_k8s_nodes,
'service_description': 'Nodes',
'has_perfdata': True,
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_persistent_volume_claims b/checks/k8s_persistent_volume_claims
index 2f9a1e1..f7db8fd 100644
--- a/checks/k8s_persistent_volume_claims
+++ b/checks/k8s_persistent_volume_claims
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_persistent_volume_claims(info):
- import json
- return json.loads(info[0][0])
-
-
@discover
def inventory_k8s_persistent_volume_claims(_claim, data):
return data.get('phase', '') == 'Bound'
@@ -55,8 +50,9 @@ def check_k8s_persistent_volume_claims(_no_item, _no_params, claim):
check_info['k8s_persistent_volume_claims'] = {
- 'parse_function': parse_k8s_persistent_volume_claims,
+ 'parse_function': parse_k8s,
'inventory_function': inventory_k8s_persistent_volume_claims,
'check_function': check_k8s_persistent_volume_claims,
'service_description': 'PVC %s',
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_persistent_volumes b/checks/k8s_persistent_volumes
index f8d5cfa..845e9f0 100644
--- a/checks/k8s_persistent_volumes
+++ b/checks/k8s_persistent_volumes
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_persistent_volumes(info):
- import json
- return json.loads(info[0][0])
-
-
@discover
def inventory_k8s_persistent_volumes(_pv, status):
return status.get('status', {}).get('phase', '') ==
'Bound'
@@ -53,8 +48,9 @@ def check_k8s_persistent_volumes(item, _no_params, pv):
check_info['k8s_persistent_volumes'] = {
- 'parse_function': parse_k8s_persistent_volumes,
+ 'parse_function': parse_k8s,
'inventory_function': inventory_k8s_persistent_volumes,
'check_function': check_k8s_persistent_volumes,
'service_description': 'PV %s',
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_resources b/checks/k8s_resources
index 74ec4be..d673380 100644
--- a/checks/k8s_resources
+++ b/checks/k8s_resources
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_resources(info):
- import json
- return json.loads(info[0][0])
-
-
def get_k8s_resources_inventory_function(name):
def inventory_function(parsed):
if parsed.get('capacity', {}).get(name):
@@ -39,7 +34,8 @@ def get_k8s_resources_inventory_function(name):
check_info['k8s_resources'] = {
- 'parse_function': parse_k8s_resources,
+ 'parse_function': parse_k8s,
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_roles b/checks/k8s_roles
index 6ebeacc..e5bda8d 100644
--- a/checks/k8s_roles
+++ b/checks/k8s_roles
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_roles(info):
- import json
- return json.loads(info[0][0])
-
-
@get_parsed_item_data
def check_k8s_roles(item, _no_params, role):
age = time.time() - role['creation_timestamp']
@@ -43,8 +38,9 @@ def check_k8s_roles(item, _no_params, role):
check_info['k8s_roles'] = {
- 'parse_function': parse_k8s_roles,
+ 'parse_function': parse_k8s,
'inventory_function': discover(),
'check_function': check_k8s_roles,
'service_description': 'Role %s',
+ 'includes': ['k8s.include'],
}
diff --git a/checks/k8s_storage_classes b/checks/k8s_storage_classes
index 609c31f..71efb6e 100644
--- a/checks/k8s_storage_classes
+++ b/checks/k8s_storage_classes
@@ -25,11 +25,6 @@
# Boston, MA 02110-1301 USA.
-def parse_k8s_storage_classes(info):
- import json
- return json.loads(info[0][0])
-
-
@get_parsed_item_data
def check_k8s_storage_classes(_no_item, _no_params, storage):
reclaim_policy = storage.get('reclaim_policy')
@@ -42,8 +37,9 @@ def check_k8s_storage_classes(_no_item, _no_params, storage):
check_info['k8s_storage_classes'] = {
- 'parse_function': parse_k8s_storage_classes,
+ 'parse_function': parse_k8s,
'inventory_function': discover(),
'check_function': check_k8s_storage_classes,
'service_description': 'Storage class %s',
+ 'includes': ['k8s.include'],
}