Class: Proxy::OpenSCAP::Parse

Inherits:
Object
  • Object
show all
Includes:
Log, Util
Defined in:
lib/smart_proxy_openscap/openscap_report_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(cname, policy_id, date) ⇒ Parse

Returns a new instance of Parse.



10
11
12
13
14
# File 'lib/smart_proxy_openscap/openscap_report_parser.rb', line 10

def initialize(cname, policy_id, date)
  @cname = cname
  @policy_id = policy_id
  @date = date
end

Instance Method Details

#as_json(arf_data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smart_proxy_openscap/openscap_report_parser.rb', line 16

def as_json(arf_data)
  in_file = Tempfile.new("#{filename}json-", "/var/tmp")
  json_file = Tempfile.new(filename, "/var/tmp")
  begin
    in_file.write arf_data
    command = "#{script_location} #{in_file.path} #{json_file.path}"
    logger.debug "Executing: #{command}"
    `#{command}`
    json_file.read
  rescue => e
    logger.debug "Failure when running script which parses reports"
    logger.debug e.backtrace.join("\n\t")
    return nil
  ensure
    in_file.close
    in_file.unlink
    json_file.close
    json_file.unlink
  end
end

#filename ⇒ Object



37
38
39
# File 'lib/smart_proxy_openscap/openscap_report_parser.rb', line 37

def filename
  "#{@cname}-#{@policy_id}-#{@date}-"
end

#script_location ⇒ Object



41
42
43
44
45
# File 'lib/smart_proxy_openscap/openscap_report_parser.rb', line 41

def script_location
  path = File.join(File.dirname(File.expand_path(__FILE__)), '../..','bin/smart-proxy-parse-arf')
  return path if File.exist? path
  "smart-proxy-parse-arf"
end