Class: AbrtReport

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Authorizable
Defined in:
app/models/abrt_report.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.import(json) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/abrt_report.rb', line 42

def self.import(json)
  host = Host.find_by_name(json[:host])
  reports = []

  json[:reports].each do |report|
    begin
      reports << AbrtReport.create!(:host => host, :count => report[:count], :json => report[:full].to_json,
                                    :duphash => report[:duphash], :reason => report[:full][:reason],
                                    :reported_at => report[:reported_at])
    rescue => e
      logger.error "Failed to import ABRT report from #{host}: #{e.class}:#{e.message}"
    end
  end

  reports
end

Instance Method Details

#add_response(response) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/abrt_report.rb', line 59

def add_response(response)
  self.transaction do
    abrt_report_response_solutions.clear
    abrt_report_response_destinations.clear

    self.forwarded_at = Time.now
    self.response_known = response['result']
    self.response_message = response['message']
    self.response_bthash = response['bthash']

    if response['solutions']
      response['solutions'].each do |solution|
        abrt_report_response_solutions.create!(
          :cause => solution['cause'],
          :note => solution['note'],
          :url => solution['url']
        )
      end
    end

    if response['reported_to']
      response['reported_to'].each do |destination|
        abrt_report_response_destinations.create!(
          :desttype => destination['type'],
          :value => destination['value'],
          :reporter => destination['reporter']
        )
      end
    end

    save!
  end
end