Sha256: c2de2ad15dd685a050d063237103e735cd34fd682999481b16b296e019a5c4a3

Contents?: true

Size: 1.39 KB

Versions: 53

Compression:

Stored size: 1.39 KB

Contents

require_relative '../helpers/log_helper'

module Kontena::Cli::Grids
  class EventsCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::Helpers::LogHelper

    SKIP_TYPES = ['grid']

    option "--node", "NODE", "Filter by node name", multivalued: true
    option "--service", "SERVICE", "Filter by service name", multivalued: true

    def execute
      require_api_url

      query_params = {}
      query_params[:nodes] = node_list.join(",") unless node_list.empty?
      query_params[:services] = service_list.join(",") unless service_list.empty?

      titles = ['TIME', 'TYPE', 'RELATIONSHIPS', 'MESSAGE']
      puts "%-25s %-25s %-40s %s" % titles
      show_logs("grids/#{current_grid}/event_logs", query_params) do |log|
        show_log(log)
      end
    end

    def show_log(log)
      msg = log['message']
      rels = log['relationships'].
        delete_if { |r| SKIP_TYPES.include?(r['type']) }.
        map { |r|
          id = r['id'].split('/')[1..-1].delete_if{ |s| s == 'null'}.join('/')
          unless id.empty?
            "#{r['type']}=#{id}"
          end
        }.compact

      time = log['created_at']
      if log['severity'] == 2
        time = time.colorize(:yellow)
      elsif log['severity'] >= 3
        time = time.colorize(:red)
      end

      puts '%-25s %-25s %-40s %s' % [
        time, log['type'], rels.join(','), msg
      ]
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
kontena-cli-1.4.0.pre7 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.4.0.pre6 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.4.0.pre5 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.4.0.pre4 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.4.0.pre3 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.4.0.pre2 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.4.0.pre1 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.4 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.4.rc1 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.3 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.3.rc1 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.2 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.2.rc2 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.2.rc1 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.1 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.1.rc2 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.1.rc1 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.0 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.0.rc4 lib/kontena/cli/grids/events_command.rb
kontena-cli-1.3.0.rc3 lib/kontena/cli/grids/events_command.rb