class RedhatAccess::SosReports::Generator

Public Class Methods

create_report(case_num) click to toggle source
# File lib/redhat_access/sos_reports/generator.rb, line 18
def self.create_report case_num
  command = SOS_COMMAND
  unless case_num.nil?
    unless is_valid_case_number case_num  #security injection check
      raise ArgumentError.new "case number must be an integer"
    else
      command = command + " --ticket-number=#{case_num}"
    end
  end
  begin
    Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
      report_location = ''
      if wait_thr.value == 0
        stdout.readlines.each do |line|
          if line.include? "tar.xz"
            report_location = line #brittle, but we assume only single line
            break
          end
        end
      else
        #puts "sos report failed"
      end
      sos_file_name = report_location.strip
      puts "SOS file created : " + sos_file_name
      sos_file_name
    end
  rescue => exception
    Rails.logger.error("Error Creating SOS report: #{$!}")
    raise exception
  end

end
is_valid_case_number(case_num) click to toggle source
# File lib/redhat_access/sos_reports/generator.rb, line 51
def self.is_valid_case_number case_num
  if case_num.nil?
    return false
  end
  case_num.to_s =~ /\A\d+\z/ ? true : false
end