foreman_rh_cloud 3.0.19 → 3.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -5
  3. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +50 -0
  4. data/app/controllers/concerns/inventory_upload/report_actions.rb +26 -0
  5. data/app/controllers/concerns/inventory_upload/task_actions.rb +25 -0
  6. data/app/controllers/foreman_inventory_upload/reports_controller.rb +3 -1
  7. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +5 -13
  8. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  9. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +18 -7
  10. data/app/controllers/insights_cloud/hits_controller.rb +42 -1
  11. data/app/controllers/insights_cloud/settings_controller.rb +1 -1
  12. data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
  13. data/app/helpers/foreman_insights_host_helper.rb +19 -0
  14. data/app/models/insights_client_report_status.rb +58 -0
  15. data/app/models/inventory_sync/inventory_status.rb +6 -0
  16. data/app/models/setting/rh_cloud.rb +5 -5
  17. data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
  18. data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
  19. data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
  20. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -6
  21. data/app/services/foreman_rh_cloud/remediations_retriever.rb +75 -0
  22. data/app/services/foreman_rh_cloud/template_renderer_helper.rb +22 -0
  23. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
  24. data/app/views/job_templates/rh_cloud_remediations.erb +14 -0
  25. data/config/package-lock.json.plugin +32774 -0
  26. data/config/routes.rb +20 -0
  27. data/db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb +10 -0
  28. data/db/seeds.d/179_ui_notifications.rb +11 -0
  29. data/db/seeds.d/50_job_templates.rb +14 -0
  30. data/lib/foreman_inventory_upload.rb +5 -1
  31. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
  32. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
  33. data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
  34. data/lib/foreman_inventory_upload/generators/slice.rb +6 -6
  35. data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
  36. data/lib/foreman_rh_cloud.rb +18 -0
  37. data/lib/foreman_rh_cloud/engine.rb +40 -2
  38. data/lib/foreman_rh_cloud/version.rb +1 -1
  39. data/lib/insights_cloud.rb +12 -0
  40. data/lib/insights_cloud/async/insights_full_sync.rb +31 -22
  41. data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
  42. data/lib/insights_cloud/async/insights_resolutions_sync.rb +66 -0
  43. data/lib/insights_cloud/async/insights_rules_sync.rb +15 -24
  44. data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
  45. data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
  46. data/lib/inventory_sync/async/inventory_hosts_sync.rb +6 -2
  47. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +29 -0
  48. data/lib/inventory_sync/async/query_inventory_job.rb +1 -4
  49. data/lib/tasks/insights.rake +4 -12
  50. data/lib/tasks/rh_cloud_inventory.rake +20 -5
  51. data/package.json +1 -1
  52. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
  53. data/test/factories/insights_factories.rb +22 -0
  54. data/test/factories/inventory_upload_factories.rb +1 -1
  55. data/test/jobs/insights_full_sync_test.rb +17 -8
  56. data/test/jobs/insights_resolutions_sync_test.rb +77 -0
  57. data/test/jobs/insights_rules_sync_test.rb +8 -3
  58. data/test/jobs/inventory_full_sync_test.rb +4 -1
  59. data/test/jobs/inventory_hosts_sync_test.rb +265 -0
  60. data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
  61. data/test/models/insights_client_report_status_test.rb +77 -0
  62. data/test/test_plugin_helper.rb +2 -0
  63. data/test/unit/rh_cloud_http_proxy_test.rb +4 -4
  64. data/test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb +49 -0
  65. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +28 -0
  66. data/test/unit/slice_generator_test.rb +66 -29
  67. data/test/unit/tags_generator_test.rb +10 -0
  68. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
  69. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
  70. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
  71. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +5 -3
  72. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +26 -2
  73. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +24 -2
  74. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +28 -63
  75. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
  76. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
  77. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
  78. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
  79. data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
  80. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
  81. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  82. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
  83. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  84. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +60 -0
  85. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationActions.js +12 -0
  86. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +43 -0
  87. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +101 -0
  88. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +9 -0
  89. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +43 -0
  90. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationTableConstants.js +38 -0
  91. data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +55 -0
  92. data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +34 -0
  93. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
  94. data/webpack/InsightsCloudSync/InsightsCloudSync.js +11 -3
  95. data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
  96. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
  97. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
  98. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
  99. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
  100. data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
  101. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
  102. data/webpack/common/ForemanTasks/index.js +1 -0
  103. data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
  104. data/webpack/common/table/helpers.js +7 -0
  105. metadata +49 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43110585639a77e33c9c4fb1fce44855b6fb4c9793db3fc624a01b567c09e400
