Class: Api::V2::AbrtReportsController

Inherits:
V2::BaseController
  • Object
show all
Includes:
AbrtReportsHelper, Api::Version2, Foreman::Controller::SmartProxyAuth
Defined in:
app/controllers/api/v2/abrt_reports_controller.rb

Instance Method Summary collapse

Methods included from AbrtReportsHelper

#count_abrt_reports, #format_reason, #render_abrt_graph, #send_to_abrt_server, #simple_format_if_multiline

Instance Method Details

#createObject



10
11
12
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
# File 'app/controllers/api/v2/abrt_reports_controller.rb', line 10

def create
  begin
    abrt_reports = AbrtReport.import(params[:abrt_report])
  rescue => e
    logger.error "Failed to import ABRT report: #{e.message}"
    logger.debug e.backtrace.join("\n")
    render :json => { 'message' => e.message }, :status => :unprocessable_entity
    return
  end

  if abrt_reports.count == 0
    render :json => { 'message' => 'Failed to import any report'}, :status => :unprocessable_entity
    return
  end

  if Setting[:abrt_automatically_forward]
    abrt_reports.each do |report|
      begin
        response = send_to_abrt_server report
        report.add_response response
      rescue => e
        logger.error "Failed to forward ABRT report: #{e.message}"
      end
    end
  end

  # Do not report forwarding error to the proxy, we can manually resend
  # it later and the proxy probably can't do anything about it anyway.
  render :json => { 'message' => 'OK' }
end