-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_counter.rb
71 lines (65 loc) · 2.59 KB
/
stack_counter.rb
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
require File.dirname(__FILE__) + '/aws_counter'
SECTION = ''
SERVICE_ID = ''
module STACK_SHORT_STATUS
IN_PROGRESS = 'IN_PROGRESS'
FAILED = 'FAILED'
COMPLETE = 'COMPLETE'
ROLLBACK = 'ROLLBACK'
end
STACK_STATUS = {
'CREATE_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'CREATE_FAILED' => STACK_SHORT_STATUS::FAILED,
'CREATE_COMPLETE' => STACK_SHORT_STATUS::COMPLETE,
'ROLLBACK_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'ROLLBACK_FAILED' => STACK_SHORT_STATUS::FAILED,
'ROLLBACK_COMPLETE' => STACK_SHORT_STATUS::ROLLBACK,
'DELETE_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'DELETE_FAILED' => STACK_SHORT_STATUS::FAILED,
# 'DELETE_COMPLETE' => STACK_SHORT_STATUS::DELETE,
'UPDATE_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'UPDATE_COMPLETE' => STACK_SHORT_STATUS::COMPLETE,
'UPDATE_ROLLBACK_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'UPDATE_ROLLBACK_FAILED' => STACK_SHORT_STATUS::FAILED,
'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS' => STACK_SHORT_STATUS::IN_PROGRESS,
'UPDATE_ROLLBACK_COMPLETE' => STACK_SHORT_STATUS::COMPLETE }
counter = Aws::Counter.new
counter.cli("aws cloudformation list-stacks --stack-status-filter #{STACK_STATUS.keys.join(' ')}").map(:per_phase) do |result, data|
data['dev'] = 0
result['StackSummaries'].each do |stack|
if m = Regexp.new("#{SECTION}+-#{SERVICE_ID}+-(?<phase>\\w+)-.+").match(stack['StackName'])
data[m[:phase]] += 1
end
end
data['total'] = data.values.inject { |a, e| a + e }
end.save('stack_count.csv')
counter.map do |result, data|
STACK_STATUS.keys.each { |status| data[status] = 0 }
result['StackSummaries'].each do |stack|
if m = Regexp.new("#{SECTION}+-#{SERVICE_ID}+-(?<phase>\\w+)-.+").match(stack['StackName'])
if STACK_STATUS.keys.include?(stack['StackStatus'])
data[stack['StackStatus']] += 1
else
data['UNKNOWN'] += 1
end
end
end
end.save('stack_count_per_status.csv')
counter.map do |result, data|
phase_list = Aws::Counter::PHASE_LIST.dup.push('dev')
phase_list.each do |phase|
STACK_STATUS.values.each do |status|
data["[#{phase}]#{status}"] = 0
end
end
result['StackSummaries'].each do |stack|
if m = Regexp.new("#{SECTION}+-#{SERVICE_ID}+-(?<phase>\\w+)-.+").match(stack['StackName'])
if STACK_STATUS.keys.include?(stack['StackStatus'])
data["[#{m[:phase]}]#{STACK_STATUS[stack['StackStatus']]}"] += 1
else
data["[#{m[:phase]}]UNKNOWN"] += 1
end
end
end
end.save('stack_count_per_phase_and_status.csv')