4
- data.tar.gz: '00285b699105835e629127cc96801082ece7ff41c9a93d82fcb7e7a6b2662c65'
3
+ metadata.gz: 408212bb105f87e7d683c1c288f2b7d4b0c0c307a1b7e71c98433a15b8540ea5
4
+ data.tar.gz: 3fde56133d829bc2d77e2ce82dd09bf9a2f68482c761ae8527db93d62f47baba
5
5
  SHA512:
6
- metadata.gz: aa89cca9fb72a26453a44cba2120c51ab3f47f67ec40ca8e539a1dfaeddae73687bd909e3f3880cd3eed94c7c5d4b509bb55e2450f5bf4e55a8db2f73ceaabe9
7
- data.tar.gz: 33d4200395db6f2f9a0e2dbd8b27d8c55ff66d7da87efa9c9c39663468f0dd9c43c8949b0ce09b2158875d053375e39d03e4550b821732df4d49fb52f5872cb3
6
+ metadata.gz: 00c0437d4448aac1a2126fc7d4229983891520d82fe326edf1cb0b11b3498ddf995ebe3a7d35a9a6801e91d5577f5d7089e30026c458048c65bdc2d47749e538
7
+ data.tar.gz: f113f8f3e98a12fdc123890708795a7c89533f3af16808d2f6175948502be1991f4e652a635ec01638c4300890cb1f06ff89b5a1b63775421d85b918ebc23bca
data/README.md CHANGED
@@ -42,7 +42,7 @@ In UI: Configure -> Insights -> Sync now
42
42
 
43
43
  From command-line:
44
44
 
45
- /usr/sbin/foreman-rake rh_cloud_inventory:sync
45
+ /usr/sbin/foreman-rake rh_cloud_insights:sync
46
46
 
47
47
  #### Synchronize inventory status
48
48
 
@@ -51,16 +51,32 @@ In UI: Configure -> Inventory Upload -> Sync inventory status
51
51
  From command-line:
52
52
 
53
53
  # all organizations
54
- /usr/sbin/foreman-rake rh_cloud_insights:sync
55
-
54
+ /usr/sbin/foreman-rake rh_cloud_inventory:sync
55
+
56
56
  # specific organization with id 1
57
57
  export organization_id=1
58
- /usr/sbin/foreman-rake rh_cloud_insights:sync
58
+ /usr/sbin/foreman-rake rh_cloud_inventory:sync
59
59
 
60
60
  ## TODO
61
61
 
62
62
  *Todo list here*
63
63
 
