foreman_rh_cloud 12.0.0 → 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
- data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +2 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +26 -22
- data/app/services/foreman_rh_cloud/cloud_request.rb +13 -3
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +17 -3
- data/app/services/foreman_rh_cloud/rules_ingester.rb +12 -1
- data/config/routes.rb +4 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +2 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +83 -42
- data/lib/foreman_inventory_upload.rb +5 -0
- data/lib/foreman_rh_cloud/engine.rb +15 -3
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +2 -0
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +35 -2
- data/test/unit/slice_generator_test.rb +212 -4
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +5 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +2 -1
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +27 -8
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/index.js +11 -3
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +71 -10
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettingsSelectors.js +13 -1
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/MinimalInventoryDropdown.js +107 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +9 -2
- data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +8 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +53 -9
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +72 -58
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +61 -6
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +18 -6
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +54 -6
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +8 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +4 -2
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +1 -8
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +4 -2
- data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +47 -28
- data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +46 -8
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +2 -7
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -6
- data/webpack/common/Switcher/SwitcherPF4.js +11 -1
- metadata +4 -11
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +0 -13
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +0 -31
- data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +0 -89
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -62
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +0 -10
- data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +0 -43
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/AdvancedSettings.js +0 -72
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/index.js +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a42f6e6437d9d99d173939b6ce360e573d40d4dbd2c99ba6aa71bd7c54ad868a
|
4
|
+
data.tar.gz: 811a4d82f96597e833067ce20b0654b90a99a35dd6c8da289272e479c6e83917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9d780419f9357ba8a73c40bccb6de50aa892e21ace6d0c5a9ab0c5f49e871e33406ca7b1b2560dd973875b08f229f8d32778699dd2b68aea69e186ce9eba1d8
|
7
|
+
data.tar.gz: 6726d03325a8cf3c5bd1aab3562120252025e4a18d0910d7c3bb08708bd509d8246fe53df87121c3532cb5f1ae2b6debde64b621171af0400b04380ffead6b85
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
[](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/ruby_tests.yml)
|
2
|
+
[](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/js_tests.yml)
|
3
|
+
|
1
4
|
# ForemanRhCloud
|
2
5
|
|
3
|
-
*
|
6
|
+
*Introduction here*
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -15,7 +18,7 @@ for how to install Foreman plugins
|
|
15
18
|
|
16
19
|
#### Inventory upload
|
17
20
|
|
18
|
-
In UI:
|
21
|
+
In UI: Insights -> Inventory Upload -> select the organization -> Generate and upload report
|
19
22
|
|
20
23
|
From command-line:
|
21
24
|
|
@@ -38,7 +41,7 @@ From command-line:
|
|
38
41
|
|
39
42
|
#### Fetch hosts remediation data
|
40
43
|
|
41
|
-
In UI:
|
44
|
+
In UI: Insights -> Recommendations -> Sync recommendations (under the vertical ellipsis)
|
42
45
|
|
43
46
|
From command-line:
|
44
47
|
|
@@ -46,7 +49,7 @@ From command-line:
|
|
46
49
|
|
47
50
|
#### Synchronize inventory status
|
48
51
|
|
49
|
-
In UI:
|
52
|
+
In UI: Insights -> Inventory Upload -> Sync all inventory status
|
50
53
|
|
51
54
|
From command-line:
|
52
55
|
|
@@ -16,7 +16,7 @@ module InventoryUpload
|
|
16
16
|
|
17
17
|
def report_file(organization_id)
|
18
18
|
filename = ForemanInventoryUpload.facts_archive_name(organization_id)
|
19
|
-
files =
|
19
|
+
files = ForemanInventoryUpload.report_file_paths(organization_id)
|
20
20
|
|
21
21
|
raise ReportMissingError.new(filename: filename) if files.empty?
|
22
22
|
|
@@ -8,12 +8,14 @@ module ForemanInventoryUpload
|
|
8
8
|
labels.map do |id, label|
|
9
9
|
generate_report_status = status_for(id, ForemanInventoryUpload::Async::GenerateReportJob)
|
10
10
|
upload_report_status = status_for(id, ForemanInventoryUpload::Async::UploadReportJob)
|
11
|
+
report_file_paths = ForemanInventoryUpload.report_file_paths(id)
|
11
12
|
|
12
13
|
[
|
13
14
|
label,
|
14
15
|
{
|
15
16
|
generate_report_status: generate_report_status,
|
16
17
|
upload_report_status: upload_report_status,
|
18
|
+
report_file_paths: report_file_paths,
|
17
19
|
id: id,
|
18
20
|
},
|
19
21
|
]
|
@@ -2,7 +2,9 @@ module ForemanInventoryUpload
|
|
2
2
|
class UploadsSettingsController < ::ApplicationController
|
3
3
|
def index
|
4
4
|
render json: {
|
5
|
+
insightsMinimalDataCollection: Setting[:insights_minimal_data_collection],
|
5
6
|
autoUploadEnabled: Setting[:allow_auto_inventory_upload],
|
7
|
+
subscriptionConnectionEnabled: Setting[:subscription_connection_enabled],
|
6
8
|
hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
|
7
9
|
ipsObfuscationEnabled: Setting[:obfuscate_inventory_ips],
|
8
10
|
excludePackagesEnabled: Setting[:exclude_installed_packages],
|
@@ -18,35 +18,39 @@ module InsightsCloud::Api
|
|
18
18
|
certs = candlepin_id_cert @organization
|
19
19
|
begin
|
20
20
|
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
21
|
-
rescue RestClient::
|
22
|
-
|
23
|
-
return render json: { error:
|
24
|
-
rescue RestClient::
|
25
|
-
logger.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
rescue RestClient::Exceptions::Timeout => e
|
22
|
+
response_obj = e.response.presence || e.exception
|
23
|
+
return render json: { message: response_obj.to_s, error: response_obj.to_s }, status: :gateway_timeout
|
24
|
+
rescue RestClient::Unauthorized => e
|
25
|
+
logger.warn("Forwarding request auth error: #{e}")
|
26
|
+
message = 'Authentication to the Insights Service failed.'
|
27
|
+
return render json: { message: message, error: message }, status: :unauthorized
|
28
|
+
rescue RestClient::NotModified => e
|
29
|
+
logger.info("Forwarding request not modified: #{e}")
|
30
|
+
message = 'Cloud request not modified'
|
31
|
+
return render json: { message: message, error: message }, status: :not_modified
|
32
|
+
rescue RestClient::ExceptionWithResponse => e
|
33
|
+
response_obj = e.response.presence || e.exception
|
34
|
+
code = response_obj.try(:code) || response_obj.try(:http_code) || 500
|
35
|
+
message = 'Cloud request failed'
|
30
36
|
|
31
|
-
if @cloud_response.code == 401
|
32
37
|
return render json: {
|
33
|
-
:message =>
|
38
|
+
:message => message,
|
39
|
+
:error => response_obj.to_s,
|
34
40
|
:headers => {},
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
:headers => {},
|
42
|
-
:response => @cloud_response,
|
43
|
-
}, status: @cloud_response.code
|
41
|
+
:response => response_obj,
|
42
|
+
}, status: code
|
43
|
+
rescue StandardError => e
|
44
|
+
# Catch any other exceptions here, such as Errno::ECONNREFUSED
|
45
|
+
logger.warn("Cloud request failed with exception: #{e}")
|
46
|
+
return render json: { error: e.to_s }, status: :bad_gateway
|
44
47
|
end
|
45
48
|
|
46
49
|
# Append redhat-specific headers
|
47
50
|
@cloud_response.headers.each do |key, value|
|
48
51
|
assign_header(response, @cloud_response, key, false) if key.to_s.start_with?('x_rh_')
|
49
52
|
end
|
53
|
+
|
50
54
|
# Append general headers
|
51
55
|
assign_header(response, @cloud_response, :x_resource_count, true)
|
52
56
|
headers[Rack::ETAG] = @cloud_response.headers[:etag]
|
@@ -56,8 +60,8 @@ module InsightsCloud::Api
|
|
56
60
|
# content type
|
57
61
|
send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
|
58
62
|
elsif @cloud_response.headers[:content_type] =~ /zip/
|
59
|
-
#
|
60
|
-
#
|
63
|
+
# If there is no Content-Disposition, but the content type is binary according to Content-Type, send the raw data
|
64
|
+
# with proper content type
|
61
65
|
send_data @cloud_response, type: @cloud_response.headers[:content_type]
|
62
66
|
else
|
63
67
|
render json: @cloud_response, status: @cloud_response.code
|
@@ -8,14 +8,24 @@ module ForemanRhCloud
|
|
8
8
|
proxy: ForemanRhCloud.transformed_http_proxy_string,
|
9
9
|
}.deep_merge(params)
|
10
10
|
|
11
|
+
if ForemanRhCloud.with_local_advisor_engine?
|
12
|
+
final_params[:ssl_ca_file] ||= ForemanRhCloud.ca_cert
|
13
|
+
end
|
14
|
+
|
11
15
|
response = RestClient::Request.execute(final_params)
|
12
16
|
|
13
17
|
logger.debug("Response headers for request url #{final_params[:url]} are: #{response.headers}")
|
14
18
|
|
15
19
|
response
|
16
|
-
rescue RestClient::
|
17
|
-
logger.debug("
|
18
|
-
raise
|
20
|
+
rescue RestClient::Exceptions::Timeout => ex
|
21
|
+
logger.debug("Timeout exception raised for request url #{final_params[:url]}: #{ex}")
|
22
|
+
raise
|
23
|
+
rescue RestClient::ExceptionWithResponse => ex
|
24
|
+
logger.debug("Response headers for request url #{final_params[:url]} with status code #{ex.http_code} are: #{ex.http_headers} and body: #{ex.http_body}")
|
25
|
+
raise
|
26
|
+
rescue StandardError => ex
|
27
|
+
logger.debug("Exception raised for request url #{final_params[:url]}: #{ex}")
|
28
|
+
raise
|
19
29
|
end
|
20
30
|
end
|
21
31
|
end
|
@@ -17,8 +17,6 @@ module ForemanRhCloud
|
|
17
17
|
logger.debug("Sending request to: #{request_opts[:url]}")
|
18
18
|
|
19
19
|
execute_cloud_request(request_opts)
|
20
|
-
rescue RestClient::ExceptionWithResponse => error_response
|
21
|
-
error_response.response.presence || error_response.exception
|
22
20
|
end
|
23
21
|
|
24
22
|
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
@@ -34,7 +32,13 @@ module ForemanRhCloud
|
|
34
32
|
),
|
35
33
|
}
|
36
34
|
requested_url = original_request.original_fullpath.end_with?('/') ? original_request.path + '/' : original_request.path
|
37
|
-
|
35
|
+
params = path_params(requested_url, certs)
|
36
|
+
|
37
|
+
if ForemanRhCloud.with_local_advisor_engine?
|
38
|
+
params[:ssl_ca_file] = ForemanRhCloud.ca_cert
|
39
|
+
end
|
40
|
+
|
41
|
+
base_params.merge(params)
|
38
42
|
end
|
39
43
|
|
40
44
|
def prepare_forward_payload(original_request, controller_name)
|
@@ -63,6 +67,12 @@ module ForemanRhCloud
|
|
63
67
|
|
64
68
|
def path_params(request_path, certs)
|
65
69
|
case request_path
|
70
|
+
when lightspeed?
|
71
|
+
{
|
72
|
+
url: ForemanRhCloud.cert_base_url + request_path,
|
73
|
+
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
74
|
+
ssl_client_key: OpenSSL::PKey.read(certs[:key]),
|
75
|
+
}
|
66
76
|
when platform_request?
|
67
77
|
{
|
68
78
|
url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
|
@@ -95,6 +105,10 @@ module ForemanRhCloud
|
|
95
105
|
headers
|
96
106
|
end
|
97
107
|
|
108
|
+
def lightspeed?
|
109
|
+
->(request_path) { request_path.include? '/lightspeed' }
|
110
|
+
end
|
111
|
+
|
98
112
|
def platform_request?
|
99
113
|
->(request_path) { request_path.include? '/platform' }
|
100
114
|
end
|
@@ -13,7 +13,18 @@ module ForemanRhCloud
|
|
13
13
|
|
14
14
|
def fetch_rules_data
|
15
15
|
advisor_url = "#{ForemanRhCloud.on_premise_url}/r/insights/v1/static/release/content.json"
|
16
|
-
|
16
|
+
uri = URI.parse(advisor_url)
|
17
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
http.use_ssl = true
|
19
|
+
|
20
|
+
# Set CA certificate
|
21
|
+
http.ca_file = ForemanRhCloud.ca_cert
|
22
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
23
|
+
|
24
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
25
|
+
|
26
|
+
response = http.request(request)
|
27
|
+
JSON.parse(response.body, symbolize_names: true)
|
17
28
|
end
|
18
29
|
|
19
30
|
def fetch_rules_and_resolutions
|
data/config/routes.rb
CHANGED
@@ -49,6 +49,10 @@ Rails.application.routes.draw do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
scope :module => :'insights_cloud/api' do
|
53
|
+
match '/api/lightspeed/*path', to: 'machine_telemetries#forward_request', via: :all
|
54
|
+
end
|
55
|
+
|
52
56
|
# API routes
|
53
57
|
|
54
58
|
namespace :api, :defaults => { :format => 'json' } do
|
@@ -50,56 +50,97 @@ module ForemanInventoryUpload
|
|
50
50
|
@stream.simple_field('success', ActiveModel::Type::Boolean.new.cast(fact_value(host, 'conversions::success')), :last)
|
51
51
|
end
|
52
52
|
|
53
|
+
def insights_minimal_data_collection(host)
|
54
|
+
@stream.simple_field('account', account_id(host.organization).to_s)
|
55
|
+
@stream.simple_field('subscription_manager_id', uuid_value!(host.subscription_facet&.uuid))
|
56
|
+
@stream.simple_field('insights_id', uuid_value(fact_value(host, 'insights_id')))
|
57
|
+
@stream.simple_field('bios_uuid', bios_uuid(host))
|
58
|
+
@stream.simple_field('bios_vendor', fact_value(host, 'dmi::bios::vendor'))
|
59
|
+
@stream.simple_field('bios_version', fact_value(host, 'dmi::bios::version'))
|
60
|
+
@stream.simple_field('arch', host.architecture&.name)
|
61
|
+
@stream.simple_field(
|
62
|
+
'infrastructure_type',
|
63
|
+
ActiveModel::Type::Boolean.new.cast(fact_value(host, 'virt::is_guest')) ? 'virtual' : 'physical'
|
64
|
+
)
|
65
|
+
@stream.object_field('system_profile') do
|
66
|
+
unless (installed_products = host.subscription_facet&.installed_products).empty?
|
67
|
+
@stream.array_field('installed_products') do
|
68
|
+
@stream.raw(installed_products.map do |product|
|
69
|
+
{
|
70
|
+
'name': product.name,
|
71
|
+
'id': product.cp_product_id,
|
72
|
+
}.to_json
|
73
|
+
end.join(', '))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@stream.simple_field('cores_per_socket', fact_value(host, 'cpu::core(s)_per_socket')) { |v| v.to_i } if fact_value(host, 'cpu::core(s)_per_socket').present?
|
77
|
+
@stream.simple_field('system_memory_bytes', fact_value(host, 'memory::memtotal')) { |v| kilobytes_to_bytes(v.to_i) } if fact_value(host, 'memory::memtotal').present?
|
78
|
+
@stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)')) { |v| v.to_i } if fact_value(host, 'cpu::cpu(s)').present?
|
79
|
+
@stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)'), :last) { |v| v.to_i } if fact_value(host, 'cpu::cpu_socket(s)').present?
|
80
|
+
end
|
81
|
+
if host.subscription_facet.hypervisor?
|
82
|
+
@stream.simple_field('cpu_socket(s)', fact_value(host, 'cpu::cpu_socket(s)'))
|
83
|
+
@stream.simple_field('hypervisor_type', fact_value(host, 'hypervisor::type'))
|
84
|
+
@stream.simple_field('hypervisor_version', fact_value(host, 'hypervisor::version'), :last)
|
85
|
+
else
|
86
|
+
@stream.simple_field('cpu_socket(s)', fact_value(host, 'cpu::cpu_socket(s)'), :last)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
53
90
|
def report_host(host)
|
54
91
|
host_ips_cache = host_ips(host)
|
55
92
|
@stream.object do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@stream.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
93
|
+
if Setting[:insights_minimal_data_collection]
|
94
|
+
insights_minimal_data_collection(host)
|
95
|
+
else
|
96
|
+
@stream.simple_field('fqdn', fqdn(host))
|
97
|
+
@stream.simple_field('account', account_id(host.organization).to_s)
|
98
|
+
@stream.simple_field('subscription_manager_id', uuid_value!(host.subscription_facet&.uuid))
|
99
|
+
@stream.simple_field('satellite_id', uuid_value!(host.subscription_facet&.uuid))
|
100
|
+
if host.subscription_facet&.convert2rhel_through_foreman.present?
|
101
|
+
@stream.object_field('conversions') do
|
102
|
+
@stream.object_field('source_os') do
|
103
|
+
@stream.simple_field('name', fact_value(host, 'conversions::source_os::name'))
|
104
|
+
@stream.simple_field('version', fact_value(host, 'conversions::source_os::version') || 'Unknown - Fact not reported', :last)
|
105
|
+
end
|
106
|
+
@stream.object_field('target_os') do
|
107
|
+
@stream.simple_field('name', fact_value(host, 'conversions::target_os::name'))
|
108
|
+
@stream.simple_field('version', fact_value(host, 'conversions::target_os::version') || 'Unknown - Fact not reported', :last)
|
109
|
+
end
|
110
|
+
report_conversions(host)
|
69
111
|
end
|
70
|
-
report_conversions(host)
|
71
112
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
report_system_profile(host, host_ips_cache)
|
80
|
-
end
|
81
|
-
@stream.array_field('facts') do
|
82
|
-
@stream.object do
|
83
|
-
@stream.simple_field('namespace', SATELLITE_NAMESPACE)
|
84
|
-
@stream.object_field('facts', :last) do
|
85
|
-
report_satellite_facts(host)
|
86
|
-
end
|
113
|
+
@stream.simple_field('bios_uuid', bios_uuid(host))
|
114
|
+
@stream.simple_field('vm_uuid', uuid_value(fact_value(host, 'virt::uuid')))
|
115
|
+
@stream.simple_field('insights_id', uuid_value(fact_value(host, 'insights_id')))
|
116
|
+
report_ip_addresses(host, host_ips_cache)
|
117
|
+
report_mac_addresses(host)
|
118
|
+
@stream.object_field('system_profile') do
|
119
|
+
report_system_profile(host, host_ips_cache)
|
87
120
|
end
|
88
|
-
end
|
89
121
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
122
|
+
@stream.array_field('facts') do
|
123
|
+
@stream.object do
|
124
|
+
@stream.simple_field('namespace', SATELLITE_NAMESPACE)
|
125
|
+
@stream.object_field('facts', :last) do
|
126
|
+
report_satellite_facts(host)
|
127
|
+
end
|
128
|
+
end
|
96
129
|
end
|
97
130
|
|
98
|
-
tags
|
99
|
-
|
100
|
-
|
101
|
-
key, value
|
102
|
-
|
131
|
+
@stream.array_field('tags', :last) do
|
132
|
+
tags_generator = Tags.new(host)
|
133
|
+
host_params_tags = tags_generator.generate_parameters
|
134
|
+
host_params_tags.each do |key, value|
|
135
|
+
report_tag(SATELLITE_PARAMS_NAMESPACE, key, value)
|
136
|
+
end
|
137
|
+
|
138
|
+
tags = tags_generator.generate
|
139
|
+
last_index = tags.count - 1
|
140
|
+
tags.each_with_index do |pair, index|
|
141
|
+
key, value = pair
|
142
|
+
report_tag(SATELLITE_NAMESPACE, key, value, index == last_index)
|
143
|
+
end
|
103
144
|
end
|
104
145
|
end
|
105
146
|
end
|
@@ -165,7 +206,7 @@ module ForemanInventoryUpload
|
|
165
206
|
end.join(', '))
|
166
207
|
end
|
167
208
|
end
|
168
|
-
|
209
|
+
if !Setting[:insights_minimal_data_collection] && !Setting[:exclude_installed_packages]
|
169
210
|
@stream.array_field('installed_packages') do
|
170
211
|
first = true
|
171
212
|
host.installed_packages.each do |package|
|
@@ -30,6 +30,11 @@ module ForemanInventoryUpload
|
|
30
30
|
File.join(ForemanInventoryUpload.done_folder, filename)
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.report_file_paths(organization_id)
|
34
|
+
filename = facts_archive_name(organization_id)
|
35
|
+
Dir[ForemanInventoryUpload.uploads_file_path(filename), ForemanInventoryUpload.done_file_path(filename)]
|
36
|
+
end
|
37
|
+
|
33
38
|
def self.generated_reports_folder
|
34
39
|
@generated_reports_folder ||= ensure_folder(
|
35
40
|
File.join(
|
@@ -44,11 +44,12 @@ module ForemanRhCloud
|
|
44
44
|
setting('allow_auto_inventory_upload', type: :boolean, description: N_('Enable automatic upload of your host inventory to the Red Hat cloud'), default: true, full_name: N_('Automatic inventory upload'))
|
45
45
|
setting('allow_auto_insights_sync', type: :boolean, description: N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), default: true, full_name: N_('Synchronize recommendations Automatically'))
|
46
46
|
setting('allow_auto_insights_mismatch_delete', type: :boolean, description: N_('Enable automatic deletion of mismatched host records from the Red Hat cloud'), default: false, full_name: N_('Automatic mismatch deletion'))
|
47
|
-
setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host names'))
|
48
|
-
setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host ipv4 addresses'))
|
49
|
-
setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud'), default: false, full_name: N_("Exclude installed
|
47
|
+
setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored and host names are always obfuscated.)'), default: false, full_name: N_('Obfuscate host names'))
|
48
|
+
setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored and host ipv4 addresses are always obfuscated.)'), default: false, full_name: N_('Obfuscate host ipv4 addresses.'))
|
49
|
+
setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored and installed packages are always excluded.)'), default: false, full_name: N_("Exclude installed packages"))
|
50
50
|
setting('include_parameter_tags', type: :boolean, description: N_('Should import include parameter tags from Foreman?'), default: false, full_name: N_('Include parameters in insights-client reports'))
|
51
51
|
setting('rhc_instance_id', type: :string, description: N_('RHC daemon id'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
|
52
|
+
setting('insights_minimal_data_collection', type: :boolean, default: false, full_name: N_('Minimal data collection'), description: N_('Only send the minimum required data to Red Hat cloud, and obfuscate wherever possible. When this is true, hostnames and IPv4 addresses are always obfuscated and installed packages are excluded, regardless of those settings.'))
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -212,4 +213,15 @@ module ForemanRhCloud
|
|
212
213
|
def self.with_local_advisor_engine?
|
213
214
|
SETTINGS.dig(:foreman_rh_cloud, :use_local_advisor_engine) || false
|
214
215
|
end
|
216
|
+
|
217
|
+
def self.ca_cert
|
218
|
+
# The reference to candlepin ca_cert_file can be removed
|
219
|
+
# once the setting is dropped. Foreman 3.15 introduces
|
220
|
+
# a single CA file that bundles all CAs.
|
221
|
+
if ::SETTINGS.dig(:katello, :candlepin, :ca_cert_file)
|
222
|
+
::SETTINGS[:katello][:candlepin][:ca_cert_file]
|
223
|
+
else
|
224
|
+
::SETTINGS[:ssl_ca_file]
|
225
|
+
end
|
226
|
+
end
|
215
227
|
end
|
data/lib/foreman_rh_cloud.rb
CHANGED
data/package.json
CHANGED
@@ -98,13 +98,46 @@ module InsightsCloud::Api
|
|
98
98
|
assert_equal net_http_resp[:content_type], @response.headers['Content-Type']
|
99
99
|
end
|
100
100
|
|
101
|
+
test "should handle StandardError" do
|
102
|
+
error_message = "Connection refused"
|
103
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(Errno::ECONNREFUSED.new)
|
104
|
+
|
105
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
106
|
+
assert_equal 502, @response.status
|
107
|
+
body = JSON.parse(@response.body)
|
108
|
+
assert_equal error_message, body['error']
|
109
|
+
end
|
110
|
+
|
111
|
+
test "should handle 304 cloud" do
|
112
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 304, "Not Modified")
|
113
|
+
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
114
|
+
|
115
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::NotModified.new(res))
|
116
|
+
|
117
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
118
|
+
assert_equal 304, @response.status
|
119
|
+
assert_equal 'Cloud request not modified', JSON.parse(@response.body)['message']
|
120
|
+
end
|
121
|
+
|
122
|
+
test "should handle RestClient::Exceptions::Timeout" do
|
123
|
+
timeout_message = "execution expired"
|
124
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::Exceptions::Timeout.new(timeout_message))
|
125
|
+
|
126
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
127
|
+
assert_equal 504, @response.status
|
128
|
+
body = JSON.parse(@response.body)
|
129
|
+
assert_equal timeout_message, body['message']
|
130
|
+
assert_equal timeout_message, body['error']
|
131
|
+
end
|
132
|
+
|
101
133
|
test "should handle failed authentication to cloud" do
|
102
134
|
net_http_resp = Net::HTTPResponse.new(1.0, 401, "Unauthorized")
|
103
135
|
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
104
|
-
|
136
|
+
|
137
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::Unauthorized.new(res))
|
105
138
|
|
106
139
|
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
107
|
-
assert_equal
|
140
|
+
assert_equal 401, @response.status
|
108
141
|
assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
|
109
142
|
end
|
110
143
|
|