blob: 7262fb1c30d4b2e44563437d4abf7c62528e5087 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
"""
Node Exporter Check
"""
import logging
from tools.kube_utils import kube_api
from internal.checks.pod_health_check import pod_status, get_logs
from internal.store_result import store_result
def node_exporter_check():
"""
Checks existence & health of node exporter pods
"""
kube = kube_api()
namespaces = kube.list_namespace()
ns_names = []
for nspace in namespaces.items:
ns_names.append(nspace.metadata.name)
result = {'category': 'observability',
'case_name': 'node_exporter_check',
'criteria': 'pass',
'details': []
}
status = []
flag = False
logger = logging.getLogger(__name__)
if 'monitoring' in ns_names:
pod_list = kube.list_namespaced_pod('monitoring', watch=False)
pods = pod_list.items
for pod in pods:
if 'node-exporter' in pod.metadata.name:
pod_stats = pod_status(logger, pod)
if pod_stats['criteria'] == 'fail':
pod_stats['logs'] = get_logs(kube, pod)
result['criteria'] = 'fail'
status.append(pod.metadata.name)
status.append(pod_stats)
flag = True
else:
for nspace in namespaces.items:
pod_list = kube.list_namespaced_pod(nspace.metadata.name, watch=False)
pods = pod_list.items
for pod in pods:
if 'node-exporter' in pod.metadata.name:
pod_stats = pod_status(logger, pod)
if pod_stats['criteria'] == 'fail':
pod_stats['logs'] = get_logs(kube, pod)
result['criteria'] = 'fail'
status.append(pod.metadata.name)
status.append(pod_stats)
flag = True
if flag is False:
result['criteria'] = 'fail'
result['details'].append(status)
store_result(logger, result)
return result
|