foreman_rh_cloud 3.0.18.1 → 4.0.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -5
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +14 -3
- data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +8 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +17 -7
- data/app/controllers/insights_cloud/hits_controller.rb +37 -0
- data/app/controllers/insights_cloud/settings_controller.rb +1 -1
- data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
- data/app/models/insights_client_report_status.rb +58 -0
- data/app/models/insights_resolution.rb +1 -1
- data/app/models/inventory_sync/inventory_status.rb +6 -0
- data/app/models/setting/rh_cloud.rb +5 -5
- data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +78 -0
- data/app/services/foreman_rh_cloud/template_renderer_helper.rb +22 -0
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
- data/app/views/job_templates/rh_cloud_remediations.erb +14 -0
- data/config/routes.rb +2 -1
- data/db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb +10 -0
- data/db/seeds.d/179_ui_notifications.rb +11 -0
- data/db/seeds.d/50_job_templates.rb +14 -0
- data/lib/foreman_inventory_upload.rb +9 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
- data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +1 -1
- data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +5 -1
- data/lib/foreman_rh_cloud.rb +18 -0
- data/lib/foreman_rh_cloud/engine.rb +36 -2
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +12 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +39 -24
- data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +69 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +13 -17
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
- data/lib/inventory_sync/async/host_result.rb +11 -6
- data/lib/inventory_sync/async/inventory_full_sync.rb +24 -41
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +34 -0
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +17 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +54 -0
- data/lib/tasks/insights.rake +4 -12
- data/lib/tasks/rh_cloud_inventory.rake +12 -4
- data/package.json +1 -1
- data/test/factories/insights_factories.rb +22 -0
- data/test/jobs/insights_full_sync_test.rb +28 -15
- data/test/jobs/insights_resolutions_sync_test.rb +77 -0
- data/test/jobs/insights_rules_sync_test.rb +8 -3
- data/test/jobs/inventory_full_sync_test.rb +185 -12
- data/test/models/insights_client_report_status_test.rb +77 -0
- data/test/unit/rh_cloud_http_proxy_test.rb +4 -4
- data/test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb +49 -0
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +28 -0
- data/test/unit/slice_generator_test.rb +11 -2
- data/test/unit/tags_generator_test.rb +10 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -1
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +5 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +15 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +13 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +81 -46
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +6 -12
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +1 -9
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +18 -27
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +1 -16
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +58 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +51 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +2 -5
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
- data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +0 -2
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +2 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +59 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationActions.js +12 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +43 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +101 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +9 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +43 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationTableConstants.js +38 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +55 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +34 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +8 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +4 -0
- data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
- data/webpack/common/table/helpers.js +7 -0
- metadata +56 -26
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +0 -36
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +0 -31
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +0 -26
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +0 -98
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97882071192995f2da93032050b9ecdfa616dba407c8d032bfd29f6741ea9d56
|
4
|
+
data.tar.gz: 88bca49cea9ee2abac2d2dc9d608a33329ad9e214d57035424e8e24984691537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67dd2ada55ac862b2d57ddf893e7408d002c40c2f89a141e6bf8c115d6eeee32d19b156e7668751f591665f948fa04d628719e5f6f5ab9e4609c02f0a14a93f4
|
7
|
+
data.tar.gz: 54ded7bb163e4a38cd3fa4a62dfe101484b98e87c016514b985190f77a07c7556e980dd8574dc5fb70cacb3fcc521a37a1f4f2325e5360cdbb2ddd6f38816804
|
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
|
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
|
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
|
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
|
-
|
@@ -13,12 +13,23 @@ module ForemanInventoryUpload
|
|
13
13
|
message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
|
14
14
|
}, status: :method_not_allowed
|
15
15
|
else
|
16
|
-
|
16
|
+
task = ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
|
17
17
|
end
|
18
|
+
return render json: { message: N_('there was an issue triggering the task') }, status: :internal_server_error unless task
|
18
19
|
|
19
20
|
render json: {
|
20
|
-
|
21
|
-
|
21
|
+
task: task,
|
22
|
+
}, status: :ok
|
23
|
+
end
|
24
|
+
|
25
|
+
def show
|
26
|
+
task = ForemanTasks::Task.find_by(id: params[:id])
|
27
|
+
return render json: { message: N_('No task was found') }, status: :internal_server_error unless task
|
28
|
+
|
29
|
+
render json: {
|
30
|
+
endedAt: task.ended_at,
|
31
|
+
output: task.output,
|
32
|
+
result: task.result,
|
22
33
|
}, status: :ok
|
23
34
|
end
|
24
35
|
end
|
@@ -8,6 +8,7 @@ module ForemanInventoryUpload
|
|
8
8
|
excludePackagesEnabled: Setting[:exclude_installed_packages],
|
9
9
|
CloudConnectorStatus: ForemanInventoryUpload::UploadsSettingsController.cloud_connector_status,
|
10
10
|
cloudToken: !Setting[:rh_cloud_token].empty?,
|
11
|
+
lastSyncTask: last_successful_inventory_sync_task,
|
11
12
|
}, status: :ok
|
12
13
|
end
|
13
14
|
|
@@ -22,5 +23,12 @@ module ForemanInventoryUpload
|
|
22
23
|
return nil unless job
|
23
24
|
{ id: job.id, task: ForemanTasks::Task.where(:id => job.task_id).first }
|
24
25
|
end
|
26
|
+
|
27
|
+
def last_successful_inventory_sync_task
|
28
|
+
task = ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryFullSync', result: 'success')
|
29
|
+
.reorder('ended_at desc').first
|
30
|
+
return nil unless task
|
31
|
+
{ output: task.output, endedAt: task.ended_at }
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
@@ -10,27 +10,28 @@ module InsightsCloud::Api
|
|
10
10
|
|
11
11
|
skip_after_action :log_response_body, :only => [:forward_request]
|
12
12
|
skip_before_action :check_media_type, :only => [:forward_request]
|
13
|
+
after_action :update_host_insights_status, only: [:forward_request]
|
13
14
|
|
14
15
|
# The method that "proxies" requests over to Cloud
|
15
16
|
def forward_request
|
16
17
|
certs = candlepin_id_cert @organization
|
17
|
-
cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
18
|
+
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
18
19
|
|
19
|
-
if cloud_response.code == 401
|
20
|
+
if @cloud_response.code == 401
|
20
21
|
return render json: {
|
21
22
|
:message => 'Authentication to the Insights Service failed.',
|
22
23
|
:headers => {},
|
23
24
|
}, status: :bad_gateway
|
24
25
|
end
|
25
26
|
|
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]
|
27
|
+
if @cloud_response.headers[:content_disposition]
|
28
|
+
return send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
|
28
29
|
end
|
29
30
|
|
30
|
-
assign_header(response, cloud_response, :x_resource_count, true)
|
31
|
-
assign_header(response, cloud_response, :x_rh_insights_request_id, false)
|
31
|
+
assign_header(response, @cloud_response, :x_resource_count, true)
|
32
|
+
assign_header(response, @cloud_response, :x_rh_insights_request_id, false)
|
32
33
|
|
33
|
-
render json: cloud_response, status: cloud_response.code
|
34
|
+
render json: @cloud_response, status: @cloud_response.code
|
34
35
|
end
|
35
36
|
|
36
37
|
def branch_info
|
@@ -69,5 +70,14 @@ module InsightsCloud::Api
|
|
69
70
|
@branch_id = cp_owner_id(@organization)
|
70
71
|
return render_message "Branch ID not found for organization #{@organization.title}", :status => 400 unless @branch_id
|
71
72
|
end
|
73
|
+
|
74
|
+
def update_host_insights_status
|
75
|
+
return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
|
76
|
+
request.path.include?('/redhat_access/r/insights/uploads/')
|
77
|
+
|
78
|
+
data = @cloud_response.code.to_s.start_with?('2')
|
79
|
+
host_status = @host.get_status(InsightsClientReportStatus)
|
80
|
+
host_status.update(reported_at: Time.now.utc, status: host_status.to_status(data: data))
|
81
|
+
end
|
72
82
|
end
|
73
83
|
end
|
@@ -9,6 +9,7 @@ module InsightsCloud
|
|
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 = InsightsHit.with_playbook.search_for(params[:query])
|
27
|
+
else
|
28
|
+
hits = resource_base_search_and_page.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,31 @@ 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
|
40
77
|
end
|
41
78
|
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
|
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
|
-
|
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,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
|
@@ -26,5 +26,11 @@ module InventorySync
|
|
26
26
|
N_('Successfully uploaded to your RH cloud inventory')
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def to_status(options = {})
|
31
|
+
# this method used to calculate status.
|
32
|
+
# Since the calculation is done externally we should return the previously calculated status
|
33
|
+
status
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
@@ -14,12 +14,12 @@ class Setting::RhCloud < Setting
|
|
14
14
|
def self.default_settings
|
15
15
|
return unless ActiveRecord::Base.connection.table_exists?('settings')
|
16
16
|
[
|
17
|
-
set('allow_auto_inventory_upload', N_('
|
18
|
-
set('allow_auto_insights_sync', N_('
|
19
|
-
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false, N_('Obfuscate host names')),
|
20
|
-
set('obfuscate_inventory_ips', N_('Obfuscate
|
17
|
+
set('allow_auto_inventory_upload', N_('Enable automatic upload of your host inventory to the Red Hat cloud'), true, N_('Automatic inventory upload')),
|
18
|
+
set('allow_auto_insights_sync', N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), false, N_('Synchronize recommendations Automatically')),
|
19
|
+
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to the Red Hat cloud'), false, N_('Obfuscate host names')),
|
20
|
+
set('obfuscate_inventory_ips', N_('Obfuscate ipv4 addresses sent to the Red Hat cloud'), false, N_('Obfuscate host ipv4 addresses')),
|
21
21
|
set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), nil, N_('Red Hat Cloud token'), nil, encrypted: true),
|
22
|
-
set('exclude_installed_packages', N_('Exclude installed packages from Red Hat cloud
|
22
|
+
set('exclude_installed_packages', N_('Exclude installed packages from being uploaded to the Red Hat cloud'), false, N_("Exclude installed Packages")),
|
23
23
|
set('include_parameter_tags', N_('Should import include parameter tags from Foreman?'), false, N_('Include parameters in insights-client reports')),
|
24
24
|
]
|
25
25
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module ForemanRhCloud
|
2
|
+
class RemediationsRetriever
|
3
|
+
include CloudAuth
|
4
|
+
|
5
|
+
attr_reader :logger
|
6
|
+
|
7
|
+
def initialize(hit_remediation_pairs, logger: Logger.new(IO::NULL))
|
8
|
+
@hit_remediation_pairs = hit_remediation_pairs
|
9
|
+
@logger = logger
|
10
|
+
|
11
|
+
logger.debug("Querying playbook for #{hit_remediation_pairs}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_playbook
|
15
|
+
response = query_playbook
|
16
|
+
|
17
|
+
logger.debug("Got playbook response: #{response.body}")
|
18
|
+
|
19
|
+
response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def hit_ids
|
25
|
+
@hit_remediation_pairs.map { |pair| pair["hit_id"] }
|
26
|
+
end
|
27
|
+
|
28
|
+
def remediation_ids
|
29
|
+
@hit_remediation_pairs.map { |pair| pair["resolution_id"] }
|
30
|
+
end
|
31
|
+
|
32
|
+
def hits
|
33
|
+
@hits ||= Hash[
|
34
|
+
InsightsHit.joins(:insights_facet).where(id: hit_ids).pluck(:id, 'insights_facets.uuid')
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
def pairs_by_remediation_id
|
39
|
+
@hit_remediation_pairs.group_by { |pair| pair["resolution_id"] }
|
40
|
+
end
|
41
|
+
|
42
|
+
def remediations
|
43
|
+
@remediations ||= Hash[
|
44
|
+
InsightsResolution.where(id: remediation_ids).pluck(:id, :resolution_type, :rule_id).map do |id, resolution_type, rule_id|
|
45
|
+
[id, {resolution_type: resolution_type, rule_id: rule_id}]
|
46
|
+
end
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
def playbook_request
|
51
|
+
{
|
52
|
+
issues: pairs_by_remediation_id.map do |remediation_id, pairs|
|
53
|
+
{
|
54
|
+
resolution: remediations[remediation_id][:resolution_type],
|
55
|
+
id: InsightsCloud.remediation_rule_id(remediations[remediation_id][:rule_id]),
|
56
|
+
systems: pairs.map do |pair|
|
57
|
+
hits[pair["hit_id"]]
|
58
|
+
end,
|
59
|
+
}
|
60
|
+
end,
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def query_playbook
|
65
|
+
RestClient::Request.execute(
|
66
|
+
method: :post,
|
67
|
+
url: InsightsCloud.playbook_url,
|
68
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
69
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
70
|
+
headers: {
|
71
|
+
content_type: :json,
|
72
|
+
Authorization: "Bearer #{rh_credentials}",
|
73
|
+
},
|
74
|
+
payload: playbook_request.to_json
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ForemanRhCloud
|
2
|
+
# Macro to fetch remediation playbook from cloud.redhat.com
|
3
|
+
module TemplateRendererHelper
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
extend ApipieDSL::Module
|
6
|
+
|
7
|
+
apipie :class, 'Macros related to Red Hat cloud interface' do
|
8
|
+
name 'RHCloud'
|
9
|
+
sections only: %w[all jobs]
|
10
|
+
end
|
11
|
+
|
12
|
+
apipie :method, 'Returns a playbook generated from Red Hat cloud recommendations' do
|
13
|
+
required :hit_remediation_pairs, String, desc: 'JSON-encoded array of hashes in the form of [{hit_id: 1, remediation_id: 2}, ...]'
|
14
|
+
returns String, desc: 'Playbook generated for the specific recommendations and hosts'
|
15
|
+
end
|
16
|
+
def remediations_playbook(hit_remediation_pairs)
|
17
|
+
hit_remediation_pairs = JSON.parse(hit_remediation_pairs)
|
18
|
+
retriever = ForemanRhCloud::RemediationsRetriever.new(hit_remediation_pairs, logger: template_logger)
|
19
|
+
retriever.create_playbook
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|