Class: AwsAuditor::Scripts::Audit

Inherits:
Object
  • Object
show all
Extended by:
AWSWrapper
Defined in:
lib/aws_auditor/scripts/audit.rb

Instance Attribute Summary

Attributes included from AWSWrapper

#aws

Class Method Summary collapse

Class Method Details

.audit_cache(options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aws_auditor/scripts/audit.rb', line 58

def self.audit_cache(options)
  puts "============== CACHE =============="
  if options[:instances]
    CacheInstance.instance_count_hash(CacheInstance.get_instances).each do |key,value|
      say "<%= color('#{key}: #{value}', :white) %>"
    end
  elsif options[:reserved]
    CacheInstance.instance_count_hash(CacheInstance.get_reserved_instances).each do |key,value|
      say "<%= color('#{key}: #{value}', :white) %>"
    end
  else
    CacheInstance.compare.each do |key,value|
      colorize(key,value)
    end
  end
end

.audit_ec2(options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/aws_auditor/scripts/audit.rb', line 41

def self.audit_ec2(options)
  puts "=============== EC2 ==============="
  if options[:instances]
    EC2Instance.instance_count_hash(EC2Instance.get_instances).each do |key,value|
      say "<%= color('#{key}: #{value}', :white) %>"
    end
  elsif options[:reserved]
    EC2Instance.instance_count_hash(EC2Instance.get_reserved_instances).each do |key,value|
      say "<%= color('#{key}: #{value}', :white) %>"
    end
  else
    EC2Instance.compare.each do |key,value|
      colorize(key,value)
    end
  end
end

.audit_rds(options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aws_auditor/scripts/audit.rb', line 24

def self.audit_rds(options)
  puts "=============== RDS ==============="
  if options[:instances]
    RDSInstance.instance_count_hash(RDSInstance.get_instances).each do |key,value|
      say "<%= color('#{key}: #{value}', :white) %>"
    end
  elsif options[:reserved]
    RDSInstance.instance_count_hash(RDSInstance.get_reserved_instances).each do |key,value|
      say "<%= color('#{key}: #{value}', :white) %>"
    end
  else
    RDSInstance.compare.each do |key, value|
      colorize(key,value)
    end
  end
end

.colorize(key, value) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/aws_auditor/scripts/audit.rb', line 75

def self.colorize(key,value)
  if value < 0
    say "<%= color('#{key}: #{value}', :yellow) %>"
  elsif value == 0
    say "<%= color('#{key}: #{value}', :green) %>"
  elsif value > 0 
    say "<%= color('#{key}: #{value}', :red) %>"
  end
end

.execute(environment, options = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/aws_auditor/scripts/audit.rb', line 8

def self.execute(environment, options=nil)
  aws(environment)
  if options[:ec2]
    audit_ec2(options)
  elsif options[:rds]
    audit_rds(options)
  elsif options[:cache]
    audit_cache(options)
  else
    audit_ec2(options)
    audit_rds(options)
    audit_cache(options)
  end

end