Module: CertBot::JsonGenerator

Defined in:
lib/cert_bot/json/json_generator.rb

Overview

Simple module to generate a JSON object with the relvevant information of an advisory item

Class Method Summary collapse

Class Method Details

.generate_json(item, output_path) ⇒ Object

Method to generate a JSON Object for the advisory item and write it to the config path

Parameters:

  • item (RSS:Item)

    an advisory item from the rss feed

  • output_path (Pathname)

    the path where the json object should be stored



13
14
15
16
17
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
# File 'lib/cert_bot/json/json_generator.rb', line 13

def self.generate_json(item, output_path)
  wid = item.link.split("=")[1]
  timestamp = item.pubDate.localtime
  update_status = CertBot::AdvisoryParser.retrieve_update_status(wid)
  cve_list = CertBot::AdvisoryParser.retrieve_cves(wid)
  cvss_entry = CertBot::AdvisoryParser.retrieve_cvss_score(wid)
  product_list = Array.new() 
  CertBot::AdvisoryParser.retrieve_affected_products(wid).each { |product|
    product_attributes = Hash.new()
    product_attributes["name"] = product["name"]
    product_attributes["cpeversion"] = product["cpeversion"]
    product_attributes["cpeproduct"] = product["cpeproduct"]
    product_list << product_attributes
  }
  
  json_hash = Hash.new()
  json_hash[:wid] = wid
  json_hash[:title] = item.title
  json_hash[:description] = item.description
  json_hash[:link] = item.link
  json_hash[:release] = timestamp
  json_hash[:status] = update_status
  json_hash[:cves] = cve_list
  json_hash[:cvss] = cvss_entry["temporalscore"]/10.0
  json_hash[:affected] = product_list
  json_hash[:severity] = item.category.content

  output_string = JSON.pretty_generate(json_hash)
  if (output_path != nil)
    file = File.open(File.join(output_path,"#{wid}_#{timestamp.strftime("%Y_%m_%d_%H")}.json"), "w")
    file.write(output_string)
    file.close
  end
  nil
end