Skip to content

Commit

Permalink
Add new endpoint for host insights details
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Dec 19, 2024
1 parent 1d61d10 commit e4a1d20
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Api
module V2
module InsightsAdvisor
class InsightsAdvisorController < ::Api::V2::BaseController
include ::Api::Version2

before_action :find_organization

def host_details
@hosts = ::Host::Managed.search_for(params[:search] || "", :order => params[:order]).where(:organization_id => @organization.id).includes(:insights)
respond_to do |format|
format.json { render 'api/v2/insights_advisor/host_details' }
end
end

private

def find_organization
@organization ||= Organization.find_by(label: params[:organization_label]) if params[:organization_label]
@organization ||= Organization.find_by(label: params[:organization]) if params[:organization]
@organization ||= Organization.find(params[:organization_id]) if params[:organization_id]
raise ::Foreman::Exception.new(N_("Organization not found")) unless @organization
end
end
end
end
end
9 changes: 9 additions & 0 deletions app/views/api/v2/insights_advisor/host_details.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
collection @hosts

attributes :name
node :insights_uuid do |host|
host.insights_facet&.uuid
end
node :insights_hit_details do |host|
host&.facts('insights::hit_details')&.values&.first
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@

post 'cloud_request', to: 'cloud_request#update'
end

namespace 'insights_advisor' do
get 'host_details', to: 'insights_advisor#host_details'
# post 'upload_hits', to: 'insights_advisor#upload_hits'
end
end
end
end

0 comments on commit e4a1d20

Please sign in to comment.