-
Notifications
You must be signed in to change notification settings - Fork 3
/
pods.py
27 lines (23 loc) · 912 Bytes
/
pods.py
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
import subprocess
from operator import itemgetter
class Pod:
def __init__(self):
data = subprocess.check_output('kubectl get pods --all-namespaces', shell = True)
data_decode = data.decode('ASCII')
self.obj = data_decode.split()
self.err_msg_list = [
"ErrImagePull",
"Error",
"CrashLoopBackOff",
"ImagePullBackOff"
]
def filtering_data(self):
for i in range(0, len(self.obj), 6):
yield (self.obj[i: i + 6])
def catching_errors(self, list_of_pods):
for items in list_of_pods:
for err in self.err_msg_list:
if err in items:
data = itemgetter(0, 1, 3)(items) # select specific items from list of the pods
data_str = ' '.join(data) # concatenate and convert items to strings
print(data_str)