class CLISplash::Logs

Thor inherited class for documentation management

Public Instance Methods

analyse() click to toggle source
# 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) click to toggle source
# 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 options[:date] then
      wanted = records.select{|key,value| key.keys.first == options[: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) click to toggle source
# 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 options[: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() click to toggle source
# 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 options[: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() click to toggle source
# File lib/splash/cli/logs.rb, line 52
def monitor
  if is_root? then
    log = get_logger
    log.level = :fatal if options[:quiet]
    result = LogScanner::new
    result.analyse
    splash_exit result.notify
  else
    splash_exit case: :not_root, :more => "Log analysis"
  end

end
show(logrecord) click to toggle source
# 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