64
+ ## Design
65
+
66
+ ### Endpoints
67
+
68
+ | purpose | url | ENV setting for the **bold** part
69
+ | ------------------------------| -------| -----------
70
+ | Inventory uploads | **https://cert.cloud.redhat.com/api/ingress/v1/upload** | SATELLITE_INVENTORY_UPLOAD_URL
71
+ | Query inventory hosts list | **https://cloud.redhat.com** /api/inventory/v1/hosts?tags= | SATELLITE_RH_CLOUD_URL
72
+ | Query insights hits | **https://cloud.redhat.com** /api/insights/v1/export/hits/ | SATELLITE_RH_CLOUD_URL
73
+ | Query insights rules | **https://cloud.redhat.com** /api/insights/v1/rule/?impacting=true&rule_status=enabled&has_playbook=true&limit=&offset= | SATELLITE_RH_CLOUD_URL
74
+ | Query insights resolutions | **https://cloud.redhat.com** /api/remediations/v1/resolutions| SATELLITE_RH_CLOUD_URL
75
+ | Forward insights-client `/static` requests | **https://cloud.redhat.com** /api/static | SATELLITE_RH_CLOUD_URL
76
+ | Forward insights-client legacy `/platform` requests | **https://cert.cloud.redhat.com** /api | SATELLITE_CERT_RH_CLOUD_URL
77
+ | Forward insights-client legacy `/redhat_access/r/insights` requests | **https://cert-api.access.redhat.com** /r/insights | SATELLITE_LEGACY_INSIGHTS_URL
78
+
79
+
64
80
  ## Contributing
65
81
 
66
82
  Fork and send a Pull Request. Thanks!
@@ -81,4 +97,3 @@ GNU General Public License for more details.
81
97
 
82
98
  You should have received a copy of the GNU General Public License
83
99
  along with this program. If not, see <http://www.gnu.org/licenses/>.
84
-
@@ -0,0 +1,50 @@
1
+ module Api
2
+ module V2
3
+ module RhCloud
4
+ class InventoryController < ::Api::V2::BaseController
5
+ include ::Api::Version2
6
+ include InventoryUpload::ReportActions
7
+ include InventoryUpload::TaskActions
8
+
9
+ api :GET, "/organizations/:organization_id/rh_cloud/report", N_("Download latest report")
10
+ def download_file
11
+ filename, file = report_file(params[:organization_id])
12
+
13
+ send_file file, disposition: 'attachment', filename: filename
14
+ rescue InventoryUpload::ReportActions::ReportMissingError => error
15
+ render json: { message: error.message }, status: :not_found
16
+ end
17
+
18
+ api :POST, "/organizations/:organization_id/rh_cloud/report", N_("Start report generation")
19
+ def generate_report
20
+ organization_id = params[:organization_id]
21
+
22
+ start_report_generation(organization_id)
23
+
24
+ render json: {
25
+ action_status: 'success',
26
+ }, status: :ok
27
+ end
28
+
29
+ api :POST, "/organizations/:organization_id/rh_cloud/inventory_sync", N_("Start inventory synchronization")
30
+ def sync_inventory_status
31
+ selected_org = Organization.find(params[:organization_id])
32
+
33
+ task = start_inventory_sync(selected_org)
34
+
35
+ render json: {
36
+ task: task,
37
+ }, status: :ok
38
+ rescue InventoryUpload::TaskActions::NothingToSyncError => error
39
+ render json: { message: error.message }, status: :bad_request
40
+ end
41
+
42
+ api :POST, "rh_cloud/enable_connector", N_("Enable cloud connector")
43
+ def enable_cloud_connector
44
+ cloud_connector = ForemanRhCloud::CloudConnector.new
45
+ render json: cloud_connector.install.to_json
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ module InventoryUpload
2
+ module ReportActions
3
+ extend ActiveSupport::Concern
4
+
5
+ class ReportMissingError < Foreman::Exception
6
+ MESSAGE = N_("The report file %{filename} doesn't exist")
7
+
8
+ def initialize(**params)
9
+ super(self.class::MESSAGE % params, params)
10
+ end
11
+ end
12
+
13
+ def start_report_generation(organization_id)
14
+ ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
15
+ end
16
+
17
+ def report_file(organization_id)
18
+ filename = ForemanInventoryUpload.facts_archive_name(organization_id)
19
+ files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
20
+
21
+ raise ReportMissingError.new(filename: filename) if files.empty?
22
+
23
+ [filename, files.first]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module InventoryUpload
2
+ module TaskActions
3
+ extend ActiveSupport::Concern
4
+
5
+ class NothingToSyncError < Foreman::Exception
6
+ MESSAGE = N_('Nothing to sync, there are no hosts with subscription for this organization.')
7
+
8
+ def initialize(**params)
9
+ super(self.class::MESSAGE, params)
10
+ end
11
+ end
12
+
13
+ def start_inventory_sync(selected_org)
14
+ subscribed_hosts = ForemanInventoryUpload::Generators::Queries.for_slice(
15
+ Host.unscoped.where(organization: selected_org)
16
+ )
17
+
18
+ if subscribed_hosts.empty?
19
+ raise NothingToSyncError
20
+ end
21
+
22
+ ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module ForemanInventoryUpload
4
4
  class ReportsController < ::ApplicationController
