-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_bs_inst_health.py
More file actions
74 lines (60 loc) · 3 KB
/
aws_bs_inst_health.py
File metadata and controls
74 lines (60 loc) · 3 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
# ---------------------------------------------------------------------------------------------------------------------------- #
# aws_bs_inst_health.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.
#
# Assumptions wthin the script:
# Total defined instnaces within Beanstalk : Min : 1, Mac : 4
#
# Author : Jackuna
# ---------------------------------------------------------------------------------------------------------------------------- #
import boto3
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
def ebs_app_status():
beanstalk = boto3.client('elasticbeanstalk')
response = beanstalk.describe_environments()
tabular_table = PrettyTable()
tabular_table.field_names = ["Application Name","Health", "Inst1","Inst2","Inst3","Inst4"]
tabular_table.align["Application Name"] = "l"
#tabular_table.align["Environment Name"] = "l"
for val in response['Environments']:
newval = val["EnvironmentName"]
new_response = beanstalk.describe_instances_health(EnvironmentName=newval, AttributeNames=['HealthStatus','Color'])
instance_len = (len(new_response['InstanceHealthList']))
if instance_len == 1:
Instnace_1 = list(new_response['InstanceHealthList'][0].values())
Instnace_2 = "NA"
Instnace_3 = "NA"
Instnace_4 = "NA"
elif instance_len == 2:
Instnace_1 = list(new_response['InstanceHealthList'][0].values())
Instnace_2 = list(new_response['InstanceHealthList'][1].values())
Instnace_3 = "NA"
Instnace_4 = "NA"
elif instance_len == 3:
Instnace_1 = list(new_response['InstanceHealthList'][0].values())
Instnace_2 = list(new_response['InstanceHealthList'][1].values())
Instnace_3 = list(new_response['InstanceHealthList'][2].values())
Instnace_4 = "NA"
elif instance_len == 4:
Instnace_1 = list(new_response['InstanceHealthList'][0].values())
Instnace_2 = list(new_response['InstanceHealthList'][1].values())
Instnace_3 = list(new_response['InstanceHealthList'][2].values())
Instnace_4 = list(new_response['InstanceHealthList'][3].values())
if val['Health'] == "Green":
Health = G+'Green'+N
else:
Health = R+'Red'+N
#tabular_table.add_row([Y+val['ApplicationName']+N,Health, val['HealthStatus'], Instnace_1,Instnace_2, Instnace_3, Instnace_4])
tabular_table.add_row([CYAN+val['ApplicationName']+N, Health, Instnace_1,Instnace_2, Instnace_3, Instnace_4])
print(tabular_table)
ebs_app_status()