Class: RedhatAccess::SosReports::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/redhat_access/sos_reports/generator.rb

Class Method Summary collapse

Class Method Details

.create_report(case_num) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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) ⇒ Object



51
52
53
54
55
56
# 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