foreman_rh_cloud 3.0.19 → 4.0.22
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/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/inventory_sync/inventory_status.rb +6 -0
- data/app/models/setting/rh_cloud.rb +5 -5
- data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
- data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -6
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +75 -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 +1 -0
- 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 +5 -1
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +6 -6
- data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
- 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 +31 -22
- data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +66 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +15 -24
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
- data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +25 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +1 -4
- data/lib/tasks/insights.rake +4 -12
- data/lib/tasks/rh_cloud_inventory.rake +18 -4
- data/package.json +1 -1
- data/test/factories/insights_factories.rb +22 -0
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_full_sync_test.rb +17 -8
- 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 +4 -1
- data/test/models/insights_client_report_status_test.rb +77 -0
- data/test/test_plugin_helper.rb +0 -1
- 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 +66 -29
- 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/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 +28 -63
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
- 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/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
- 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 +11 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
- data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
- data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
- data/webpack/common/ForemanTasks/index.js +1 -0
- data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
- data/webpack/common/table/helpers.js +7 -0
- metadata +38 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea5629e755a80131b35cb1509ff5d44fefccbe70c0362829e7d7c0f1d9f2484d
|
4
|
+
data.tar.gz: b1e1ded88509739b56711a97aa81797592d5b4ec8b32cb811ad9d6a280adfb57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ac6593a54fd506e2a8bb690bc4c6e046f92fea706333c77a54f9472b4977fd88201e2d13852f15418e326cee9961b25f31ef9cfda4703cc88f29c84d63a6459
|
7
|
+
data.tar.gz: '02649cb1f8b0e11d6570988f3cafe55e82d14bad6f133f5cf691c396b542156e0e2c2e132d0eb38a11bb421d14e5d31757e630ba463052cd4cbf71c701564fc7'
|
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
|
-
|
@@ -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
|
@@ -2,6 +2,8 @@ module ForemanRhCloud
|
|
2
2
|
module CloudAuth
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
+
include CloudRequest
|
6
|
+
|
5
7
|
def rh_credentials
|
6
8
|
@rh_credentials ||= query_refresh_token
|
7
9
|
end
|
@@ -24,5 +26,15 @@ module ForemanRhCloud
|
|
24
26
|
Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
|
25
27
|
raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
|
26
28
|
end
|
29
|
+
|
30
|
+
def execute_cloud_request(params)
|
31
|
+
final_params = {
|
32
|
+
headers: {
|
33
|
+
Authorization: "Bearer #{rh_credentials}",
|
34
|
+
},
|
35
|
+
}.deep_merge(params)
|
36
|
+
|
37
|
+
super(final_params)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ForemanRhCloud
|
2
|
+
module CloudRequest
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def execute_cloud_request(params)
|
6
|
+
final_params = {
|
7
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
8
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
9
|
+
}.deep_merge(params)
|
10
|
+
|
11
|
+
RestClient::Request.execute(final_params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,7 +2,7 @@ require 'rest-client'
|
|
2
2
|
|
3
3
|
module ForemanRhCloud
|
4
4
|
class CloudRequestForwarder
|
5
|
-
include
|
5
|
+
include ForemanRhCloud::CloudRequest
|
6
6
|
|
7
7
|
def forward_request(original_request, controller_name, branch_id, certs)
|
8
8
|
forward_params = prepare_forward_params(original_request, branch_id)
|
@@ -22,7 +22,6 @@ module ForemanRhCloud
|
|
22
22
|
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
23
23
|
base_params = {
|
24
24
|
method: original_request.method,
|
25
|
-
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
26
25
|
payload: forward_payload,
|
27
26
|
headers: {
|
28
27
|
params: forward_params,
|
@@ -33,10 +32,6 @@ module ForemanRhCloud
|
|
33
32
|
base_params.merge(path_params(original_request.path, certs))
|
34
33
|
end
|
35
34
|
|
36
|
-
def execute_cloud_request(request_opts)
|
37
|
-
RestClient::Request.execute request_opts
|
38
|
-
end
|
39
|
-
|
40
35
|
def prepare_forward_payload(original_request, controller_name)
|
41
36
|
forward_payload = original_request.request_parameters[controller_name]
|
42
37
|
|
@@ -0,0 +1,75 @@
|
|
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
|
+
execute_cloud_request(
|
66
|
+
method: :post,
|
67
|
+
url: InsightsCloud.playbook_url,
|
68
|
+
headers: {
|
69
|
+
content_type: :json,
|
70
|
+
},
|
71
|
+
payload: playbook_request.to_json
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
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
|