#!/usr/bin/env ruby -W:no-deprecated require 'prometheus/client' require 'prometheus/client/push' begin 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." end require 'yaml' require 'splash/constants' require 'splash/helpers' require 'splash/config' require 'splash/command' require 'splash/logs' require 'splash/controller' #inhibit warning : due to prometheus-client call to URI.encode warning $-w = nil include Splash::Helpers module CLISplash class Commands < Thor option :ack, :type => :boolean desc "wrap NAME", "wrapping for command or ack result" def wrap(name) command = Splash::CommandWrapper::new(name) command.ack if options[:ack] command.call_and_notify 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 end desc "stop", "Stopping Logs Monitor Daemon" def stop run_as_root :stopdaemon end end class Config < Thor include Splash::Config include Splash::Helpers desc "setup", "Setup installation fo Splash" def setup run_as_root :setupsplash end desc "sanitycheck", "Verify installation fo Splash" def sanitycheck run_as_root :checkconfig end desc "version", "display current Splash version" def version config = get_config puts "Splash version : #{config.version}, Author : #{config.author}" puts config.copyright end end class Logs < Thor desc "analyse", "analyze logs in config" def analyse result = Splash::LogScanner::new result.analyse p result.output end desc "monitor", "monitor logs in config" def monitor result = Splash::LogScanner::new result.analyse result.notify end end end class CLI < Thor 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" subcommand "logs", Logs desc "daemon SUBCOMMAND ...ARGS", "Logs monitor daemon contoller" subcommand "daemon", CLIController desc "config SUBCOMMAND ...ARGS", "config tools for Splash" subcommand "config", Config end CLI.start(ARGV)