5
+ include InventoryUpload::ReportActions
6
+
5
7
  def last
6
8
  label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
7
9
  output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
@@ -20,7 +22,7 @@ module ForemanInventoryUpload
20
22
  def generate
21
23
  organization_id = params[:organization_id]
22
24
 
23
- ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
25
+ start_report_generation(organization_id)
24
26
 
25
27
  render json: {
26
28
  action_status: 'success',
@@ -1,25 +1,17 @@
1
1
  module ForemanInventoryUpload
2
2
  class TasksController < ::ApplicationController
3
+ include InventoryUpload::TaskActions
4
+
3
5
  def create
4
6
  selected_org = Organization.current
5
- subscribed_hosts_ids = Set.new(
6
- ForemanInventoryUpload::Generators::Queries.for_slice(
7
- Host.unscoped.where(organization: selected_org)
8
- ).pluck(:id)
9
- )
10
7
 
11
- if subscribed_hosts_ids.empty?
12
- return render json: {
13
- message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
14
- }, status: :method_not_allowed
15
- else
16
- task = ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
17
- end
18
- return render json: { message: N_('there was an issue triggering the task') }, status: :internal_server_error unless task
8
+ task = start_inventory_sync(selected_org)
19
9
 
20
10
  render json: {
21
11
  task: task,
22
12
  }, status: :ok
13
+ rescue InventoryUpload::TaskActions::NothingToSyncError => error
14
+ render json: { message: error.message }, status: :internal_server_error
23
15
  end
24
16
 
25
17
  def show
@@ -1,5 +1,7 @@
1
1
  module ForemanInventoryUpload
2
2
  class UploadsController < ::ApplicationController
3
+ include InventoryUpload::ReportActions
4
+
3
5
  def last
4
6
  label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
5
7
  output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
@@ -10,11 +12,9 @@ module ForemanInventoryUpload
10
12
  end
11
13
 
12
14
  def download_file
13
- filename = ForemanInventoryUpload.facts_archive_name(params[:organization_id])
14
- files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
15
+ filename, file = report_file(params[:organization_id])
15
16
 
16
- return send_file files.first, disposition: 'attachment', filename: filename unless files.empty?
17
- raise ::Foreman::Exception.new("The report file doesn't exist")
17
+ send_file file, disposition: 'attachment', filename: filename
18
18
  end
19
19
 
20
20
  def enable_cloud_connector
@@ -5,32 +5,34 @@ module InsightsCloud::Api
5
5
  include ::InsightsCloud::ClientAuthentication
6
6
  include ::InsightsCloud::CandlepinCache
7
7
 
8
+ before_action :set_admin_user, only: [:forward_request]
8
9
  before_action :cert_uuid, :ensure_org, :ensure_branch_id, :only => [:forward_request, :branch_info]
9
10
  before_action :ensure_telemetry_enabled_for_consumer, :only => [:forward_request]
10
11
 
11
12
  skip_after_action :log_response_body, :only => [:forward_request]
12
13
  skip_before_action :check_media_type, :only => [:forward_request]
14
+ after_action :update_host_insights_status, only: [:forward_request]
13
15
 
14
16
  # The method that "proxies" requests over to Cloud
15
17
  def forward_request
16
18
  certs = candlepin_id_cert @organization
17
- cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
19
+ @cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
18
20
 
19
- if cloud_response.code == 401
21
+ if @cloud_response.code == 401
20
22
  return render json: {
21
23
  :message => 'Authentication to the Insights Service failed.',
22
24
  :headers => {},
23
25
  }, status: :bad_gateway
24
26
  end
25
27
 
26
- if cloud_response.headers[:content_disposition]
27
- return send_data cloud_response, disposition: cloud_response.headers[:content_disposition], type: cloud_response.headers[:content_type]
28
+ if @cloud_response.headers[:content_disposition]
29
+ return send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
28
30
  end
29
31
 
30
- assign_header(response, cloud_response, :x_resource_count, true)
31
- assign_header(response, cloud_response, :x_rh_insights_request_id, false)
32
+ assign_header(response, @cloud_response, :x_resource_count, true)
33
+ assign_header(response, @cloud_response, :x_rh_insights_request_id, false)
32
34
 
33
- render json: cloud_response, status: cloud_response.code
35
+ render json: @cloud_response, status: @cloud_response.code
34
36
  end
35
37
 
36
38
  def branch_info
@@ -69,5 +71,14 @@ module InsightsCloud::Api
69
71
  @branch_id = cp_owner_id(@organization)
70
72
  return render_message "Branch ID not found for organization #{@organization.title}", :status => 400 unless @branch_id
71
73
  end
74
+
75
+ def update_host_insights_status
76
+ return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
77
+ request.path.include?('/redhat_access/r/insights/uploads/')
78
+
79
+ data = @cloud_response.code.to_s.start_with?('2')
80
+ host_status = @host.get_status(InsightsClientReportStatus)
81
+ host_status.update(reported_at: Time.now.utc, status: host_status.to_status(data: data))
82
+ end
72
83
  end
73
84
  end
@@ -3,12 +3,13 @@ module InsightsCloud
3
3
  include Foreman::Controller::AutoCompleteSearch
4
4
 
5
5
  def index
6
- hits = resource_base_search_and_page.where(host: Host.authorized).preload(:host, :rule)
6
+ hits = resource_base_search_and_page.preload(:host, :rule)
7
7
 
8
8
  render json: {
9
9
  hasToken: !Setting[:rh_cloud_token].empty?,
10
10
  hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, has_playbook: hit.has_playbook?) },
