Class: AwsAuditor::Scripts::Audit
- Inherits:
-
Object
- Object
- AwsAuditor::Scripts::Audit
- Extended by:
- AWSWrapper
- Defined in:
- lib/aws_auditor/scripts/audit.rb
Class Attribute Summary collapse
-
.options ⇒ Object
Returns the value of attribute options.
Attributes included from AWSWrapper
Class Method Summary collapse
- .colorize(key, value) ⇒ Object
- .execute(environment, options = nil) ⇒ Object
- .header(type, length = 50) ⇒ Object
- .output(class_type) ⇒ Object
Class Attribute Details
.options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/aws_auditor/scripts/audit.rb', line 9 def @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, =nil) aws(environment) @options = no_selection = .values.uniq == [false] output("EC2Instance") if [:ec2] || no_selection output("RDSInstance") if [:rds] || no_selection output("CacheInstance") if [: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 [:instances] instances = klass.instance_count_hash(klass.get_instances) puts header(class_type) instances.each{ |key,value| say "<%= color('#{key}: #{value}', :white) %>" } elsif [: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 |