Class: Morpheus::Cli::RecentActivityCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/recent_activity_command.rb

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, included

Constructor Details

#initializeRecentActivityCommand

Returns a new instance of RecentActivityCommand.



11
12
13
14
# File 'lib/morpheus/cli/recent_activity_command.rb', line 11

def initialize() 
	@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
	@active_groups = ::Morpheus::Cli::Groups.load_group_file
end

Instance Method Details

#connect(opts) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/morpheus/cli/recent_activity_command.rb', line 16

def connect(opts)
	@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).load_saved_credentials()
	if @access_token.empty?
		print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
		exit 1
	end
	@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
	@dashboard_interface = @api_client.dashboard
end

#handle(args) ⇒ Object



30
31
32
# File 'lib/morpheus/cli/recent_activity_command.rb', line 30

def handle(args)
	list(args)
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/recent_activity_command.rb', line 34

def list(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		opts.on(nil,'--start', "Start timestamp. Default is 30 days ago.") do |val|
			options[:start_ts] = val
		end
		opts.on(nil,'--end', "End timestamp. Default is now.") do |val|
			options[:end_ts] = val
		end
		build_common_options(opts, options, [:list, :json])
	end
	optparse.parse(args)

	connect(options)
	begin
		
		params = {}
		[:phrase, :offset, :max, :sort, :direction, :start, :end].each do |k|
			params[k] = options[k] unless options[k].nil?
		end

		json_response = @dashboard_interface.recent_activity(params)
		
		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			

			# todo: impersonate command and show that info here

			print "\n" ,cyan, bold, "Dashboard\n","==================", reset, "\n\n"
			print cyan
			
			print "\n"
			puts "Coming soon.... see --json"
			print "\n"

			print reset,"\n"

		end
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#usageObject



26
27
28
# File 'lib/morpheus/cli/recent_activity_command.rb', line 26

def usage
	"Usage: morpheus recent-activity"
end