Class: CLISplash::Logs
- Inherits:
-
Thor
- Object
- Thor
- CLISplash::Logs
- Includes:
- Splash::Config, Splash::Exiter, Splash::Logs
- Defined in:
- lib/splash/cli/logs.rb
Overview
Thor inherited class for documentation management
Constant Summary
Constants included from Splash::Exiter
Constants included from Splash::Loggers
Splash::Loggers::ALIAS, Splash::Loggers::LEVELS
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_METRICS_SCHEDULING, Splash::Constants::DAEMON_PID_FILE, Splash::Constants::DAEMON_PROCESS_NAME, Splash::Constants::DAEMON_PROCMON_SCHEDULING, Splash::Constants::DAEMON_STDERR_TRACE, Splash::Constants::DAEMON_STDOUT_TRACE, Splash::Constants::DEFAULT_RETENTION, Splash::Constants::EMAIL, Splash::Constants::EXECUTION_TEMPLATE, Splash::Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Splash::Constants::LICENSE, Splash::Constants::LOGGERS_STRUCT, Splash::Constants::PID_PATH, Splash::Constants::PROMETHEUS_ALERTMANAGER_URL, Splash::Constants::PROMETHEUS_PUSHGATEWAY_URL, Splash::Constants::PROMETHEUS_URL, Splash::Constants::TRACE_PATH, Splash::Constants::TRANSPORTS_STRUCT, Splash::Constants::VERSION, Splash::Constants::WEBADMIN_IP, Splash::Constants::WEBADMIN_PID_FILE, Splash::Constants::WEBADMIN_PID_PATH, Splash::Constants::WEBADMIN_PORT, Splash::Constants::WEBADMIN_PROCESS_NAME, Splash::Constants::WEBADMIN_PROXY, Splash::Constants::WEBADMIN_STDERR_TRACE, Splash::Constants::WEBADMIN_STDOUT_TRACE
Instance Method Summary collapse
- #analyse ⇒ Object
- #get_result(label) ⇒ Object
- #history(label) ⇒ Object
- #list ⇒ Object
- #monitor ⇒ Object
- #show(logrecord) ⇒ Object
Methods included from Splash::Exiter
Methods included from Splash::Loggers
#change_logger, #get_logger, #get_session
Methods included from Splash::Config
Methods included from Splash::ConfigUtilities
#addservice, #checkconfig, #flush_backend, #setupsplash
Methods included from Splash::Helpers
#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #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
#analyse ⇒ Object
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 40 41 42 43 44 45 46 47 |
# File 'lib/splash/cli/logs.rb', line 14 def analyse if is_root? then log = get_logger results = LogScanner::new res = results.analyse log.info "SPlash Configured log monitors :" full_status = true results.output.each do |result| if result[:status] == :clean then log.ok "Log : #{result[:log]} with label : #{result[:label]} : no errors" log.item "Detected pattern : #{result[:pattern]}" log.item "Nb lines = #{result[:lines]}" elsif result[:status] == :missing then log.ko "Log : #{result[:log]} with label : #{result[:label]} : missing !" log.item "Detected pattern : #{result[:pattern]}" else log.ko "Log : #{result[:log]} with label : #{result[:label]} : #{result[:count]} errors" log.item "Detected pattern : #{result[:pattern]}" log.item "Nb lines = #{result[:lines]}" end full_status = false unless result[:status] == :clean end 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 else splash_exit case: :not_root, :more => "Log analysis" end end |
#get_result(label) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/splash/cli/logs.rb', line 120 def get_result(label) if is_root? then log = get_logger log.info "Log : #{label}" config = get_config records = LogsRecords::new(label).get_all_records if [:date] then wanted = records.select{|key,value| key.keys.first == [:date]}.first else wanted = records.last end if wanted.nil? then splash_exit case: :not_found, more: "Log never monitored" else record =wanted.keys.first value=wanted[record] log.item record log.arrow "Status : #{value[:status].to_s}" log.arrow "nb files : #{value[:errors]}" log.arrow "nb lines : #{value[:lines]}" end else splash_exit case: :not_root, :more => "Log get result" end end |
#history(label) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/splash/cli/logs.rb', line 152 def history(label) if is_root? then log = get_logger log.info "Log : #{label}" config = get_config if [:table] then table = TTY::Table.new do |t| t << ["Start Date", "File","Status", "Nb errors", "Nb lines"] t << ['','','','',''] LogsRecords::new(label).get_all_records.each do |item| record =item.keys.first value=item[record] t << [record, value[:file], value[:status].to_s, value[:errors], value[:lines]] end end if check_unicode_term then puts table.render(:unicode) else puts table.render(:ascii) end else LogsRecords::new(label).get_all_records.each do |item| record =item.keys.first value=item[record] log.item record log.arrow "Status : #{value[:status].to_s}" log.arrow "nb files : #{value[:errors]}" log.arrow "nb lines : #{value[:lines]}" end end splash_exit case: :quiet_exit else splash_exit case: :not_root, :more => "Log analysis" end end |
#list ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/splash/cli/logs.rb', line 95 def list if is_root? then 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]} label : #{record[:label]}" if [:detail] then log.arrow "pattern : /#{record[:pattern]}/" end end splash_exit case: :quiet_exit else splash_exit case: :not_root, :more => "Log analysis" end end |
#monitor ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/splash/cli/logs.rb', line 52 def monitor if is_root? then log = get_logger log.level = :fatal if [:quiet] result = LogScanner::new result.analyse splash_exit result.notify else splash_exit case: :not_root, :more => "Log analysis" end end |
#show(logrecord) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/splash/cli/logs.rb', line 70 def show(logrecord) if is_root? then log = get_logger log_record_set = get_config.logs.select{|item| item[:log] == logrecord or item[:label] == logrecord.to_sym} unless log_record_set.empty? then record = log_record_set.first log.info "Splash log monitor : #{record[:log]}" log.item "pattern : /#{record[:pattern]}/" log.item "label : #{record[:label]}" splash_exit case: :quiet_exit else splash_exit case: :not_found, :more => "log not configured" end else splash_exit case: :not_root, :more => "Log analysis" end end |