bin/splash in prometheus-splash-0.0.2 vs bin/splash in prometheus-splash-0.0.3
- old
+ new
@@ -3,10 +3,12 @@
begin
require 'prometheus/client'
require 'prometheus/client/push'
require 'thor'
+ require 'rufus-scheduler'
+
rescue Gem::GemNotFoundException
$stderr.puts "Loadind error, it's like you try to run Splash, with a lake of dependencies."
$stderr.puts "If you run on RVM, please run with rvmsudo and not with sudo."
$stderr.puts "If problem is percistant, please, proceed to new install and Setup."
end
@@ -15,13 +17,15 @@
require 'splash/constants'
require 'splash/helpers'
require 'splash/config'
require 'splash/templates'
+require 'splash/backends'
require 'splash/commands'
require 'splash/logs'
+require 'splash/orchestrator'
require 'splash/controller'
#inhibit warning : due to prometheus-client call to URI.encode warning
$-w = nil
@@ -30,46 +34,76 @@
module CLISplash
class Commands < Thor
include Splash::Config
+ include Splash::Backends
- desc "wrap NAME", "wrapping for command or ack result"
+ desc "run NAME", "run for command/sequence or ack result"
long_desc <<-LONGDESC
- wrapping for command or ack result
+ Running command or sequence or ack result
with --no-trace prevent storing execution trace in TRACE_PATH (see config file)
with --ack, notify errorcode=0 to Prometheus PushGateway
+ with --no-notify, bypass Prometheus notification
LONGDESC
option :trace, :type => :boolean, :default => true
option :ack, :type => :boolean, negate: false
+ option :notify, :type => :boolean, :default => true
def wrap(name)
if is_root? then
command = Splash::CommandWrapper::new(name)
command.ack if options[:ack]
- command.call_and_notify trace: options[:trace]
+ command.call_and_notify trace: options[:trace], notify: options[:notify]
else
$stderr.puts "Command wrapping need to be run as root"
exit 60
end
end
+
+ desc "treeview", "Show commands sequence tree"
+ def treeview(command, depht = 0)
+ puts "Command : #{command.to_s}" if depht == 0
+ cmd = get_config.commands[command.to_sym]
+ if cmd[:on_failure] then
+ print " " * depht + " "
+ puts "* on failure => #{cmd[:on_failure]}"
+ treeview(cmd[:on_failure], depht+2)
+ end
+ if cmd[:on_success] then
+ print " " * depht + " "
+ puts "* on success => #{cmd[:on_success]}"
+ treeview(cmd[:on_success],depht+2)
+ end
+ end
+
+
+
+
+
+
+
+
+
desc "list", "Show configured commands"
long_desc <<-LONGDESC
Show configured commands
with --detail, show command details
LONGDESC
option :detail, :type => :boolean
def list
puts "Splash configured commands :"
list = get_config.commands
puts 'No configured commands found' if list.keys.empty?
- listc.keys.each do |command|
+ list.keys.each do |command|
puts " * #{command.to_s}"
if options[:detail] then
puts " - command line : '#{list[command][:command]}'"
puts " - command description : '#{list[command][:desc]}'"
+ puts " - command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
+ puts " - command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
end
end
end
@@ -78,10 +112,12 @@
list = get_config.commands
if list.keys.include? command.to_sym then
puts "Splash command : #{command}"
puts " - command line : '#{list[command.to_sym][:command]}'"
puts " - command description : '#{list[command.to_sym][:desc]}'"
+ puts " - command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
+ puts " - command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
else
$stderr.puts "Command not configured"
exit 50
end
end
@@ -90,13 +126,14 @@
desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
def lastrun(command)
list = get_config.commands
if list.keys.include? command.to_sym then
print "Splash command #{command} previous execution report:\n\n"
- filename = "#{get_config[:trace_path]}/#{command}_trace.last"
- if File::exist? filename then
- system("cat #{filename}")
+ backend = get_backend :execution_trace
+ key = "#{command}_trace.last"
+ if backend.exist? key: key then
+ print backend.get key: key
else
puts "Command not already runned."
end
else
$stderr.puts "Command not configured"
@@ -161,24 +198,67 @@
end
class Logs < Thor
+ include Splash::Config
desc "analyse", "analyze logs in config"
def analyse
- result = Splash::LogScanner::new
- result.analyse
- p result.output
+ results = Splash::LogScanner::new
+ results.analyse
+ puts "SPlash Configured logs status :"
+ full_status = true
+ results.output.each do |result|
+ status = (result[:status] == :clean)? "OK": "KO"
+ puts " * Log : #{result[:log]} : [#{status}]"
+ puts " - Detected pattern : #{result[:pattern]}"
+ puts " - detailled Status : #{result[:status].to_s}"
+ puts " count = #{result[:count]}" if result[:status] == :matched
+ puts " nb lines = #{result[:lines]}" if result[:status] != :missing
+ full_status = false unless result[:status] == :clean
+ end
+ display_status = (full_status)? "OK": "KO"
+ puts "Global Status : [#{display_status}]"
end
desc "monitor", "monitor logs in config"
def monitor
result = Splash::LogScanner::new
result.analyse
result.notify
end
+ desc "show LOG", "show configured log monitoring for LOG"
+ def show(log)
+ log_record_set = get_config.logs.select{|item| item[:log] == log }
+ unless log_record_set.empty? then
+ record = log_record_set.first
+ puts "Splash log monitor : #{record[:log]}"
+ puts " -> pattern : /#{record[:pattern]}/"
+ else
+ $stderr.puts "log not configured"
+ exit 50
+ end
+ end
+
+ desc "list", "Show configured logs monitoring"
+ long_desc <<-LONGDESC
+ Show configured logs monitoring
+ with --detail, show logs monitor details
+ LONGDESC
+ option :detail, :type => :boolean
+ def list
+ puts "Splash configured log monitoring :"
+ log_record_set = get_config.logs
+ puts 'No configured commands found' if log_record_set.empty?
+ log_record_set.each do |record|
+ puts " * log monitor : #{record[:log]}"
+ if options[:detail] then
+ puts " -> pattern : /#{record[:pattern]}/"
+ end
+ end
+ end
end
end
class CLI < Thor