Class: Fum::Commands::Events

Inherits:
Fum::Command show all
Defined in:
lib/fum/commands/events.rb

Instance Method Summary collapse

Methods inherited from Fum::Command

#initialize, #stage

Methods included from Util

#die

Constructor Details

This class inherits a constructor from Fum::Command

Instance Method Details

#execute(options) ⇒ Object



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
# File 'lib/fum/commands/events.rb', line 16

def execute(options)
  beanstalk = Fog::AWS[:beanstalk]

  filters = {
      'MaxRecords' => options[:number],
      'ApplicationName' => options[:application],
      'VersionLabel' => options[:version_label]
  }
  filters['Severity'] = options[:severity].upcase unless options[:severity].nil?

  if options[:environment] && options[:environment].match(/e-[a-zA-Z0-9]{10}/)
    filters['EnvironmentId'] = options[:environment]
  else
    filters['EnvironmentName'] = options[:environment]
  end

  filters = filters.delete_if { |key, value| value.nil? }

  events = beanstalk.events.all(filters).reverse

  # Beanstalk seems to return an extra item
  events.shift

  events.each { |event|
    app = event.application_name
    if event.environment_name
      app += "(#{event.environment_name})"
    elsif event.version_label
      app += "(#{event.version_label})"
    elsif event.template_name
      app += "(#{event.template_name})"
    end

    puts "#{event.date.strftime('%b %d %H:%M:%S')} #{app} #{event.severity} \"#{event.message}\""
  }

end

#parse_optionsObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/fum/commands/events.rb', line 5

def parse_options
  Trollop::options do
    banner "usage: events [options], where options are:"
    opt :number, "Number of events to show", :type => :integer, :default => 100
    opt :application, "Show events only for the specified application", :type => :string
    opt :environment, "Show events associated with the specified environment name or id", :type => :string
    opt :severity, "Limit events to severity or higher", :type => :string
    opt :version_label, "Version label", :type => :string, :long => "version"
  end
end