11
11
  itemCount: hits.count,
12
+ isExperimentalMode: Setting[:lab_features],
12
13
  }, status: :ok
13
14
  end
14
15
 
@@ -20,6 +21,21 @@ module InsightsCloud
20
21
  }, status: :ok
21
22
  end
22
23
 
24
+ def resolutions
25
+ if remediation_all_selected_param
26
+ hits = resource_base.with_playbook.search_for(params[:query])
27
+ else
28
+ hits = resource_base_search_and_page.with_playbook.where(id: remediation_ids_param)
29
+ end
30
+
31
+ hits.preload(:host, rule: :resolutions)
32
+
33
+ render json: {
34
+ hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, resolutions: hit.rule.resolutions.map(&:attributes), reboot: hit.rule.reboot_required) },
35
+ itemCount: hits.count,
36
+ }, status: :ok
37
+ end
38
+
23
39
  def model_of_controller
24
40
  ::InsightsHit
25
41
  end
@@ -32,10 +48,35 @@ module InsightsCloud
32
48
  :insights_hits
33
49
  end
34
50
 
51
+ def action_permission
52
+ case params[:action]
53
+ when 'resolutions'
54
+ 'view'
55
+ else
56
+ super
57
+ end
58
+ end
59
+
35
60
  private
36
61
 
37
62
  def host_id_param
38
63
  params.require(:host_id)
39
64
  end
