class Bosh::Cli::Command::Events

Public Instance Methods

list() click to toggle source
# File lib/cli/commands/events.rb, line 12
def list
  auth_required
  show_events
end

Private Instance Methods

show_events() click to toggle source
# File lib/cli/commands/events.rb, line 18
def show_events
  events = director.list_events(options)
  if events.empty?
    nl
    say('No events')
    nl
    return
  end

  events_table = table do |t|
    headings   = ['ID', 'Time', 'User', 'Action', 'Object type', 'Object ID', 'Task', 'Dep', 'Inst', 'Context']
    t.headings = headings

    events.each do |event|
      row = []
      id  = event['id']
      id  = "#{id} <- #{event['parent_id']}" if event['parent_id']
      row << id
      row << Time.at(event['timestamp']).utc.strftime('%a %b %d %H:%M:%S %Z %Y')
      row << event['user']
      row << event['action']
      row << event['object_type']
      row << event.fetch('object_name', '-')
      row << event.fetch('task', '-')
      row << event.fetch('deployment', '-')
      row << event.fetch('instance', '-')
      context = event['error'] ? {'error' => event['error'].to_s.truncate(80)}.merge(event['context']) : event['context']
      context = context.empty? ? '-' : context.map { |k, v| "#{k}: #{v}" }.join(",\n")
      row << context
      t << row
    end
  end

  nl
  say(events_table)
  nl
end