lib/splash/cli/commands.rb in prometheus-splash-0.8.4 vs lib/splash/cli/commands.rb in prometheus-splash-0.8.5
- old
+ new
@@ -157,11 +157,11 @@
else
commands = get_config.commands
end
log.info "Command : #{command.to_s}" if depht == 0
aproc = Proc::new do |command,depht|
- cmd = commands[command.to_sym]
+ cmd = commands.select{|item| item[:name] == command.to_sym}.first
if cmd[:on_failure] then
spacer= " " * depht + " "
log.flat "#{spacer}* on failure => #{cmd[:on_failure]}"
aproc.call(cmd[:on_failure], depht+2)
end
@@ -209,20 +209,20 @@
log.receive "Receving list of commands from #{options[:hostname]}"
else
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}"
+ log.ko 'No configured commands found' if list.empty?
+ list.each do |command|
+ log.item "#{command[:name].to_s}"
if options[:detail] then
- log.arrow "command line : '#{list[command][:command]}'"
- log.arrow "command description : '#{list[command][:desc]}'"
- log.arrow "command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
- log.arrow "command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
- if list[command.to_sym][:schedule]
- sched,val = list[command.to_sym][:schedule].flatten
+ log.arrow "command line : '#{command[:command]}'"
+ log.arrow "command description : '#{command[:desc]}'"
+ log.arrow "command failure callback : '#{command[:on_failure]}'" if command[:on_failure]
+ log.arrow "command success callback : '#{command[:on_success]}'" if command[:on_success]
+ if command[:schedule] then
+ sched,val = command[:schedule].flatten
log.arrow "command scheduled : #{sched} #{val}."
end
end
end
splash_exit case: :quiet_exit
@@ -233,11 +233,11 @@
long_desc <<-LONGDESC
Show specific configured command COMMAND\n
with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
LONGDESC
option :hostname, :type => :string, :aliases => "-H"
- def show(command)
+ def show(name)
unless is_root? then
splash_exit case: :not_root, :more => "Command show specifications"
end
log = get_logger
list = {}
@@ -259,18 +259,19 @@
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}"
- log.item "command line : '#{list[command.to_sym][:command]}'"
- log.item "command description : '#{list[command.to_sym][:desc]}'"
- log.item "command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
- log.item "command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
- if list[command.to_sym][:schedule]
- sched,val = list[command.to_sym][:schedule].flatten
+ command = list.select{|item| item[:name] == name.to_sym}.first
+ unless command.nil? then
+ log.info "Splash command : #{command[:name]}"
+ log.item "command line : '#{command[:command]}'"
+ log.item "command description : '#{command[:desc]}'"
+ log.item "command failure callback : '#{command[:on_failure]}'" if command[:on_failure]
+ log.item "command success callback : '#{command[:on_success]}'" if command[:on_success]
+ if command[:schedule]
+ sched,val = command[:schedule].flatten
log.item "command scheduled : #{sched} #{val}."
end
splash_exit case: :quiet_exit
else
splash_exit case: :not_found, :more => 'Command not configured'
@@ -299,11 +300,11 @@
value=item[record]
t << [record, value[:status].to_s,
value[:end_date],
value[:exec_time],
value[:stdout].empty?,
- value[:stdout].empty?]
+ value[:stderr].empty?]
end
end
if check_unicode_term then
puts table.render(:unicode)
else
@@ -347,15 +348,15 @@
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
+ list = get_config.commands
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
+ if list.select{|cmd| cmd[:name] == command.to_sym}.count > 0 then
log.info "Splash command #{command} previous execution report:\n"
req = { :key => command}
req[:hostname] = options[:hostname] if options[:hostname]
if backend.exist? req then
res = backend.get req