Class: CLISplash::Logs

Inherits:
Thor
  • Object
show all
Includes:
Splash::Config, Splash::Exiter
Defined in:
lib/splash/cli/logs.rb

Constant Summary

Constants included from Splash::Exiter

Splash::Exiter::EXIT_MAP

Constants included from Splash::Constants

Splash::Constants::AUTHOR, Splash::Constants::BACKENDS_STRUCT, Splash::Constants::CONFIG_FILE, Splash::Constants::COPYRIGHT, Splash::Constants::DAEMON_LOGMON_SCHEDULING, Splash::Constants::DAEMON_PID_FILE, Splash::Constants::DAEMON_PID_PATH, Splash::Constants::DAEMON_PROCESS_NAME, Splash::Constants::DAEMON_STDERR_TRACE, Splash::Constants::DAEMON_STDOUT_TRACE, Splash::Constants::EMAIL, Splash::Constants::EXECUTION_TEMPLATE, Splash::Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Splash::Constants::LICENSE, Splash::Constants::LOGGERS_STRUCT, Splash::Constants::PROMETHEUS_PUSHGATEWAY_HOST, Splash::Constants::PROMETHEUS_PUSHGATEWAY_PORT, Splash::Constants::TRACE_PATH, Splash::Constants::TRANSPORTS_STRUCT, Splash::Constants::VERSION

Instance Method Summary collapse

Methods included from Splash::Exiter

#splash_exit

Methods included from Splash::Loggers

#change_logger, #get_logger

Methods included from Splash::Config

#get_config

Methods included from Splash::ConfigUtilities

#checkconfig, #setupsplash

Methods included from Splash::Helpers

#daemonize, #get_process, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Instance Method Details

#analyseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/splash/cli/logs.rb', line 10

def analyse
  log  = get_logger
  results = Splash::LogScanner::new
  res = results.analyse
  log.info "SPlash Configured logs status :"
  full_status = true
  results.output.each do |result|
    if result[:status] == :clean then
      log.ok "Log : #{result[:log]} : no errors"
      log.item "Detected pattern : #{result[:pattern]}"
      log.item "Nb lines = #{result[:lines]}"
    elsif result[:status] == :missing then
      log.ko "Log : #{result[:log]} : missing !"
      log.item "Detected pattern : #{result[:pattern]}"
    else
      log.ko "Log : #{result[:log]} : #{result[:count]} errors"
      log.item "Detected pattern : #{result[:pattern]}"
      log.item "Nb lines = #{result[:lines]}"
    end

    full_status = false unless result[:status] == :clean
  end
  display_status = (full_status)? "OK": "KO"
  if full_status then
    log.ok "Global status : no error found"
  else
    log.error "Global status : some error found"
  end
  splash_exit case: :quiet_exit
end

#listObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/splash/cli/logs.rb', line 70

def list
  log = get_logger
  log.info "Splash configured log monitoring :"
  log_record_set = get_config.logs
  log.ko 'No configured commands found' if log_record_set.empty?
  log_record_set.each do |record|
    log.item "log monitor : #{record[:log]}"
    if options[:detail] then
      log.flat "  ->   pattern : /#{record[:pattern]}/"
    end
  end
  splash_exit case: :quiet_exit
end

#monitorObject



42
43
44
45
46
47
48
# File 'lib/splash/cli/logs.rb', line 42

def monitor
  result = Splash::LogScanner::new
  result.analyse
  result.notify
  splash_exit result.notify

end

#show(logrecord) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/splash/cli/logs.rb', line 51

def show(logrecord)
  log = get_logger
  log_record_set = get_config.logs.select{|item| item[:log] == logrecord }
  unless log_record_set.empty? then
    record = log_record_set.first
    log.info "Splash log monitor : #{record[:log]}"
    log.item "pattern : /#{record[:pattern]}/"
    splash_exit case: :quiet_exit
  else
    splash_exit case: :not_found, :more => "log not configured"
  end
end