lib/splash/cli/commands.rb in prometheus-splash-0.8.3 vs lib/splash/cli/commands.rb in prometheus-splash-0.8.4
- old
+ new
@@ -13,11 +13,11 @@
include Splash::Loggers
include Splash::Commands
# Thor method : execution of command
- desc "execute NAME", "run for command/sequence or ack result"
+ desc "execute COMMAND", "run for command/sequence or ack result"
long_desc <<-LONGDESC
execute command or sequence or ack result\n
with --no-trace prevent storing execution trace in configured backend (see config file)\n
with --ack, notify errorcode=0 to Prometheus PushGateway\n
with --no-notify, bypass Prometheus notification\n
@@ -77,11 +77,11 @@
end
end
# Thor method : scheduling commands
- desc "schedule NAME", "Schedule excution of command on Splash daemon"
+ desc "schedule COMMAND", "Schedule excution of command on Splash daemon"
long_desc <<-LONGDESC
Schedule excution of command on Splash daemon\n
with --hostname, Schedule on an other Splash daemon via transport\n
with --at TIME/DATE, Schedule at specified date/time, like 2030/12/12 23:30:00 or 12:00 \n
with --in TIMING, Schedule in specified timing, like 12s, 1m, 2h, 3m10s, 10d\n
@@ -123,11 +123,11 @@
splash_exit res
end
# Thor method : getting a treeview of sequence of commands
- desc "treeview", "Show commands sequence tree"
+ desc "treeview COMMAND", "Show commands sequence tree"
long_desc <<-LONGDESC
Show commands sequence tree\n
with --hostname, ask other Splash daemon via transport\n
LONGDESC
option :hostname, :type => :string, :aliases => "-H"
@@ -282,15 +282,15 @@
# Thor method : show commands executions history
long_desc <<-LONGDESC
show commands executions history for LABEL\n
LONGDESC
option :table, :type => :boolean, :aliases => "-t"
- desc "history LABEL", "show commands executions history"
+ desc "history COMMAND", "show commands executions history"
def history(command)
if is_root? then
log = get_logger
- log.info "Log : #{command}#"
+ log.info "Command : #{command}"
config = get_config
if options[:table] then
table = TTY::Table.new do |t|
t << ["Start Date","Status", "end_date", "Execution time","STDOUT empty ? ", "STDERR empty ? "]
t << ['','','','','','']
@@ -326,65 +326,21 @@
else
splash_exit case: :not_root, :more => "Command execution history"
end
end
- # Thor method : getting information on the last execution of a command
- desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
- long_desc <<-LONGDESC
- Show last running result for 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 lastrun(command)
- unless is_root? then
- splash_exit case: :not_root, :more => "Command last execution report"
- end
- log = get_logger
- 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}
- req[:hostname] = options[:hostname] if options[:hostname]
- if backend.exist? req then
- res = backend.get req
- tp = Template::new(
- list_token: get_config.execution_template_tokens,
- template_file: get_config.execution_template_path)
- tp.map YAML::load(res).last.values.first
- log.flat tp.output
- else
- log.ko "Command not already runned."
- end
- splash_exit case: :quiet_exit
- else
- splash_exit case: :not_found, :more => "Command report never runned remotly" if options[:hostname]
- end
- end
-
-
# Thor method : getting information on one specific execution of a command
- desc "onerun COMMAND", "Show running result for specific configured command COMMAND"
+ desc "get_result COMMAND", "Show running result for specific configured command COMMAND"
long_desc <<-LONGDESC
Show specific running result for specific configured command COMMAND\n
with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
with --date <DATE>, a date format string (same as in history ouput)
LONGDESC
option :hostname, :type => :string, :aliases => "-H"
- option :date, :type => :string, :aliases => "-D", :required => true
- def onerun(command)
+ option :date, :type => :string, :aliases => "-D"
+ def get_result(command)
unless is_root? then
splash_exit case: :not_root, :more => "Command specific execution report"
end
log = get_logger
backend = get_backend :execution_trace
@@ -405,28 +361,36 @@
if backend.exist? req then
res = backend.get req
tp = Template::new(
list_token: get_config.execution_template_tokens,
template_file: get_config.execution_template_path)
- prov = YAML::load(res).select{|key,value| key.keys.first == options[:date]}
- if prov.empty? then
+ if options[:date] then
+ prov = YAML::load(res).select{|key,value| key.keys.first == options[:date]}.first
+ else
+ prov = YAML::load(res).last
+ end
+ if prov.nil? then
log.ko "Command not runned one this date or date misformatted."
else
- tp.map prov.first.values.first
+ tp.map prov.values.first
log.flat tp.output
end
else
log.ko "Command not already runned."
end
splash_exit case: :quiet_exit
else
- splash_exit case: :not_found, :more => "Command report never runned remotly" if options[:hostname]
+ if options[:hostname]
+ splash_exit case: :not_found, :more => "Command never runned remotly"
+ else
+ splash_exit case: :not_found, :more => "Command never runned"
+ end
end
end
# Thor method : getting the list of avaibles executions reports
- desc "getreportlist", "list all executions report results "
+ desc "reportlist", "list all executions report results "
long_desc <<-LONGDESC
list all executions report results\n
with --pattern <SEARCH>, search type string, wilcard * (group) ? (char)\n
with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)\n
with --all, get all execution report for all servers (only with Redis backend configured)\n
@@ -435,10 +399,10 @@
LONGDESC
option :pattern, :type => :string, :aliases => "-p"
option :hostname, :type => :string, :aliases => "-H"
option :all, :type => :boolean, :negate => false, :aliases => "-A"
option :detail, :type => :boolean, :aliases => "-D"
- def getreportlist
+ def reportlist
unless is_root? then
splash_exit case: :not_root, :more => "Command execution report list"
end
log = get_logger
options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'