class ForemanMaintain::Cli::ReportCommand

Public Instance Methods

execute() click to toggle source
# File lib/foreman_maintain/cli/report_command.rb, line 27
def execute
  report_data = generate_report
  yaml = report_data.to_yaml
  save_report(yaml, @output)

  exit runner.exit_code
end
fresh_enough?(input, max_age) click to toggle source
# File lib/foreman_maintain/cli/report_command.rb, line 58
def fresh_enough?(input, max_age)
  @input && File.exist?(input) &&
    (@max_age.nil? || (Time.now - File.stat(input).mtime <= 60 * 60 * max_age.to_i))
end
generate_report() click to toggle source
# File lib/foreman_maintain/cli/report_command.rb, line 6
def generate_report
  scenario = run_scenario(Scenarios::Report::Generate.new({}, [:reports])).first

  # description can be used too
  report_data = scenario.steps.map(&:data).compact.reduce(&:merge).
                transform_keys(&:to_s).sort.to_h
  report_data['version'] = 3
  report_data
end
prefix_keys(data) click to toggle source
# File lib/foreman_maintain/cli/report_command.rb, line 54
def prefix_keys(data)
  data.transform_keys { |key| 'foreman.' + key }
end
save_report(report, file) click to toggle source
# File lib/foreman_maintain/cli/report_command.rb, line 16
def save_report(report, file)
  if file
    File.write(file, report)
  else
    puts report
  end
end