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
- .create_product_list(products) ⇒ Object private
-
.generate_json(item, output_path) ⇒ Object
Method to generate a JSON Object for the advisory item and write it to the config path.
Class Method Details
.create_product_list(products) ⇒ Object (private)
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cert_bot/json/json_generator.rb', line 42 private_class_method def self.create_product_list(products) product_list = Array.new() products.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 } product_list end |
.generate_json(item, output_path) ⇒ Object
Method to generate a JSON Object for the advisory item and write it to the config path
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 |
# File 'lib/cert_bot/json/json_generator.rb', line 13 def self.generate_json(item, output_path) wid = item.link.split("=")[1] = item.pubDate.localtime cvss_entry = CertBot::AdvisoryParser.retrieve_cvss_score(wid) fixed_list = create_product_list(CertBot::AdvisoryParser.retrieve_fixed_products(wid)) fixed_list << "none" if (fixed_list.empty?) 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] = json_hash[:status] = CertBot::AdvisoryParser.retrieve_update_status(wid) json_hash[:cves] = CertBot::AdvisoryParser.retrieve_cves(wid) json_hash[:cvss] = cvss_entry["temporalscore"]/10.0 json_hash[:affected] = create_product_list(CertBot::AdvisoryParser.retrieve_affected_products(wid)) json_hash[:fixed] = fixed_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}_#{.strftime("%Y_%m_%d_%H")}.json"), "w") file.write(output_string) file.close end nil end |