-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun_describe_cloudwatch.py
executable file
·73 lines (51 loc) · 1.6 KB
/
run_describe_cloudwatch.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
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
#!/usr/bin/env python3
from env import env
from run_common import AWSCli
aws_cli = AWSCli()
def describe_cloudwatch_dashboard():
if not env.get('cloudwatch'):
return False
if not env['cloudwatch'].get('DASHBOARDS'):
return False
d_set = set()
dashboards_list = env['cloudwatch']['DASHBOARDS']
for dl in dashboards_list:
d_name = f"{dl['NAME']}_{dl['AWS_REGION']}"
d_set.add(d_name)
cmd = ['cloudwatch', 'list-dashboards']
result = aws_cli.run(cmd)
for de in result['DashboardEntries']:
if de['DashboardName'] in d_set:
return True
return False
def describe_cloudwatch_alarm():
if not env.get('cloudwatch'):
return False
if not env['cloudwatch'].get('ALARMS'):
return False
a_set = set()
alarms_list = env['cloudwatch']['ALARMS']
for al in alarms_list:
a_name = f"{al['NAME']}_{al['AWS_REGION']}_{al.get('METRIC_NAME', '')}"
a_set.add(f'"{a_name}"')
cmd = ['cloudwatch', 'describe-alarms']
cmd += ['--alarm-names']
cmd += a_set
result = aws_cli.run(cmd)
for ma in result['MetricAlarms']:
if ma['AlarmName'] in a_set:
return True
return False
results = list()
if describe_cloudwatch_dashboard():
results.append('CloudWatch Dashboard -------------- O')
else:
results.append('CloudWatch Dashboard -------------- X')
if describe_cloudwatch_alarm():
results.append('CloudWatch Alarm -------------- O')
else:
results.append('CloudWatch Alarm -------------- X')
print('#' * 80)
for r in results:
print(r)
print('#' * 80)