Class: Api::V2::AdvisorEngine::AdvisorEngineController

Inherits:
BaseController
  • Object
show all
Includes:
Api::Version2, Foreman::Controller::FilterParameters, Foreman::Controller::SmartProxyAuth
Defined in:
app/controllers/api/v2/advisor_engine/advisor_engine_controller.rb

Instance Method Summary collapse

Instance Method Details

#host_detailsObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/api/v2/advisor_engine/advisor_engine_controller.rb', line 14

def host_details
  uuids = params.require(:host_uuids)
  @hosts = ::Host.joins(:insights).where(:insights => { :uuid => uuids })
  if @hosts.empty?
    render json: { error: 'No hosts found for the given UUIDs' }, status: :not_found
  else
    respond_to do |format|
      format.json { render 'api/v2/advisor_engine/host_details' }
    end
  end
end

#payload_paramsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/api/v2/advisor_engine/advisor_engine_controller.rb', line 78

def payload_params
  params.require(:payload).permit(
    :details,
    {
      resolutions: [
        :rule_id, :description, :needs_reboot, :resolution_risk, :resolution_type
      ],
      rules: [
        :rule_id, :description, :category_name, :impact_name, :summary, :generic,
        :reason, :total_risk, :reboot_required, :more_info, :rating
      ],
      hits: [
        :rule_id, :title, :solution_url, :total_risk, :likelihood, :publish_date, :results_url
      ],
    }
  )
end

#upload_hitsObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/api/v2/advisor_engine/advisor_engine_controller.rb', line 65

def upload_hits
  host = Host.find_by(name: params.require(:host_name))
  if host.blank?
    render json: { error: 'No host found for the given host name' }, status: :not_found
  else
    hits_uploader = ForemanRhCloud::HitsUploader.new(host: host, payload: payload_params.to_h, uuid: params[:host_uuid])
    hits_uploader.upload!
    render json: {
      action_status: 'success',
    }, status: :ok
  end
end