lib/splash/cli/commands.rb in prometheus-splash-0.4.5 vs lib/splash/cli/commands.rb in prometheus-splash-0.5.0
- old
+ new
@@ -25,12 +25,14 @@
option :notify, :type => :boolean, :default => true
option :callback, :type => :boolean, :default => true
option :hostname, :type => :string
def execute(name)
log = get_logger
+ log.level = :fatal if options[:quiet]
if is_root? then
if options[:hostname] then
+ options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
splash_exit({ :case => :options_incompatibility, :more => '--hostname forbidden with delagate commands'}) if get_config.commands[name.to_sym][:delegate_to]
log.info "Remote Splash configured commands on #{options[:hostname]}:"
log.info "ctrl+c for interrupt"
begin
transport = get_default_client
@@ -47,17 +49,18 @@
else
res = transport.execute({ :verb => :execute_command,
payload: {:name => name},
:return_to => "splash.#{Socket.gethostname}.returncli",
:queue => "splash.#{options[:hostname]}.input" })
- res[:more] = "Remote command : :execute_command Scheduled"
- splash_exit res
end
end
rescue Interrupt
splash_exit case: :interrupt, more: "Remote command exection"
end
+ log.receive "Command execute confirmation"
+ res[:more] = "Remote command : :execute_command Scheduled"
+ splash_exit res
else
command = Splash::CommandWrapper::new(name)
if options[:ack] then
splash_exit command.ack
end
@@ -78,15 +81,16 @@
with --in TIMING, Schedule in specified timing, like 12s, 1m, 2h, 3m10s, 10d\n
--in and --at are imcompatibles.\n
WARNING : scheduling by CLI are not percisted, so use it only for specifics cases.\n
NOTES : Scheduling, force trace, notifying and callback.
LONGDESC
- option :hostname, :type => :string
+ option :hostname, :type => :string, :default => Socket.gethostname
option :at, :type => :string
option :in, :type => :string
def schedule(name)
log = get_logger
+ log.level = :fatal if options[:quiet]
hostname = (options[:hostname])? options[:hostname] : Socket.gethostname
splash_exit({ :case => :options_incompatibility, :more => '--at or --in is required'}) unless options[:at] or options[:in]
splash_exit({ :case => :options_incompatibility, :more => '--at an --in'}) if options[:at] and options[:in]
log.info "Remote Splash scheduling command on #{hostname}:"
log.info "ctrl+c for interrupt"
@@ -99,36 +103,65 @@
schedule = { :at => options[:at]} if options[:at]
res = transport.execute({ :verb => :execute_command,
payload: {:name => name, :schedule => schedule},
:return_to => "splash.#{Socket.gethostname}.returncli",
:queue => "splash.#{hostname}.input" })
- log.receive "Execute command sheduled confirmed"
- res[:more] = "Remote command : :execute_command with schedule"
- splash_exit res
end
rescue Interrupt
splash_exit case: :interrupt, more: "Remote command exection"
end
+ log.receive "Execute command sheduled confirmed"
+ res[:more] = "Remote command : :execute_command with schedule"
+ splash_exit res
end
desc "treeview", "Show commands sequence tree"
- def treeview(command, depht = 0)
+ long_desc <<-LONGDESC
+ Show commands sequence tree\n
+ with --hostname, ask other Splash daemon via transport\n
+ LONGDESC
+ option :hostname, :type => :string
+ def treeview(command)
+ depht = 0
log = get_logger
+ if options[:hostname] then
+ options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
+ log.info "Remote Splash scheduling command on #{options[:hostname]}:"
+ log.info "ctrl+c for interrupt"
+ begin
+ transport = get_default_client
+ if transport.class == Hash and transport.include? :case then
+ splash_exit transport
+ else
+ commands = transport.execute({ :verb => :list_commands,
+ :return_to => "splash.#{Socket.gethostname}.returncli",
+ :queue => "splash.#{options[:hostname]}.input" })
+ end
+ rescue Interrupt
+ splash_exit case: :interrupt, more: "Remote command exection"
+ end
+ log.receive "Receving list of commands from #{options[:hostname]}"
+ else
+ commands = get_config.commands
+ end
log.info "Command : #{command.to_s}" if depht == 0
- cmd = get_config.commands[command.to_sym]
- if cmd[:on_failure] then
- spacer= " " * depht + " "
- log.flat "#{spacer}* on failure => #{cmd[:on_failure]}"
- treeview(cmd[:on_failure], depht+2)
+ aproc = Proc::new do |command,depht|
+ cmd = commands[command.to_sym]
+ if cmd[:on_failure] then
+ spacer= " " * depht + " "
+ log.flat "#{spacer}* on failure => #{cmd[:on_failure]}"
+ aproc.call(cmd[:on_failure], depht+2)
+ end
+ if cmd[:on_success] then
+ spacer = " " * depht + " "
+ log.flat "#{spacer}* on success => #{cmd[:on_success]}"
+ aproc.call(cmd[:on_success],depht+2)
+ end
end
- if cmd[:on_success] then
- spacer = " " * depht + " "
- log.flat "#{spacer}* on success => #{cmd[:on_success]}"
- treeview(cmd[:on_success],depht+2)
- end
+ aproc.call(command,depht)
end
desc "list", "Show configured commands"
long_desc <<-LONGDESC
@@ -140,10 +173,11 @@
option :hostname, :type => :string
def list
log = get_logger
list = {}
if options[:hostname] then
+ options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
log.info "Remote Splash configured commands on #{options[:hostname]}:"
log.info "ctrl+c for interrupt"
begin
transport = get_default_client
if transport.class == Hash and transport.include? :case then
@@ -154,14 +188,15 @@
:queue => "splash.#{options[:hostname]}.input" })
end
rescue Interrupt
splash_exit case: :interrupt, more: "remote list Command"
end
+ log.receive "Receving list of commands from #{options[:hostname]}"
else
- log.info "Splash configured commands :"
list = get_config.commands
end
+ log.info "Splash configured commands :"
log.ko 'No configured commands found' if list.keys.empty?
list.keys.each do |command|
log.item "#{command.to_s}"
if options[:detail] then
log.arrow "command line : '#{list[command][:command]}'"
@@ -186,10 +221,11 @@
option :hostname, :type => :string
def show(command)
log = get_logger
list = {}
if options[:hostname] then
+ options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
log.info "Remote Splash configured commands on #{options[:hostname]}:"
log.info "ctrl+c for interrupt"
begin
transport = get_default_client
if transport.class == Hash and transport.include? :case then
@@ -200,10 +236,11 @@
:queue => "splash.#{options[:hostname]}.input" })
end
rescue Interrupt
splash_exit case: :interrupt, more: "remote list Command"
end
+ log.receive "Receving list of commands from #{options[:hostname]}"
else
list = get_config.commands
end
if list.keys.include? command.to_sym then
log.info "Splash command : #{command}"
@@ -233,12 +270,14 @@
backend = get_backend :execution_trace
redis = (backend.class == Splash::Backends::Redis)? true : false
if not redis and options[:hostname] then
splash_exit case: :specific_config_required, :more => "Redis backend is requiered for Remote execution report request"
end
+ splash_exit case: :not_root if not is_root? and not redis
list = get_config.commands.keys
if options[:hostname] then
+ options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
list = backend.list("*", options[:hostname]).map(&:to_sym)
end
if list.include? command.to_sym then
log.info "Splash command #{command} previous execution report:\n"
req = { :key => command}
@@ -272,17 +311,19 @@
option :hostname, :type => :string
option :all, :type => :boolean, :negate => false
option :detail, :type => :boolean
def getreportlist
log = get_logger
+ options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
if options[:hostname] and options[:all] then
splash_exit case: :options_incompatibility, more: "--all, --hostname"
end
backend = get_backend :execution_trace
redis = (backend.class == Splash::Backends::Redis)? true : false
if not redis and (options[:hostname] or options[:all]) then
splash_exit case: :specific_config_required, more: "Redis Backend requiered for Remote execution report Request"
end
+ splash_exit case: :not_root if not is_root? and not redis
pattern = (options[:pattern])? options[:pattern] : '*'
if options[:all] then
res = backend.listall pattern
elsif options[:hostname]
res = backend.list pattern, options[:hostname]