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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/abrt_report.rb', line 42

def self.import(json)
  reports = []
  host    = Host.find_by_name(json[:host]) || Host.joins(:provision_interface).where({:nics => {:ip => json[:host]}}).try(:first)

  # If the host lookup failed, it is possible that we are using subscription management certificates which
  # have UUID in their CN instead of host's FQDN. Try asking Katello if it knows host with such UUID.
  if host.nil? && defined?(::Katello::System) && content_host = ::Katello::System.find_by_uuid(json[:host])
      host = content_host.foreman_host
  end

  # The subscription management certificate also has (what is likely) FQDN in the subjectAltName certificate field.
  # Try finding such host as a last resort.
  if host.nil? && !json[:althosts].nil?
    json[:althosts].each do |hostname|
      host = Host.find_by_name(hostname)
      break unless host.nil?
    end
  end

  if host.nil?
    logger.error "Unable to find host #{json[:host]}"
    return []
  end

  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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/abrt_report.rb', line 79

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