foreman_rh_cloud 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -0
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +25 -0
- data/app/controllers/insights_cloud/settings_controller.rb +24 -0
- data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
- data/app/helpers/foreman_inventory_upload_host_helper.rb +10 -1
- data/app/models/insights_facet.rb +5 -1
- data/app/models/inventory_sync/inventory_status.rb +30 -0
- data/app/models/setting/rh_cloud.rb +1 -0
- data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -1
- data/config/routes.rb +3 -0
- data/db/migrate/20200727111529_add_uuid_column_to_insights_facets.foreman_rh_cloud.rb +5 -0
- data/lib/foreman_inventory_upload.rb +4 -0
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -1
- data/lib/foreman_inventory_upload/generators/slice.rb +25 -3
- data/lib/foreman_rh_cloud.rb +13 -0
- data/lib/foreman_rh_cloud/engine.rb +7 -1
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +8 -8
- data/lib/insights_cloud/async/insights_full_sync.rb +17 -10
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +23 -0
- data/lib/inventory_sync/async/host_result.rb +50 -0
- data/lib/inventory_sync/async/inventory_full_sync.rb +99 -0
- data/test/controllers/insights_sync/settings_controller_test.rb +30 -0
- data/test/factories/insights_factories.rb +31 -0
- data/test/jobs/insights_full_sync_test.rb +4 -2
- data/test/jobs/inventory_full_sync_test.rb +91 -0
- data/test/unit/insights_facet_test.rb +16 -0
- data/test/unit/slice_generator_test.rb +15 -7
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +3 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +2 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +5 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +15 -13
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +6 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +3 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +52 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +59 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +36 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +9 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +33 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +36 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +26 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +36 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +18 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +63 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +41 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/modal.scss +20 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +22 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +6 -1
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +3 -1
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +2 -0
- data/webpack/ForemanRhCloudPages.js +7 -0
- data/webpack/ForemanRhCloudTestHelpers.js +12 -3
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +33 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +60 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +10 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +28 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsSelectors.js +6 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettings.test.js +18 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +46 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +56 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsSelectors.test.js +21 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +15 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +31 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +33 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsSelectors.test.js.snap +9 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/index.js +21 -0
- data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +16 -0
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +1 -0
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +45 -0
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +17 -0
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +38 -0
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +1 -0
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +3 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +32 -28
- data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +7 -2
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +49 -44
- data/webpack/InsightsCloudSync/index.js +2 -1
- data/webpack/__mocks__/foremanReact/constants.js +5 -0
- data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
- data/webpack/__tests__/ForemanRhCloudSelectors.test.js +4 -1
- data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +12 -2
- data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +9 -9
- data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +24 -2
- data/webpack/index.js +2 -12
- metadata +59 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1ed5e65ca0dd0c2515ab70dcffa4ba5bb480a822b822d122ab6b126a5ec242
|
4
|
+
data.tar.gz: 9e7f83b694de9ffe66da0f86c781f869161c93aa92c426a16bb319601bc407f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33c3a9d35df67a9c7217d385ccb035673795ac0200c3aac6bc7695e28fd6360a737832ac929d010c866af71ab8e2a54ce11947c2aacd3135a1959326e1469ba2
|
7
|
+
data.tar.gz: e41fd42b654ba57a64fac11e6b77ab5caa55a511a3dfc5371ef329904f7c9989562aedb7d3f52044d28f744691f5795e4b45addbeba4015ae4094fb28942a0cc
|
@@ -23,6 +23,7 @@ module ForemanInventoryUpload
|
|
23
23
|
render json: {
|
24
24
|
autoUploadEnabled: Setting[:allow_auto_inventory_upload],
|
25
25
|
hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
|
26
|
+
cloudToken: Setting[:rh_cloud_token],
|
26
27
|
accounts: accounts,
|
27
28
|
}, status: :ok
|
28
29
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
class TasksController < ::ApplicationController
|
3
|
+
def create
|
4
|
+
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
|
+
|
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
|
+
host_statuses = InventorySync::Async::InventoryFullSync.perform_now(selected_org)
|
17
|
+
end
|
18
|
+
|
19
|
+
render json: {
|
20
|
+
syncHosts: host_statuses[:sync],
|
21
|
+
disconnectHosts: host_statuses[:disconnect],
|
22
|
+
}, status: :ok
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module InsightsCloud
|
2
|
+
class SettingsController < ::ApplicationController
|
3
|
+
def show
|
4
|
+
render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
|
5
|
+
end
|
6
|
+
|
7
|
+
def update
|
8
|
+
Setting[:allow_auto_insights_sync] = settings_params
|
9
|
+
render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def render_setting(node_name, setting)
|
15
|
+
render json: {
|
16
|
+
node_name => Setting[setting],
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def settings_params
|
21
|
+
ActiveModel::Type::Boolean.new.cast(params.require(:insightsSyncEnabled))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -6,6 +6,15 @@ module ForemanInventoryUploadHostHelper
|
|
6
6
|
def hits_counts_cell(host)
|
7
7
|
host_hits = hits_counts[host.id]
|
8
8
|
content = n_('One recommendation', '%{hits} recommendations', host_hits) % { hits: host_hits } if host_hits
|
9
|
-
tag.td
|
9
|
+
tag.td class: ['hidden-xs', 'ellipsis'] do
|
10
|
+
if host_hits
|
11
|
+
link_to(
|
12
|
+
content,
|
13
|
+
InsightsCloud::WebUi.system_url(InsightsCloud::WebUi::ADVISOR, host.insights.uuid),
|
14
|
+
:rel => 'external noopener noreferrer',
|
15
|
+
:target => '_blank'
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
10
19
|
end
|
11
20
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module InventorySync
|
2
|
+
class InventoryStatus < HostStatus::Status
|
3
|
+
DISCONNECT = 0
|
4
|
+
SYNC = 1
|
5
|
+
|
6
|
+
def self.status_name
|
7
|
+
N_('Inventory')
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_global(_options = {})
|
11
|
+
case status
|
12
|
+
when DISCONNECT
|
13
|
+
::HostStatus::Global::WARN
|
14
|
+
when SYNC
|
15
|
+
::HostStatus::Global::OK
|
16
|
+
else
|
17
|
+
::HostStatus::Global::WARN
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_label
|
22
|
+
case status
|
23
|
+
when DISCONNECT
|
24
|
+
N_('Host was not uploaded to your RH cloud inventory')
|
25
|
+
when SYNC
|
26
|
+
N_('Successfully uploaded to your RH cloud inventory')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -6,6 +6,7 @@ class Setting::RhCloud < Setting
|
|
6
6
|
transaction do
|
7
7
|
[
|
8
8
|
set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), false),
|
9
|
+
set('allow_auto_insights_sync', N_('Allow recommendations synchronization from Red Hat cloud'), false),
|
9
10
|
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false),
|
10
11
|
set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), 'DEFAULT', N_('Red Hat Cloud token'), nil, encrypted: true),
|
11
12
|
].each { |s| create! s.update(:category => 'Setting::RhCloud')}
|
@@ -1 +1 @@
|
|
1
|
-
<%= mount_react_component(
|
1
|
+
<%= mount_react_component('ForemanInventoryUpload', '#ForemanRhCloudReactRoot') %>
|
data/config/routes.rb
CHANGED
@@ -8,10 +8,13 @@ Rails.application.routes.draw do
|
|
8
8
|
get 'auto_upload', to: 'uploads#show_auto_upload'
|
9
9
|
post 'auto_upload', to: 'uploads#auto_upload'
|
10
10
|
post 'host_obfuscation', to: 'uploads#host_obfuscation'
|
11
|
+
|
12
|
+
resources :tasks, only: [:create]
|
11
13
|
end
|
12
14
|
|
13
15
|
namespace :insights_cloud do
|
14
16
|
resources :tasks, only: [:create]
|
17
|
+
resource :settings, only: [:show, :update]
|
15
18
|
end
|
16
19
|
|
17
20
|
namespace :foreman_rh_cloud do
|
@@ -3,6 +3,8 @@ module ForemanInventoryUpload
|
|
3
3
|
class Slice
|
4
4
|
include FactHelpers
|
5
5
|
|
6
|
+
SATELLITE_NAMESPACE = 'satellite'
|
7
|
+
|
6
8
|
attr_accessor :slice_id
|
7
9
|
attr_reader :hosts_count
|
8
10
|
|
@@ -52,7 +54,7 @@ module ForemanInventoryUpload
|
|
52
54
|
end
|
53
55
|
@stream.array_field('facts') do
|
54
56
|
@stream.object do
|
55
|
-
@stream.simple_field('namespace',
|
57
|
+
@stream.simple_field('namespace', SATELLITE_NAMESPACE)
|
56
58
|
@stream.object_field('facts', :last) do
|
57
59
|
report_satellite_facts(host)
|
58
60
|
end
|
@@ -60,8 +62,15 @@ module ForemanInventoryUpload
|
|
60
62
|
end
|
61
63
|
|
62
64
|
@stream.array_field('tags', :last) do
|
63
|
-
|
64
|
-
|
65
|
+
report_satellite_tag('satellite_instance_id', Foreman.instance_id) if Foreman.respond_to?(:instance_id)
|
66
|
+
report_satellite_tag('lifecycle_environment', host.lifecycle_environment&.name)
|
67
|
+
report_satellite_tag('content_view', host.content_view&.name)
|
68
|
+
report_satellite_tag('activation_key', host.activation_keys) { |key| key.name }
|
69
|
+
report_satellite_tag('host_collection', host.host_collections) { |collection| collection.name }
|
70
|
+
report_satellite_tag('location', host.location.name)
|
71
|
+
report_satellite_tag('organization', host.organization.name)
|
72
|
+
report_satellite_tag('hostgroup', host.hostgroup&.name)
|
73
|
+
report_satellite_tag('organization_id', host.organization_id.to_s, :last)
|
65
74
|
end
|
66
75
|
end
|
67
76
|
end
|
@@ -75,6 +84,18 @@ module ForemanInventoryUpload
|
|
75
84
|
@stream.comma unless last
|
76
85
|
end
|
77
86
|
|
87
|
+
def report_satellite_tag(key, value, last = nil)
|
88
|
+
return if value.nil?
|
89
|
+
|
90
|
+
array_value = Array(value)
|
91
|
+
last_index = array_value.count - 1
|
92
|
+
|
93
|
+
array_value.each_with_index do |value, index|
|
94
|
+
value = yield(value) if block_given?
|
95
|
+
report_tag(SATELLITE_NAMESPACE, key, value, last && index == last_index)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
78
99
|
def report_system_profile(host)
|
79
100
|
@stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)').to_i)
|
80
101
|
@stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)').to_i)
|
@@ -146,6 +167,7 @@ module ForemanInventoryUpload
|
|
146
167
|
end
|
147
168
|
@stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
|
148
169
|
@stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
|
170
|
+
@stream.simple_field('system_purpose_sla', host.subscription_facet.service_level)
|
149
171
|
@stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
|
150
172
|
@stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
|
151
173
|
@stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
|
data/lib/foreman_rh_cloud.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
require 'foreman_rh_cloud/engine.rb'
|
2
2
|
|
3
3
|
module ForemanRhCloud
|
4
|
+
def self.base_url
|
5
|
+
# for testing set ENV to 'https://ci.cloud.redhat.com'
|
6
|
+
@base_url ||= ENV['SATELLITE_RH_CLOUD_URL'] || 'https://cloud.redhat.com'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.authentication_url
|
10
|
+
# https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
|
11
|
+
@authentication_url ||= ENV['SATELLITE_RH_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.verify_ssl_method
|
15
|
+
@verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
|
16
|
+
end
|
4
17
|
end
|
@@ -57,8 +57,13 @@ module ForemanRhCloud
|
|
57
57
|
menu :top_menu, :inventory_upload, :caption => N_('Inventory Upload'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :inventory_upload}, parent: :configure_menu
|
58
58
|
menu :top_menu, :insights_hits_import, :caption => N_('Insights'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :insights_cloud }, parent: :configure_menu
|
59
59
|
|
60
|
-
register_facet InsightsFacet, :insights
|
60
|
+
register_facet InsightsFacet, :insights do
|
61
|
+
set_dependent_action :destroy
|
62
|
+
end
|
63
|
+
|
61
64
|
register_global_js_file 'subscriptions_extension'
|
65
|
+
|
66
|
+
register_custom_status(InventorySync::InventoryStatus)
|
62
67
|
end
|
63
68
|
|
64
69
|
::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
|
@@ -68,6 +73,7 @@ module ForemanRhCloud
|
|
68
73
|
unless Rails.env.test?
|
69
74
|
ForemanTasks.dynflow.config.on_init do |world|
|
70
75
|
ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
|
76
|
+
InsightsCloud::Async::InsightsScheduledSync.spawn_if_missing(world)
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
data/lib/insights_cloud.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module InsightsCloud
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module WebUi
|
3
|
+
ADVISOR = 'advisor'
|
4
|
+
VULNERABILITY = 'vulnerability'
|
5
|
+
PATCH = 'patch'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def self.system_url(subsystem, host_uuid)
|
8
|
+
ForemanRhCloud.base_url + "/insights/#{subsystem}/systems/#{host_uuid}"
|
9
|
+
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.hits_export_url
|
13
|
-
base_url + '/api/insights/v1/export/hits/'
|
13
|
+
ForemanRhCloud.base_url + '/api/insights/v1/export/hits/'
|
14
14
|
end
|
15
15
|
end
|
@@ -3,13 +3,11 @@ require 'rest-client'
|
|
3
3
|
module InsightsCloud
|
4
4
|
module Async
|
5
5
|
class InsightsFullSync < ::ApplicationJob
|
6
|
-
def perform
|
7
|
-
@organization = organization
|
8
|
-
|
6
|
+
def perform
|
9
7
|
hits = query_insights_hits
|
10
8
|
|
11
|
-
|
12
|
-
setup_host_names(
|
9
|
+
@hits_host_names = Hash[hits.map { |hit| [hit['hostname'], hit['uuid']] }]
|
10
|
+
setup_host_names(@hits_host_names.keys)
|
13
11
|
|
14
12
|
replace_hits_data(hits)
|
15
13
|
end
|
@@ -28,7 +26,7 @@ module InsightsCloud
|
|
28
26
|
hits_response = RestClient::Request.execute(
|
29
27
|
method: :get,
|
30
28
|
url: InsightsCloud.hits_export_url,
|
31
|
-
verify_ssl:
|
29
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
32
30
|
headers: {
|
33
31
|
Authorization: "Bearer #{rh_credentials}",
|
34
32
|
}
|
@@ -40,8 +38,8 @@ module InsightsCloud
|
|
40
38
|
def query_refresh_token
|
41
39
|
token_response = RestClient::Request.execute(
|
42
40
|
method: :post,
|
43
|
-
url:
|
44
|
-
verify_ssl:
|
41
|
+
url: ForemanRhCloud.authentication_url,
|
42
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
45
43
|
payload: {
|
46
44
|
grant_type: 'refresh_token',
|
47
45
|
client_id: 'rhsm-api',
|
@@ -57,7 +55,7 @@ module InsightsCloud
|
|
57
55
|
|
58
56
|
def setup_host_names(host_names)
|
59
57
|
@host_ids = Hash[
|
60
|
-
Host.where(name: host_names).pluck(:name, :id)
|
58
|
+
Host.unscoped.where(name: host_names).pluck(:name, :id)
|
61
59
|
]
|
62
60
|
end
|
63
61
|
|
@@ -71,7 +69,16 @@ module InsightsCloud
|
|
71
69
|
InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
|
72
70
|
# create new facets for hosts that are missing one
|
73
71
|
hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
|
74
|
-
InsightsFacet.create(
|
72
|
+
InsightsFacet.create(
|
73
|
+
@host_ids.map do |host_name, host_id|
|
74
|
+
unless hosts_with_existing_facets.include?(host_id)
|
75
|
+
{
|
76
|
+
host_id: host_id,
|
77
|
+
uuid: @hits_host_names[host_name],
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end.compact
|
81
|
+
)
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module InsightsCloud
|
2
|
+
module Async
|
3
|
+
class InsightsScheduledSync < ::ApplicationJob
|
4
|
+
def perform
|
5
|
+
unless Setting[:allow_auto_insights_sync]
|
6
|
+
logger.debug(
|
7
|
+
'The scheduled process is disabled due to the "allow_auto_insights_sync"
|
8
|
+
setting being set to false.'
|
9
|
+
)
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
InsightsFullSync.perform_later()
|
14
|
+
ensure
|
15
|
+
self.class.set(:wait => 24.hours).perform_later
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.singleton_job_name
|
19
|
+
name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module InventorySync
|
2
|
+
module Async
|
3
|
+
class HostResult
|
4
|
+
def initialize(result)
|
5
|
+
@total = result['total']
|
6
|
+
@count = result['count']
|
7
|
+
@page = result['page']
|
8
|
+
@per_page = result['per_page']
|
9
|
+
@fqdns = result["results"].map { |host| host['fqdn'] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def status_hashes
|
13
|
+
@fqdns.map do |fqdn|
|
14
|
+
host_id = host_id(fqdn)
|
15
|
+
if host_id
|
16
|
+
touched << host_id
|
17
|
+
{
|
18
|
+
host_id: host_id,
|
19
|
+
status: InventorySync::InventoryStatus::SYNC,
|
20
|
+
reported_at: Time.current,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end.compact
|
24
|
+
end
|
25
|
+
|
26
|
+
def touched
|
27
|
+
@touched ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def host_id(fqdn)
|
31
|
+
hosts[fqdn]
|
32
|
+
end
|
33
|
+
|
34
|
+
def hosts
|
35
|
+
@hosts ||= Hash[
|
36
|
+
Host.where(name: @fqdns).pluck(:name, :id)
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def percentage
|
41
|
+
ratio = @per_page * @page * 1.0 / @total * 100
|
42
|
+
(ratio > 100) ? 100 : ratio.truncate(2)
|
43
|
+
end
|
44
|
+
|
45
|
+
def last?
|
46
|
+
@total <= @per_page * @page
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|