[checkmk-commits] Use discover of the check_api in Kubernetes checks

Tom Baerwinkel tb at mathias-kettner.de
Wed Nov 21 11:20:45 CET 2018


Module: check_mk
Branch: master
Commit: 4d5c83b4907b421bd42c97954c8b665eee53f9bf
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4d5c83b4907b421bd42c97954c8b665eee53f9bf

Author: Tom Baerwinkel <tb at mathias-kettner.de>
Date:   Tue Nov 20 09:43:24 2018 +0100

Use discover of the check_api in Kubernetes checks

Change-Id: I59c6a6c6fefa5102ee87b80fbe9f01216101a8aa

---

 checks/k8s_component_statuses       | 7 +------
 checks/k8s_namespaces               | 7 +++----
 checks/k8s_persistent_volume_claims | 8 +++-----
 checks/k8s_persistent_volumes       | 7 +++----
 checks/k8s_roles                    | 7 +------
 checks/k8s_storage_classes          | 7 +------
 6 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/checks/k8s_component_statuses b/checks/k8s_component_statuses
index c4b8473..f441feb 100644
--- a/checks/k8s_component_statuses
+++ b/checks/k8s_component_statuses
@@ -30,11 +30,6 @@ def parse_k8s_component_statuses(info):
     return json.loads(info[0][0])
 
 
-def inventory_k8s_component_statuses(parsed):
-    for component in parsed:
-        yield component, {}
-
-
 @get_parsed_item_data
 def check_k8s_component_statuses(item, _no_params, conditions):
     for condition in conditions:
@@ -48,7 +43,7 @@ def check_k8s_component_statuses(item, _no_params, conditions):
 
 check_info['k8s_component_statuses'] = {
     'parse_function': parse_k8s_component_statuses,
-    'inventory_function': inventory_k8s_component_statuses,
+    'inventory_function': discover(),
     'check_function': check_k8s_component_statuses,
     'service_description': 'Component %s',
 }
diff --git a/checks/k8s_namespaces b/checks/k8s_namespaces
index b8a9509..0df4bf6 100644
--- a/checks/k8s_namespaces
+++ b/checks/k8s_namespaces
@@ -30,10 +30,9 @@ def parse_k8s_namespaces(info):
     return json.loads(info[0][0])
 
 
-def inventory_k8s_namespaces(parsed):
-    for namespace, status in parsed.iteritems():
-        if status.get('status').get('phase', '') == 'Active':
-            yield namespace, {}
+ at discover
+def inventory_k8s_namespaces(_namespace, status):
+    return status.get('status', {}).get('phase', '') == 'Active'
 
 
 @get_parsed_item_data
diff --git a/checks/k8s_persistent_volume_claims b/checks/k8s_persistent_volume_claims
index b64e120..2f9a1e1 100644
--- a/checks/k8s_persistent_volume_claims
+++ b/checks/k8s_persistent_volume_claims
@@ -30,11 +30,9 @@ def parse_k8s_persistent_volume_claims(info):
     return json.loads(info[0][0])
 
 
-def inventory_k8s_persistent_volume_claims(parsed):
-    for claim, data in parsed.iteritems():
-        if data.get('phase', '') != 'Bound':
-            continue
-        yield claim, {}
+ at discover
+def inventory_k8s_persistent_volume_claims(_claim, data):
+    return data.get('phase', '') == 'Bound'
 
 
 @get_parsed_item_data
diff --git a/checks/k8s_persistent_volumes b/checks/k8s_persistent_volumes
index dc8480b..f8d5cfa 100644
--- a/checks/k8s_persistent_volumes
+++ b/checks/k8s_persistent_volumes
@@ -30,10 +30,9 @@ def parse_k8s_persistent_volumes(info):
     return json.loads(info[0][0])
 
 
-def inventory_k8s_persistent_volumes(parsed):
-    for pc, status in parsed.iteritems():
-        if status.get('status').get('phase', '') == 'Bound':
-            yield pc, {}
+ at discover
+def inventory_k8s_persistent_volumes(_pv, status):
+    return status.get('status', {}).get('phase', '') == 'Bound'
 
 
 @get_parsed_item_data
diff --git a/checks/k8s_roles b/checks/k8s_roles
index b71e3ae..6ebeacc 100644
--- a/checks/k8s_roles
+++ b/checks/k8s_roles
@@ -30,11 +30,6 @@ def parse_k8s_roles(info):
     return json.loads(info[0][0])
 
 
-def inventory_k8s_roles(parsed):
-    for role in parsed:
-        yield role, {}
-
-
 @get_parsed_item_data
 def check_k8s_roles(item, _no_params, role):
     age = time.time() - role['creation_timestamp']
@@ -49,7 +44,7 @@ def check_k8s_roles(item, _no_params, role):
 
 check_info['k8s_roles'] = {
     'parse_function': parse_k8s_roles,
-    'inventory_function': inventory_k8s_roles,
+    'inventory_function': discover(),
     'check_function': check_k8s_roles,
     'service_description': 'Role %s',
 }
diff --git a/checks/k8s_storage_classes b/checks/k8s_storage_classes
index b9b8cae..609c31f 100644
--- a/checks/k8s_storage_classes
+++ b/checks/k8s_storage_classes
@@ -30,11 +30,6 @@ def parse_k8s_storage_classes(info):
     return json.loads(info[0][0])
 
 
-def inventory_k8s_storage_classes(parsed):
-    for storage_name in parsed:
-        yield storage_name, {}
-
-
 @get_parsed_item_data
 def check_k8s_storage_classes(_no_item, _no_params, storage):
     reclaim_policy = storage.get('reclaim_policy')
@@ -48,7 +43,7 @@ def check_k8s_storage_classes(_no_item, _no_params, storage):
 
 check_info['k8s_storage_classes'] = {
     'parse_function': parse_k8s_storage_classes,
-    'inventory_function': inventory_k8s_storage_classes,
+    'inventory_function': discover(),
     'check_function': check_k8s_storage_classes,
     'service_description': 'Storage class %s',
 }



More information about the checkmk-commits mailing list