65
+
66
+ def remediation_request_params
67
+ params.permit(remediations: [:hit_id, :remediation_id]).require(:remediations)
68
+ end
69
+
70
+ def remediation_ids_param
71
+ params.require(:ids).map(&:to_i)
72
+ end
73
+
74
+ def remediation_all_selected_param
75
+ ActiveModel::Type::Boolean.new.cast(params[:isAllSelected])
76
+ end
77
+
78
+ def resource_base
79
+ super.where(host: Host.authorized)
80
+ end
40
81
  end
41
82
  end
@@ -13,7 +13,7 @@ module InsightsCloud
13
13
  token = Setting::RhCloud.find_by_name("rh_cloud_token")
14
14
  token.value = params.require(:value)
15
15
  token.save!
16
- InsightsCloud::Async::InsightsFullSync.perform_now
16
+ ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
17
17
  redirect_to(:controller => "hits", :action => 'index')
18
18
  end
19
19
 
@@ -1,8 +1,7 @@
1
1
  module InsightsCloud
2
2
  class TasksController < ::ApplicationController
3
3
  def create
4
- job = InsightsCloud::Async::InsightsFullSync.perform_later
5
- task = ForemanTasks::Task.find_by(external_id: job.provider_job_id)
4
+ task = ForemanTasks.async_task(InsightsCloud::Async::InsightsFullSync)
6
5
 
7
6
  render json: {
8
7
  task: task,
@@ -0,0 +1,19 @@
1
+ module ForemanInsightsHostHelper
2
+ def insights_host_overview_buttons(host)
3
+ search_condition = "hostname=#{host.fqdn}"
4
+ [
5
+ {
6
+ button: link_to_if_authorized(
7
+ _("Recommendations"),
8
+ hash_for_foreman_rh_cloud_insights_cloud_path(
9
+ search: search_condition,
10
+ select_all: true
11
+ ),
12
+ title: _("Host Insights recommendations"),
13
+ class: 'btn btn-default'
14
+ ),
15
+ priority: 1000,
16
+ },
17
+ ]
18
+ end
19
+ end
@@ -0,0 +1,58 @@
1
+ class InsightsClientReportStatus < HostStatus::Status
2
+ REPORT_INTERVAL = 48.hours
3
+
4
+ REPORTING = 0 # host_registration_insights = true & getting data
5
+ NO_REPORT = 1 # host_registration_insights = true & not getting data
6
+ NOT_MANAGED = 2 # host_registration_insights = false
7
+ NOT_MANAGED_WITH_DATA = 3 # host_registration_insights = false & getting data
8
+
9
+ def self.status_name
10
+ N_('Insights')
11
+ end
12
+
13
+ def to_label(_options = {})
14
+ case status
15
+ when REPORTING
16
+ N_('Reporting')
17
+ when NO_REPORT
18
+ N_('Not reporting')
19
+ when NOT_MANAGED
20
+ N_('Not reporting (not set by registration)')
21
+ when NOT_MANAGED_WITH_DATA
22
+ N_('Reporting (not set by registration)')
23
+ end
24
+ end
25
+
26
+ def to_global(_options = {})
27
+ case status
28
+ when REPORTING
29
+ ::HostStatus::Global::OK
30
+ when NO_REPORT
31
+ ::HostStatus::Global::ERROR
32
+ when NOT_MANAGED
33
+ ::HostStatus::Global::OK
34
+ when NOT_MANAGED_WITH_DATA
35
+ ::HostStatus::Global::WARN
36
+ end
37
+ end
38
+
39
+ def to_status(data: false)
40
+ if insights_param
41
+ return REPORTING if data
42
+ return in_interval? ? REPORTING : NO_REPORT
43
+ end
44
+
45
+ data ? NOT_MANAGED_WITH_DATA : NOT_MANAGED
46
+ end
47
+
48
+ private
49
+
50
+ def in_interval?
51
+ return false unless reported_at
52
+ (Time.now.utc - reported_at).to_i < REPORT_INTERVAL.to_i
53
+ end
54
+
55
+ def insights_param
56
+ host.host_params_hash.dig('host_registration_insights', :value)
57
+ end
58
+ end