lib/outliers/cli/process.rb in outliers-0.3.3 vs lib/outliers/cli/process.rb in outliers-0.5.0.beta1
- old
+ new
@@ -1,10 +1,10 @@
module Outliers
module CLI
class Process
def process
- @options = { threads: 1 }
+ @options = { threads: 1, log_level: 'info' }
option_parser.parse!
Outliers.config_path @options[:directory]
@@ -14,35 +14,57 @@
if @options[:threads] > 1
@run.threaded = true
@run.thread_count = @options[:threads]
end
+ log_level = @options.fetch(:log_level).upcase
+
+ unless ["DEBUG", "INFO", "WARN", "ERROR"].include? log_level
+ @logger.error "Invalid log level. Valid levels are debug, info, warn, error."
+ exit 1
+ end
+
+ @logger.level = Logger.const_get log_level
+
begin
- @run.credentials = Credentials.load_from_file "#{ENV['HOME']}/.outliers.yml"
+ @run.account = Account.load_from_file "#{ENV['HOME']}/.outliers.yml"
@run.process_evaluations_in_dir
rescue Outliers::Exceptions::Base => e
@logger.error e.message
exit 1
end
- passed = @run.passed.count
- failed = @run.failed.count
+ passing_count = @run.passing_results.count
+ failing_count = @run.failing_results.count
@logger.info "Evaluations completed."
- @run.failed.each do |f|
- if f.evaluation
- @logger.info "Evaluation '#{f.evaluation}' verification '#{f.verification}' of '#{f.resource}' failed."
+ if key
+ @logger.info "Running report handlers."
+ @run.results.each do |result|
+ unless Outliers::Handlers::OutliersApi.new.post result, key, results_url
+ @logger.error "Report handler failed."
+ exit 1
+ end
+ end
+ @logger.info "Report handlers completed."
+ else
+ @logger.info "OUTLIERS_KEY not set, not sending results."
+ end
+
+ @run.failing_results.each do |r|
+ if r.name
+ @logger.info "Results of '#{r.name}', verifying '#{r.verification_name}' of '#{r.provider_name}:#{r.resource_name}' via '#{r.account_name}' failed."
else
- @logger.info "Verification '#{f.verification}' of '#{f.resource}' failed."
+ @logger.info "Verification '#{r.verification_name}' of '#{r.provider_name}:#{r.resource_name}' via '#{r.account_name}' failed."
end
- @logger.info "Failing resource IDs '#{f.failing_resources.map{|r| r.id}.join(', ')}'"
+ @logger.info "Failing resource IDs '#{r.failing_resources.map{|r| r.id}.join(', ')}'"
end
- @logger.info "(#{failed} evaluations failed, #{passed} evaluations passed.)"
+ @logger.info "(#{failing_count} evaluations failed, #{passing_count} evaluations passed.)"
- exit 1 unless failed.zero?
+ exit 1 unless failing_count.zero?
end
def command_name
'process'
end
@@ -51,19 +73,35 @@
'Process evaluations in config folder.'
end
private
+ def key
+ ENV['OUTLIERS_KEY']
+ end
+
+ def url
+ ENV['OUTLIERS_URL'] ||= 'https://api.getoutliers.com'
+ end
+
+ def results_url
+ "#{url}/results"
+ end
+
def option_parser
OptionParser.new do |opts|
opts.banner = "Usage: outliers process [options]"
- opts.on("-t", "--threads [THREADS]", "Maximum number of evaluations threads to run concurrently (Default: 1).") do |o|
- @options[:threads] = o.to_i
- end
-
opts.on("-d", "--directory [DIRECTORY]", "Directory containing evaluations to load.") do |o|
@options[:directory] = o
+ end
+
+ opts.on("-l", "--log_level [LOG_LEVEL]", "Log level (Default: info).") do |o|
+ @options[:log_level] = o
+ end
+
+ opts.on("-t", "--threads [THREADS]", "Maximum number of evaluations threads to run concurrently (Default: 1).") do |o|
+ @options[:threads] = o.to_i
end
end
end
end