Module: check_mk
Branch: master
Commit: 566f046bfccb67e9f5d897e5c32a475d64e97848
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=566f046bfccb67…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Dec 5 08:48:47 2018 +0100
k8s_resources: remove redundant code from inventory
CMK-511
Change-Id: Ib3c54014a30729779826e38620179ffe9cdd9276
---
checks/k8s_resources | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/checks/k8s_resources b/checks/k8s_resources
index c6d294b..74ec4be 100644
--- a/checks/k8s_resources
+++ b/checks/k8s_resources
@@ -30,16 +30,19 @@ def parse_k8s_resources(info):
return json.loads(info[0][0])
+def get_k8s_resources_inventory_function(name):
+ def inventory_function(parsed):
+ if parsed.get('capacity', {}).get(name):
+ return [(None, {})]
+
+ return inventory_function
+
+
check_info['k8s_resources'] = {
'parse_function': parse_k8s_resources,
}
-def inventory_k8s_pod_resources(parsed):
- if parsed.get('capacity', {}).get('pods'):
- return [(None, {})]
-
-
def check_k8s_pod_resources(_no_item, params, parsed):
pods = parsed.get('allocations', {}).get('pods', 0)
yield 0, 'Pods: %d' % pods, [('k8s_pods', pods)]
@@ -61,7 +64,7 @@ def check_k8s_pod_resources(_no_item, params, parsed):
check_info['k8s_resources.pods'] = {
- 'inventory_function': inventory_k8s_pod_resources,
+ 'inventory_function': get_k8s_resources_inventory_function('pods'),
'check_function': check_k8s_pod_resources,
'service_description': 'Pod resources',
'has_perfdata': True,
@@ -69,11 +72,6 @@ check_info['k8s_resources.pods'] = {
}
-def inventory_k8s_cpu_resources(parsed):
- if parsed.get('capacity', {}).get('cpu'):
- return [(None, {})]
-
-
def check_k8s_cpu_resources(_no_item, params, parsed):
request = parsed.get('requests', {}).get('cpu', 0.0)
yield 0, 'Request: %.3f' % request, [('k8s_cpu_request', request)]
@@ -101,7 +99,7 @@ def check_k8s_cpu_resources(_no_item, params, parsed):
check_info['k8s_resources.cpu'] = {
- 'inventory_function': inventory_k8s_cpu_resources,
+ 'inventory_function': get_k8s_resources_inventory_function('cpu'),
'check_function': check_k8s_cpu_resources,
'service_description': 'CPU resources',
'has_perfdata': True,
@@ -109,11 +107,6 @@ check_info['k8s_resources.cpu'] = {
}
-def inventory_k8s_mem_resources(parsed):
- if parsed.get('capacity', {}).get('memory'):
- return [(None, {})]
-
-
def check_k8s_mem_resources(_no_item, params, parsed):
request = parsed.get('requests', {}).get('memory', 0.0)
yield 0, 'Request: %s' % get_bytes_human_readable(request),
[('k8s_memory_request', request)]
@@ -143,7 +136,7 @@ def check_k8s_mem_resources(_no_item, params, parsed):
check_info['k8s_resources.memory'] = {
- 'inventory_function': inventory_k8s_mem_resources,
+ 'inventory_function':
get_k8s_resources_inventory_function('memory'),
'check_function': check_k8s_mem_resources,
'service_description': 'Memory resources',
'has_perfdata': True,