-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_bs_inst_health_v0.py
More file actions
116 lines (80 loc) · 3.57 KB
/
aws_bs_inst_health_v0.py
File metadata and controls
116 lines (80 loc) · 3.57 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# ---------------------------------------------------------------------------------------------------------------------------- #
# aws_bs_inst_health_v0.py : AWS Beanstalk Health Status, An xample for the implemenantion of python's boto3 library with
# other python packages.
# Script will show the overall health of beanstalk application with it's respective instances health too.
#
# So what's new ? : The look and feel of all the details in a tabular format.
#
# As comapred to the same first script, no assumption is required over here for max-min instances, it will poppulate by it's own
#
# Author : Jackuna
# ---------------------------------------------------------------------------------------------------------------------------- #
import boto3
import json
from prettytable import PrettyTable
#Color
R = "\033[0;31;40m" # RED
G = "\033[0;32;40m" # GREEN
Y = "\033[0;33;40m" # Yellow
B = "\033[0;34;40m" # Blue
N = "\033[0m" # Reset
CYAN = "\033[1;36m" # CYAN
# Global Varibales
instance_len_list = []
max_instance_len = ""
tabular_fields = ["Application Name","Health","Status"]
def ebs_app_status():
def grab_instance_length():
global instance_len_list
global max_instance_len
beanstalk = boto3.client('elasticbeanstalk')
response = beanstalk.describe_environments()
for val in response['Environments']:
newval = val["EnvironmentName"]
new_response = beanstalk.describe_instances_health(EnvironmentName=newval, AttributeNames=['HealthStatus','Color'])
instance_len_list.append((len(new_response['InstanceHealthList'])))
return max(instance_len_list)
def create_preetyTable_feilds():
global tabular_fields
global max_instance_len
max_instance_len = grab_instance_length()
for new_range in range(0, max_instance_len):
tabular_fields.append("Inst"+str(new_range))
#print(tabular_fields)
def create_preetyTable():
global tabular_fields
global max_instance_lencreate_preetyTable_feilds()
beanstalk = boto3.client('elasticbeanstalk')
response = beanstalk.describe_environments()
tabular_table = PrettyTable()
tabular_table.field_names = tabular_fields
tabular_table.align["Application Name"] = "l"
for val in response['Environments']:
rows = []
rows.append(str(CYAN+val['ApplicationName']+N))
newval = val["EnvironmentName"]
new_response = beanstalk.describe_instances_health(EnvironmentName=newval, AttributeNames=['HealthStatus','Color'])
new_range = len(new_response['InstanceHealthList'])
if val['HealthStatus'] == "Info":
HealthStatus = Y+'Info'+N
elif val['HealthStatus'] == "Ok":
HealthStatus = G+'Ok'+N
if val['Health'] == "Green":
Health = G+'Green'+N
elif val['Health'] == "Info":
Health = Y+'Info'+N
else:
Health = R+'Red'+N
rows.append(HealthStatus)
rows.append(Health)
for ll in range(0, new_range):
Inst = list(new_response['InstanceHealthList'][ll].values())
rows.append(str(Inst))
length_rows = max_instance_len
if length_rows > new_range:
rng = length_rows - new_range
for x_val in range(0, rng):
rows.append("NA")
tabular_table.add_row(rows)
print(tabular_table)
create_preetyTable()