Class: Morpheus::Cli::RecentActivityCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::RecentActivityCommand
- Includes:
- AccountsHelper, CliCommand
- Defined in:
- lib/morpheus/cli/commands/recent_activity_command.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #connect(opts) ⇒ Object
-
#handle(args) ⇒ Object
def usage “Usage: morpheus #CliCommand#command_name” end.
-
#initialize ⇒ RecentActivityCommand
constructor
A new instance of RecentActivityCommand.
- #list(args) ⇒ Object
Methods included from AccountsHelper
#account_column_definitions, #account_users_interface, #accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_all_user_ids, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #find_user_group_by_id, #find_user_group_by_name, #find_user_group_by_name_or_id, #format_access_string, #format_role_type, #format_user_role_names, #format_user_status, #get_access_color, #get_access_string, included, #list_account_column_definitions, #list_user_column_definitions, #list_user_group_column_definitions, #role_column_definitions, #roles_interface, #subtenant_role_column_definitions, #user_column_definitions, #user_group_column_definitions, #user_groups_interface
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Constructor Details
#initialize ⇒ RecentActivityCommand
Returns a new instance of RecentActivityCommand.
12 13 14 |
# File 'lib/morpheus/cli/commands/recent_activity_command.rb', line 12 def initialize() # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance end |
Instance Method Details
#connect(opts) ⇒ Object
16 17 18 19 20 |
# File 'lib/morpheus/cli/commands/recent_activity_command.rb', line 16 def connect(opts) @api_client = establish_remote_appliance_connection(opts) @dashboard_interface = @api_client.dashboard @accounts_interface = @api_client.accounts end |
#handle(args) ⇒ Object
def usage
"Usage: morpheus #{command_name}"
end
26 27 28 29 |
# File 'lib/morpheus/cli/commands/recent_activity_command.rb', line 26 def handle(args) print_error yellow,"[DEPRECATED] The command `recent-activity` is deprecated. It has been replaced by `activity list`.",reset,"\n" list(args) end |
#list(args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/morpheus/cli/commands/recent_activity_command.rb', line 31 def list(args) params, = {}, {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = usage opts.on( '-u', '--user USER', "Username or ID" ) do |val| [:user] = val end opts.on('--start TIMESTAMP','--start TIMESTAMP', "Start timestamp. Default is 30 days ago.") do |val| [:start] = parse_time(val).utc.iso8601 end opts.on('--end TIMESTAMP','--end TIMESTAMP', "End timestamp. Default is now.") do |val| [:end] = parse_time(val).utc.iso8601 end (opts, ) opts. = <<-EOT List recent activity. This command is deprecated. Use `activity` instead. EOT end # parse options optparse.parse!(args) # parse arguments verify_args!(args:args, count:0, optparse:optparse) # establish connection to @remote_appliance connect() # construct request #params.merge!(parse_query_options(options)) # inject -Q PARAMS params.merge!(()) # inject phrase,sort,max,offset and -Q PARAMS # parse my options # this api allows filter by params.accountId # todo: use OptionSourceHelper parse_tenant_id() instead of AccountsHelper account = () account_id = account ? account['id'] : nil if account_id params['accountId'] = account_id end if [:start] params['start'] = [:start] end if [:end] params['end'] = [:end] end # parse --user if [:user] user_ids = parse_user_id_list([:user]) return 1 if user_ids.nil? # userId limited to one right now # params['userId'] = user_ids params['userId'] = user_ids[0] end # setup interface and check for dry run? @dashboard_interface.setopts() if [:dry_run] print_dry_run @dashboard_interface.dry.recent_activity(params) return 0, nil end # make the request json_response = @dashboard_interface.recent_activity(params) # determine exit status exit_code, err = 0, nil # could error if there are no results. # if json_response['activity'].empty? # exit_code = 3 # err = "0 results found" # end # render output render_response(json_response, , "activity") do title = "Activity" subtitles = [] subtitles += parse_list_subtitles() if [:start] subtitles << "Start: #{[:start]}" end if [:end] subtitles << "End: #{[:end]}" end print_h1 title, subtitles print cyan items = json_response["activity"] if items.empty? puts "No activity found." print reset,"\n" else # JD: this api response is funky, no meta and it includes date objects # ok then its gone, get good api response data gosh darnit! # use /api/activity instead items = items.select { |item| item['_id'] || item['name'] } columns = [ # {"ID" => lambda {|item| item['id'] } }, # {"SEVERITY" => lambda {|item| format_activity_severity(item['severity']) } }, {"TYPE" => lambda {|item| item['activityType'] } }, {"AUTHOR" => lambda {|item| item['userName'] || '' } }, {"MESSAGE" => lambda {|item| item['message'] || '' } }, {"OBJECT" => lambda {|item| format_activity_display_object(item) } }, {"WHEN" => lambda {|item| format_local_dt(item['ts']) } } ] print as_pretty_table(items, columns, ) print reset,"\n" end return exit_code, err end end |