Class: AwsAuditor::Scripts::Audit

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

Class Attribute Summary collapse

Attributes included from AWSWrapper

#aws

Class Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/aws_auditor/scripts/audit.rb', line 9

def options
  @options
end

Class Method Details

.colorize(key, value) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/aws_auditor/scripts/audit.rb', line 39

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



12
13
14
15
16
17
18
19
# File 'lib/aws_auditor/scripts/audit.rb', line 12

def self.execute(environment, options=nil)
  aws(environment)
  @options = options
  no_selection = options.values.uniq == [false]
  output("EC2Instance") if options[:ec2] || no_selection
  output("RDSInstance") if options[:rds] || no_selection 
  output("CacheInstance") if options[:cache] || no_selection
end

.header(type, length = 50) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/aws_auditor/scripts/audit.rb', line 49

def self.header(type, length = 50)
  type.upcase!.slice! "INSTANCE"
  half_length = (length - type.length)/2.0 - 1
  [
    "*" * length,
    "*" * half_length.floor + " #{type} " + "*" * half_length.ceil,
    "*" * length
  ].join("\n")
end

.output(class_type) ⇒ Object



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

def self.output(class_type)
  klass = AwsAuditor.const_get(class_type)
  print "Gathering info, please wait..."; print "\r"
  if options[:instances]
    instances = klass.instance_count_hash(klass.get_instances)
    puts header(class_type)
    instances.each{ |key,value| say "<%= color('#{key}: #{value}', :white) %>" }
  elsif options[:reserved]
    reserved = klass.instance_count_hash(klass.get_reserved_instances)
    puts header(class_type)
    reserved.each{ |key,value| say "<%= color('#{key}: #{value}', :white) %>" }
  else
    compared = klass.compare
    puts header(class_type)
    compared.each{ |key,value| colorize(key,value) }
  end
end