class CircActivator::CLI

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/circactivator/cli.rb, line 26
def initialize(*args)
  super
  CircActivator::Log.create(options[:debug])
  @monitoring = CircActivator::Monitoring.new
end

Public Instance Methods

exit_handler() click to toggle source
# File lib/circactivator/cli.rb, line 88
def exit_handler
  @monitoring.set_error_file unless options[:debug]
  if @monitoring.errors?
    Kernel.exit(2)
  else
    Kernel.exit(0)
  end
end
log_error(msg) click to toggle source
# File lib/circactivator/cli.rb, line 83
def log_error(msg)
  CircActivator::Log.error(msg)
  @monitoring.add_error_message(msg)
end
run_updater(group, check_bundle_id, regex) click to toggle source
# File lib/circactivator/cli.rb, line 64
def run_updater(group, check_bundle_id, regex)
  CircActivator::Log.info("Starting update for group #{group}, check bundle #{check_bundle_id}")

  begin
    updater = CircActivator::CheckUpdater.new(check_bundle_id)
    updater.name_regex = regex unless regex.nil?
    updated_metrics = updater.run(options[:debug])
  rescue => e
    log_error("Error updating #{check_bundle_id}: #{e.class}: #{e.message}")
    return
  end

  if updated_metrics.length > 0
    CircActivator::Log.info("Update for group #{group}, check bundle #{check_bundle_id} complete.  Metrics added: #{updated_metrics.join(', ')}")
  else
    CircActivator::Log.info("Update for group #{group}, check bundle #{check_bundle_id} complete.  No metrics updated.")
  end
end
update_all_groups() click to toggle source
# File lib/circactivator/cli.rb, line 47
def update_all_groups
  CircActivator::Config.check_bundles.each do |group, check_bundles|
    check_bundles.each do |check_bundle_id, regex|
      run_updater(group, check_bundle_id, regex)
    end
  end

  exit_handler
end
update_check_bundle(check_bundle_id, regex=nil) click to toggle source
# File lib/circactivator/cli.rb, line 58
def update_check_bundle(check_bundle_id, regex=nil)
  run_updater('no_group', check_bundle_id, regex)
  exit_handler
end
update_group(group) click to toggle source
# File lib/circactivator/cli.rb, line 33
def update_group(group)
  unless CircActivator::Config['check_bundles'].include?(group)
    CircActivator::Log.fatal("Site #{group} not found in the configuration.")
    exit(1)
  end

  CircActivator::Config['check_bundles'][group].each do |check_bundle_id, regex|
    run_updater(group, check_bundle_id, regex)
  end

  exit_handler
end