bin/splash in prometheus-splash-0.0.1 vs bin/splash in prometheus-splash-0.0.2
- old
+ new
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby -W:no-deprecated
-require 'prometheus/client'
-require 'prometheus/client/push'
begin
+ require 'prometheus/client'
+ require 'prometheus/client/push'
require 'thor'
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."
@@ -14,12 +14,13 @@
require 'yaml'
require 'splash/constants'
require 'splash/helpers'
require 'splash/config'
+require 'splash/templates'
-require 'splash/command'
+require 'splash/commands'
require 'splash/logs'
require 'splash/controller'
#inhibit warning : due to prometheus-client call to URI.encode warning
$-w = nil
@@ -28,58 +29,135 @@
module CLISplash
class Commands < Thor
+ include Splash::Config
- option :ack, :type => :boolean
desc "wrap NAME", "wrapping for command or ack result"
+ long_desc <<-LONGDESC
+ wrapping for command or ack result
+ with --no-trace prevent storing execution trace in TRACE_PATH (see config file)
+ with --ack, notify errorcode=0 to Prometheus PushGateway
+ LONGDESC
+ option :trace, :type => :boolean, :default => true
+ option :ack, :type => :boolean, negate: false
def wrap(name)
- command = Splash::CommandWrapper::new(name)
- command.ack if options[:ack]
- command.call_and_notify
+ if is_root? then
+ command = Splash::CommandWrapper::new(name)
+ command.ack if options[:ack]
+ command.call_and_notify trace: options[:trace]
+ else
+ $stderr.puts "Command wrapping need to be run as root"
+ exit 60
+ 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|
+ puts " * #{command.to_s}"
+ if options[:detail] then
+ puts " - command line : '#{list[command][:command]}'"
+ puts " - command description : '#{list[command][:desc]}'"
+ end
+ end
+ end
+
+
+ desc "show COMMAND", "Show specific configured command COMMAND"
+ def show(command)
+ 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]}'"
+ else
+ $stderr.puts "Command not configured"
+ exit 50
+ end
+ end
+
+
+ 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}")
+ else
+ puts "Command not already runned."
+ end
+ else
+ $stderr.puts "Command not configured"
+ exit 50
+ end
+ end
+
end
class CLIController < Thor
include Splash::LogsMonitor::DaemonController
option :foreground, :type => :boolean
desc "start", "Starting Logs Monitor Daemon"
def start
- run_as_root :startdaemon
+ errorcode = run_as_root :startdaemon
+ exit errorcode
end
desc "stop", "Stopping Logs Monitor Daemon"
def stop
- run_as_root :stopdaemon
+ errorcode = run_as_root :stopdaemon
+ exit errorcode
end
+ desc "status", "Logs Monitor Daemon status"
+ def status
+ errorcode = run_as_root :statusdaemon
+ exit errorcode
+ end
+
end
+
+
+
class Config < Thor
include Splash::Config
include Splash::Helpers
desc "setup", "Setup installation fo Splash"
def setup
- run_as_root :setupsplash
-
+ errorcode = run_as_root :setupsplash
+ exit errorcode
end
desc "sanitycheck", "Verify installation fo Splash"
def sanitycheck
- run_as_root :checkconfig
+ errorcode = run_as_root :checkconfig
+ exit errorcode
end
desc "version", "display current Splash version"
def version
- config = get_config
- puts "Splash version : #{config.version}, Author : #{config.author}"
- puts config.copyright
+ config = get_config
+ puts "Splash version : #{config.version}, Author : #{config.author}"
+ puts config.copyright
end
end
@@ -103,12 +181,12 @@
end
end
class CLI < Thor
- def self.exit_on_failure?
- true
- end
+ def self.exit_on_failure?
+ true
+ end
include CLISplash
desc "commands SUBCOMMAND ...ARGS", "Managing commands/batchs supervision"
subcommand "commands", Commands
desc "logs SUBCOMMAND ...ARGS", "Managing Files/Logs supervision"