foreman_openscap 0.4.3 → 0.5.0
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/app/assets/javascripts/foreman_openscap/load_report.js +1 -1
- data/app/assets/javascripts/foreman_openscap/policy_edit.js +0 -2
- data/app/controllers/api/v2/compliance/arf_reports_controller.rb +7 -22
- data/app/controllers/api/v2/compliance/policies_controller.rb +5 -5
- data/app/controllers/api/v2/compliance/scap_contents_controller.rb +3 -3
- data/app/controllers/arf_reports_controller.rb +62 -0
- data/app/controllers/{scaptimony_dashboard_controller.rb → compliance_dashboard_controller.rb} +1 -1
- data/app/controllers/compliance_hosts_controller.rb +5 -0
- data/app/controllers/{scaptimony_policies_controller.rb → policies_controller.rb} +13 -13
- data/app/controllers/{scaptimony_policy_dashboard_controller.rb → policy_dashboard_controller.rb} +3 -3
- data/app/controllers/{scaptimony_scap_contents_controller.rb → scap_contents_controller.rb} +11 -11
- data/app/helpers/{scaptimony_report_dashboard_helper.rb → arf_report_dashboard_helper.rb} +3 -5
- data/app/helpers/arf_reports_helper.rb +21 -0
- data/app/helpers/compliance_hosts_helper.rb +25 -0
- data/app/helpers/concerns/foreman_openscap/hosts_helper_extensions.rb +2 -32
- data/app/helpers/{scaptimony_policies_helper.rb → policies_helper.rb} +6 -2
- data/app/helpers/{scaptimony_policy_dashboard_helper.rb → policy_dashboard_helper.rb} +8 -8
- data/app/lib/proxy_api/available_proxy.rb +26 -0
- data/app/lib/proxy_api/openscap.rb +40 -0
- data/app/mailers/foreman_openscap/policy_mailer.rb +42 -0
- data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +91 -0
- data/app/models/concerns/foreman_openscap/host_extensions.rb +73 -17
- data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +3 -5
- data/app/models/foreman_openscap/arf_report.rb +165 -0
- data/app/models/foreman_openscap/asset.rb +27 -0
- data/app/models/foreman_openscap/asset_policy.rb +6 -0
- data/app/models/foreman_openscap/compliance_status.rb +50 -0
- data/app/models/{concerns/foreman_openscap/policy_extensions.rb → foreman_openscap/policy.rb} +72 -45
- data/app/models/foreman_openscap/policy_arf_report.rb +8 -0
- data/app/models/foreman_openscap/policy_revision.rb +6 -0
- data/app/models/foreman_openscap/scap_content.rb +112 -0
- data/app/models/foreman_openscap/scap_content_profile.rb +6 -0
- data/app/overrides/hosts/overview/host_compliance_status.rb +4 -4
- data/app/services/foreman_openscap/arf_report_status_calculator.rb +45 -0
- data/app/services/{scaptimony → foreman_openscap}/host_report_dashboard/data.rb +12 -6
- data/app/services/{scaptimony → foreman_openscap}/policy_dashboard/data.rb +5 -5
- data/app/services/{scaptimony → foreman_openscap}/report_dashboard/data.rb +4 -4
- data/app/views/api/v2/compliance/policies/create.json.rabl +3 -0
- data/app/views/{scaptimony_arf_reports → arf_reports}/_list.html.erb +4 -4
- data/app/views/arf_reports/_metrics.html.erb +37 -0
- data/app/views/arf_reports/_output.html.erb +23 -0
- data/app/views/{scaptimony_arf_reports → arf_reports}/index.html.erb +0 -0
- data/app/views/arf_reports/show.html.erb +14 -0
- data/app/views/{scaptimony_arf_reports/show.html.erb → arf_reports/show_html.html.erb} +2 -3
- data/app/views/compliance_hosts/_compliance_status.erb +6 -0
- data/app/views/{scaptimony_hosts → compliance_hosts}/show.html.erb +9 -2
- data/app/views/dashboard/{_foreman_openscap_host_reports_widget.html.erb → _compliance_host_reports_widget.html.erb} +3 -3
- data/app/views/dashboard/{_foreman_openscap_reports_breakdown_widget.html.erb → _compliance_reports_breakdown_widget.html.erb} +1 -1
- data/app/views/foreman_openscap/policy_mailer/_dashboard.erb +21 -0
- data/app/views/foreman_openscap/policy_mailer/_hosts.erb +44 -0
- data/app/views/foreman_openscap/policy_mailer/_list.erb +10 -0
- data/app/views/foreman_openscap/policy_mailer/_policy.erb +7 -0
- data/app/views/foreman_openscap/policy_mailer/policy_summary.erb +19 -0
- data/app/views/{scaptimony_policies → policies}/_form.html.erb +2 -8
- data/app/views/{scaptimony_policies → policies}/_list.html.erb +5 -5
- data/app/views/policies/_scap_content_results.html.erb +3 -0
- data/app/views/policies/create.html.erb +2 -0
- data/app/views/{scaptimony_policies → policies}/disassociate_multiple_hosts.html.erb +2 -2
- data/app/views/{scaptimony_policies → policies}/edit.html.erb +0 -0
- data/app/views/{scaptimony_policies → policies}/index.html.erb +1 -1
- data/app/views/policies/new.html.erb +2 -0
- data/app/views/{scaptimony_policies → policies}/select_multiple_hosts.html.erb +2 -2
- data/app/views/{scaptimony_policies → policies}/show.html.erb +1 -1
- data/app/views/{scaptimony_policies → policies}/steps/_create_policy_form.html.erb +0 -0
- data/app/views/{scaptimony_policies → policies}/steps/_hostgroups_form.html.erb +0 -0
- data/app/views/{scaptimony_policies → policies}/steps/_locations_form.html.erb +0 -0
- data/app/views/{scaptimony_policies → policies}/steps/_organizations_form.html.erb +0 -0
- data/app/views/policies/steps/_scap_content_form.html.erb +9 -0
- data/app/views/{scaptimony_policies → policies}/steps/_schedule_form.html.erb +1 -1
- data/app/views/{scaptimony_policies → policies}/steps/_step_form.html.erb +3 -3
- data/app/views/{scaptimony_policies → policies}/welcome.html.erb +2 -2
- data/app/views/{scaptimony_policy_dashboard → policy_dashboard}/_policy_chart_widget.html.erb +0 -0
- data/app/views/{scaptimony_policy_dashboard → policy_dashboard}/_policy_reports.html.erb +2 -2
- data/app/views/{scaptimony_policy_dashboard → policy_dashboard}/_policy_status_widget.html.erb +3 -3
- data/app/views/{scaptimony_policy_dashboard → policy_dashboard}/index.html.erb +0 -0
- data/app/views/{scaptimony_scap_contents → scap_contents}/_form.html.erb +5 -6
- data/app/views/{scaptimony_scap_contents → scap_contents}/_list.html.erb +3 -3
- data/app/views/{scaptimony_scap_contents → scap_contents}/edit.html.erb +0 -0
- data/app/views/{scaptimony_scap_contents → scap_contents}/index.html.erb +1 -1
- data/app/views/{scaptimony_scap_contents → scap_contents}/new.html.erb +0 -0
- data/app/views/{scaptimony_scap_contents → scap_contents}/welcome.html.erb +2 -2
- data/config/routes.rb +15 -11
- data/db/migrate/20141013172051_create_scaptimony_policies.rb +9 -0
- data/db/migrate/20141014105333_create_scaptimony_assets.rb +10 -0
- data/db/migrate/20141015092642_create_scaptimony_arf_reports.rb +13 -0
- data/db/migrate/20141015115511_add_arf_report_unique_constraint.rb +6 -0
- data/db/migrate/20141104164201_create_scaptimony_scap_contents.rb +7 -0
- data/db/migrate/20141104171545_create_scaptimony_policy_revisions.rb +14 -0
- data/db/migrate/20141105174625_add_description_to_scaptimony_policy_revisions.rb +5 -0
- data/db/migrate/20141105174834_add_columns_to_scaptimony_policies.rb +12 -0
- data/db/migrate/20141107091756_add_columns_to_scaptimony_scap_contents.rb +8 -0
- data/db/migrate/20141111104519_add_constraint_to_scaptimony_scap_contents.rb +5 -0
- data/db/migrate/20141113221054_create_scaptimony_scap_content_profiles.rb +12 -0
- data/db/migrate/20141116170632_remove_xccdf_profile_from_scaptimony_policies.rb +5 -0
- data/db/migrate/20141116171305_add_profile_to_scaptimony_policies.rb +6 -0
- data/db/migrate/20141118142954_add_constraint_to_scaptimony_policies.rb +5 -0
- data/db/migrate/20141119164918_create_scaptimony_xccdf_results.rb +8 -0
- data/db/migrate/20141119175434_create_scaptimony_xccdf_rules.rb +8 -0
- data/db/migrate/20141119182606_create_scaptimony_xccdf_rule_results.rb +9 -0
- data/db/migrate/20141121120326_create_scaptimony_arf_report_breakdowns.rb +24 -0
- data/db/migrate/20141121164042_replace_arf_report_breakdown_view.rb +25 -0
- data/db/migrate/20141206211151_create_scaptimony_assets_policies.rb +9 -0
- data/db/migrate/20141214112917_add_scap_file_to_scap_content.rb +5 -0
- data/db/migrate/20141216154502_rename_scaptimony_asset_policies.rb +5 -0
- data/db/migrate/20150111085317_polymorph_asset.rb +8 -0
- data/db/migrate/20150112152944_create_scaptimony_arf_report_raws.rb +10 -0
- data/db/migrate/20150114210634_rename_scaptimony_arf_report_raw_raw.rb +5 -0
- data/db/migrate/20150115155947_add_scaptimony_scap_content_digest.rb +21 -0
- data/db/migrate/20150116083129_add_day_of_month_and_cron_line_to_scaptimony_policy.rb +6 -0
- data/db/migrate/20150821100137_migrate_from_scaptimony.rb +59 -0
- data/db/migrate/20150827123826_remove_scaptimony_permissions.rb +21 -0
- data/db/migrate/20150925124959_create_policy_arf_reports.rb +13 -0
- data/db/migrate/20150929124853_add_result_to_logs.rb +9 -0
- data/db/migrate/20150929152345_move_arf_reports_to_reports_table.rb +179 -0
- data/db/migrate/20151023131950_link_arf_report_directly_to_host.rb +17 -0
- data/db/seeds.d/openscap_policy_notification.rb +9 -0
- data/lib/foreman_openscap/bulk_upload.rb +3 -1
- data/lib/foreman_openscap/engine.rb +53 -42
- data/lib/foreman_openscap/helper.rb +8 -0
- data/lib/foreman_openscap/version.rb +1 -1
- data/lib/tasks/foreman_openscap_tasks.rake +14 -0
- data/test/factories/arf_report_factory.rb +9 -6
- data/test/factories/asset_factory.rb +1 -1
- data/test/factories/compliance_host_factory.rb +9 -0
- data/test/factories/compliance_log_factory.rb +11 -0
- data/test/factories/policy_arf_report_factory.rb +6 -0
- data/test/factories/policy_factory.rb +3 -2
- data/test/factories/scap_content_related.rb +2 -2
- data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +4 -3
- data/test/functional/api/v2/compliance/policies_controller_test.rb +2 -2
- data/test/functional/api/v2/compliance/scap_contents_controller_test.rb +3 -1
- data/test/lib/foreman_openscap/bulk_upload_test.rb +1 -1
- data/test/test_plugin_helper.rb +30 -0
- data/test/unit/arf_report_status_calculator_test.rb +11 -0
- data/test/unit/arf_report_test.rb +148 -0
- data/test/unit/compliance_status_test.rb +71 -0
- data/test/unit/openscap_host_test.rb +38 -7
- data/test/unit/policy_mailer_test.rb +38 -0
- data/test/unit/scap_content_test.rb +32 -0
- metadata +130 -74
- data/app/controllers/scaptimony_arf_reports_controller.rb +0 -34
- data/app/controllers/scaptimony_hosts_controller.rb +0 -5
- data/app/models/concerns/foreman_openscap/arf_report_extensions.rb +0 -50
- data/app/models/concerns/foreman_openscap/asset_extensions.rb +0 -34
- data/app/models/concerns/foreman_openscap/scap_content_extensions.rb +0 -40
- data/app/overrides/hosts/index/host_arf_report.rb +0 -5
- data/app/views/scaptimony_arf_reports/_host_report.html.erb +0 -8
- data/app/views/scaptimony_hosts/_host_status.html.erb +0 -17
- data/app/views/scaptimony_policies/_scap_content_results.html.erb +0 -7
- data/app/views/scaptimony_policies/create.html.erb +0 -2
- data/app/views/scaptimony_policies/new.html.erb +0 -2
- data/app/views/scaptimony_policies/steps/_scap_content_form.html.erb +0 -17
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class CreateScaptimonyXccdfRuleResults < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :scaptimony_xccdf_rule_results do |t|
|
|
4
|
+
t.references :arf_report, index: true, null: false
|
|
5
|
+
t.references :xccdf_result, index: true, null: false
|
|
6
|
+
t.references :xccdf_rule, index: true, null: false
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class CreateScaptimonyArfReportBreakdowns < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
execute <<-SQL
|
|
4
|
+
CREATE VIEW scaptimony_arf_report_breakdowns AS
|
|
5
|
+
SELECT
|
|
6
|
+
arf.id as arf_report_id,
|
|
7
|
+
COUNT(CASE WHEN result.name IN ('pass','fixed') THEN 1 ELSE null END) as passed,
|
|
8
|
+
COUNT(CASE result.name WHEN 'fail' THEN 1 ELSE null END) as failed,
|
|
9
|
+
COUNT(CASE WHEN result.name NOT IN ('pass', 'fixed', 'fail', 'notselected', 'notapplicable') THEN 1 ELSE null END) as othered
|
|
10
|
+
FROM
|
|
11
|
+
scaptimony_arf_reports arf,
|
|
12
|
+
scaptimony_xccdf_rule_results rule,
|
|
13
|
+
scaptimony_xccdf_results result
|
|
14
|
+
WHERE
|
|
15
|
+
arf.id = rule.arf_report_id
|
|
16
|
+
AND rule.xccdf_result_id = result.id
|
|
17
|
+
GROUP BY arf.id;
|
|
18
|
+
SQL
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.down
|
|
22
|
+
execute 'DROP VIEW scaptimony_arf_report_breakdowns' if table_exists? 'scaptimony_arf_report_breakdowns'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class ReplaceArfReportBreakdownView < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
execute 'DROP VIEW IF EXISTS scaptimony_arf_report_breakdowns'
|
|
4
|
+
execute <<-SQL
|
|
5
|
+
CREATE VIEW scaptimony_arf_report_breakdowns AS
|
|
6
|
+
SELECT
|
|
7
|
+
arf.id as arf_report_id,
|
|
8
|
+
COUNT(CASE WHEN result.name IN ('pass','fixed') THEN 1 ELSE null END) as passed,
|
|
9
|
+
COUNT(CASE result.name WHEN 'fail' THEN 1 ELSE null END) as failed,
|
|
10
|
+
COUNT(CASE WHEN result.name NOT IN ('pass', 'fixed', 'fail', 'notselected', 'notapplicable') THEN 1 ELSE null END) as othered
|
|
11
|
+
FROM
|
|
12
|
+
scaptimony_arf_reports arf
|
|
13
|
+
LEFT OUTER JOIN
|
|
14
|
+
scaptimony_xccdf_rule_results rule
|
|
15
|
+
ON arf.id = rule.arf_report_id
|
|
16
|
+
LEFT OUTER JOIN scaptimony_xccdf_results result
|
|
17
|
+
ON rule.xccdf_result_id = result.id
|
|
18
|
+
GROUP BY arf.id;
|
|
19
|
+
SQL
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.down
|
|
23
|
+
execute 'DROP VIEW scaptimony_arf_report_breakdowns' if table_exists? 'scaptimony_arf_report_breakdowns'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class CreateScaptimonyAssetsPolicies < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :scaptimony_assets_policies, :id => false do |t|
|
|
4
|
+
t.references :asset, :index => true, :null => false
|
|
5
|
+
t.references :policy, :index => true, :null => false
|
|
6
|
+
end
|
|
7
|
+
add_index :scaptimony_assets_policies, [:asset_id, :policy_id], :unique => true
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class CreateScaptimonyArfReportRaws < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :scaptimony_arf_report_raws, :id => false do |t|
|
|
4
|
+
t.references :arf_report, :index => true, :null => false
|
|
5
|
+
t.integer :size
|
|
6
|
+
t.binary :raw
|
|
7
|
+
end
|
|
8
|
+
add_index :scaptimony_arf_report_raws, [:arf_report_id], :unique => true
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'digest/sha2'
|
|
2
|
+
|
|
3
|
+
class AddScaptimonyScapContentDigest < ActiveRecord::Migration
|
|
4
|
+
def change
|
|
5
|
+
unless column_exists?(:scaptimony_scap_contents, :digest)
|
|
6
|
+
add_column :scaptimony_scap_contents, :digest, :string, :limit => 128
|
|
7
|
+
ScapContentHack.find_each do |content|
|
|
8
|
+
content.digest
|
|
9
|
+
content.save!
|
|
10
|
+
end
|
|
11
|
+
change_column :scaptimony_scap_contents, :digest, :string, :null => false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class ScapContentHack < ActiveRecord::Base
|
|
16
|
+
self.table_name = 'scaptimony_scap_contents'
|
|
17
|
+
def digest
|
|
18
|
+
self[:digest] ||= Digest::SHA256.hexdigest "#{scap_file}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class MigrateFromScaptimony < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
ActiveRecord::Base.connection.tables.grep(/^scaptimony/).each do |table|
|
|
4
|
+
rename_table table, table.sub(/^scaptimony/, "foreman_openscap")
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
execute 'DROP VIEW scaptimony_arf_report_breakdowns' if table_exists? 'scaptimony_arf_report_breakdowns'
|
|
8
|
+
execute 'DROP VIEW foreman_openscap_arf_report_breakdowns' if table_exists? 'foreman_openscap_arf_report_breakdowns'
|
|
9
|
+
|
|
10
|
+
execute <<-SQL
|
|
11
|
+
CREATE VIEW foreman_openscap_arf_report_breakdowns AS
|
|
12
|
+
SELECT
|
|
13
|
+
arf.id as arf_report_id,
|
|
14
|
+
COUNT(CASE WHEN result.name IN ('pass','fixed') THEN 1 ELSE null END) as passed,
|
|
15
|
+
COUNT(CASE result.name WHEN 'fail' THEN 1 ELSE null END) as failed,
|
|
16
|
+
COUNT(CASE WHEN result.name NOT IN ('pass', 'fixed', 'fail', 'notselected', 'notapplicable') THEN 1 ELSE null END) as othered
|
|
17
|
+
FROM
|
|
18
|
+
foreman_openscap_arf_reports arf
|
|
19
|
+
LEFT OUTER JOIN
|
|
20
|
+
foreman_openscap_xccdf_rule_results rule
|
|
21
|
+
ON arf.id = rule.arf_report_id
|
|
22
|
+
LEFT OUTER JOIN foreman_openscap_xccdf_results result
|
|
23
|
+
ON rule.xccdf_result_id = result.id
|
|
24
|
+
GROUP BY arf.id;
|
|
25
|
+
SQL
|
|
26
|
+
|
|
27
|
+
taxonomies = TaxableTaxonomy.where(:taxable_type => ["Scaptimony::ArfReport", "Scaptimony::Policy", "Scaptimony::ScapContent"])
|
|
28
|
+
taxonomies.each { |t| t.taxable_type = t.taxable_type.sub(/^Scaptimony/, "ForemanOpenscap")}.map(&:save!)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def down
|
|
32
|
+
ActiveRecord::Base.connection.tables.grep(/^foreman_openscap/).each do |table|
|
|
33
|
+
rename_table table, table.sub(/^foreman_openscap/, "scaptimony")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
execute 'DROP VIEW scaptimony_arf_report_breakdowns' if table_exists? 'scaptimony_arf_report_breakdowns'
|
|
37
|
+
execute 'DROP VIEW foreman_openscap_arf_report_breakdowns' if table_exists? 'foreman_openscap_arf_report_breakdowns'
|
|
38
|
+
|
|
39
|
+
execute <<-SQL
|
|
40
|
+
CREATE VIEW scaptimony_arf_report_breakdowns AS
|
|
41
|
+
SELECT
|
|
42
|
+
arf.id as arf_report_id,
|
|
43
|
+
COUNT(CASE WHEN result.name IN ('pass','fixed') THEN 1 ELSE null END) as passed,
|
|
44
|
+
COUNT(CASE result.name WHEN 'fail' THEN 1 ELSE null END) as failed,
|
|
45
|
+
COUNT(CASE WHEN result.name NOT IN ('pass', 'fixed', 'fail', 'notselected', 'notapplicable') THEN 1 ELSE null END) as othered
|
|
46
|
+
FROM
|
|
47
|
+
scaptimony_arf_reports arf
|
|
48
|
+
LEFT OUTER JOIN
|
|
49
|
+
scaptimony_xccdf_rule_results rule
|
|
50
|
+
ON arf.id = rule.arf_report_id
|
|
51
|
+
LEFT OUTER JOIN scaptimony_xccdf_results result
|
|
52
|
+
ON rule.xccdf_result_id = result.id
|
|
53
|
+
GROUP BY arf.id;
|
|
54
|
+
SQL
|
|
55
|
+
|
|
56
|
+
taxonomies = TaxableTaxonomy.where(:taxable_type => ["ForemanOpenscap::ArfReport", "ForemanOpenscap::Policy", "ForemanOpenscap::ScapContent"])
|
|
57
|
+
taxonomies.each { |t| t.taxable_type = t.taxable_type.sub(/^ForemanOpenscap/, "Scaptimony")}.map(&:save!)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class RemoveScaptimonyPermissions < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
permissions = Permission.where(:resource_type => ["Scaptimony::Policy", "Scaptimony::ScapContent"])
|
|
4
|
+
new_type = "ForemanOpenscap"
|
|
5
|
+
permissions.each do |p|
|
|
6
|
+
say "Converting permission '#{p.id}' with name '#{p.name}' of type '#{p.resource_type}' to new type '#{new_type}'"
|
|
7
|
+
p.resource_type = p.resource_type.sub(/^Scaptimony/, new_type)
|
|
8
|
+
p.save!
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def down
|
|
13
|
+
permissions = Permission.where(:resource_type => ["ForemanOpenscap::Policy", "ForemanOpenscap::ScapContent"])
|
|
14
|
+
permissions.each do |p|
|
|
15
|
+
old_type = "Scaptimony"
|
|
16
|
+
say "Converting permission '#{p.id}' with name '#{p.name}' of type '#{p.resource_type}' to new type '#{old_type}'"
|
|
17
|
+
p.resource_type = p.resource_type.sub(/^ForemanOpenscap/, old_type)
|
|
18
|
+
p.save!
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class CreatePolicyArfReports < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
create_table :foreman_openscap_policy_arf_reports do |t|
|
|
4
|
+
t.integer :policy_id
|
|
5
|
+
t.integer :arf_report_id
|
|
6
|
+
t.string :digest, :limit => 128
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def down
|
|
11
|
+
drop_table :foreman_openscap_policy_arf_reports
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
class MoveArfReportsToReportsTable < ActiveRecord::Migration
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Metrics/MethodLength
|
|
4
|
+
# rubocop:disable Metrics/AbcSize
|
|
5
|
+
def up
|
|
6
|
+
old_arf_reports = execute("SELECT * FROM foreman_openscap_arf_reports;")
|
|
7
|
+
|
|
8
|
+
#select only reports with existing host
|
|
9
|
+
old_arf_reports = old_arf_reports.select do |item|
|
|
10
|
+
asset = ForemanOpenscap::Asset.find item['asset_id']
|
|
11
|
+
!asset.host.nil? && asset.assetable_type = "Host::Base"
|
|
12
|
+
end
|
|
13
|
+
#and remove assets without assetable
|
|
14
|
+
ForemanOpenscap::Asset.where(:assetable_type => "Host::Base").select { |a| a.host.nil? }.map(&:destroy)
|
|
15
|
+
ForemanOpenscap::Asset.where(:assetable_type => "Hostgroup").select { |a| a.hostgroup.nil? }.map(&:destroy)
|
|
16
|
+
|
|
17
|
+
old_arf_reports.each do |item|
|
|
18
|
+
metrics = breakdown_to_metrics item["id"]
|
|
19
|
+
|
|
20
|
+
#reported_at attribute must be unique
|
|
21
|
+
reported_at = DateTime.strptime(item["created_at"], "%Y-%m-%d %H:%M:%S")
|
|
22
|
+
|
|
23
|
+
reported_at += 1.seconds until arfs_by_reported(reported_at).empty?
|
|
24
|
+
|
|
25
|
+
arf = ForemanOpenscap::ArfReport.create!(:metrics => metrics,
|
|
26
|
+
:reported_at => reported_at,
|
|
27
|
+
:created_at => item["created_at"],
|
|
28
|
+
:updated_at => item["updated_at"],
|
|
29
|
+
:host_id => item["asset_id"],
|
|
30
|
+
:status => metrics)
|
|
31
|
+
|
|
32
|
+
ForemanOpenscap::PolicyArfReport.create!(:arf_report_id => arf.id, :policy_id => item["policy_id"], :digest => item["digest"])
|
|
33
|
+
|
|
34
|
+
xccdf_rules.each { |rule_item| Source.find_or_create(rule_item["xid"]) }
|
|
35
|
+
|
|
36
|
+
xccdf_rule_results(item["id"]).each do |rr_item|
|
|
37
|
+
message = Message.find_or_create("No message for this log")
|
|
38
|
+
|
|
39
|
+
rule_item = xccdf_rule(rr_item['xccdf_rule_id'])
|
|
40
|
+
source = Source.find_or_create(rule_item['xid'])
|
|
41
|
+
|
|
42
|
+
Log.create!(:report_id => arf.id,
|
|
43
|
+
:result => xccdf_result(rr_item["xccdf_result_id"])['name'],
|
|
44
|
+
:message_id => message.id,
|
|
45
|
+
:source_id => source.id,
|
|
46
|
+
:level => :info)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
execute 'DROP VIEW foreman_openscap_arf_report_breakdowns' if table_exists? 'foreman_openscap_arf_report_breakdowns'
|
|
51
|
+
drop_table :foreman_openscap_xccdf_results
|
|
52
|
+
drop_table :foreman_openscap_xccdf_rules
|
|
53
|
+
drop_table :foreman_openscap_xccdf_rule_results
|
|
54
|
+
drop_table :foreman_openscap_arf_reports
|
|
55
|
+
drop_table :foreman_openscap_arf_report_raws
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def down
|
|
59
|
+
#warning! we cannot fully revert since arf_report_raws got dropped and we have no way of recreating them
|
|
60
|
+
create_table :foreman_openscap_arf_reports do |t|
|
|
61
|
+
t.references :asset, :index => true
|
|
62
|
+
t.references :policy, :index => true
|
|
63
|
+
t.datetime :date
|
|
64
|
+
t.string :digest, :limit => 128
|
|
65
|
+
|
|
66
|
+
t.timestamps
|
|
67
|
+
end
|
|
68
|
+
add_index :foreman_openscap_arf_reports, :digest, :unique => true
|
|
69
|
+
|
|
70
|
+
add_index :foreman_openscap_arf_reports, [:asset_id, :policy_id, :date, :digest],
|
|
71
|
+
:unique => true, :name => :index_openscap_arf_reports_unique_set
|
|
72
|
+
|
|
73
|
+
create_table :foreman_openscap_xccdf_results do |t|
|
|
74
|
+
t.string :name, :limit => 16, :null => false
|
|
75
|
+
end
|
|
76
|
+
add_index :foreman_openscap_xccdf_results, [:name], :unique => true
|
|
77
|
+
|
|
78
|
+
create_table :foreman_openscap_xccdf_rules do |t|
|
|
79
|
+
t.string :xid, :null => false
|
|
80
|
+
end
|
|
81
|
+
add_index :foreman_openscap_xccdf_rules, [:xid], :unique => true
|
|
82
|
+
|
|
83
|
+
create_table :foreman_openscap_xccdf_rule_results do |t|
|
|
84
|
+
t.references :arf_report, :index => true, :null => false
|
|
85
|
+
t.references :xccdf_result, :index => true, :null => false
|
|
86
|
+
t.references :xccdf_rule, :index => true, :null => false
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
create_table :foreman_openscap_arf_report_raws, :id => false do |t|
|
|
90
|
+
t.references :arf_report, :index => true, :null => false
|
|
91
|
+
t.integer :size
|
|
92
|
+
t.binary :raw
|
|
93
|
+
end
|
|
94
|
+
add_index :foreman_openscap_arf_report_raws, [:arf_report_id], :unique => true
|
|
95
|
+
|
|
96
|
+
execute <<-SQL
|
|
97
|
+
CREATE VIEW foreman_openscap_arf_report_breakdowns AS
|
|
98
|
+
SELECT
|
|
99
|
+
arf.id as arf_report_id,
|
|
100
|
+
COUNT(CASE WHEN result.name IN ('pass','fixed') THEN 1 ELSE null END) as passed,
|
|
101
|
+
COUNT(CASE result.name WHEN 'fail' THEN 1 ELSE null END) as failed,
|
|
102
|
+
COUNT(CASE WHEN result.name NOT IN ('pass', 'fixed', 'fail', 'notselected', 'notapplicable') THEN 1 ELSE null END) as othered
|
|
103
|
+
FROM
|
|
104
|
+
foreman_openscap_arf_reports arf
|
|
105
|
+
LEFT OUTER JOIN
|
|
106
|
+
foreman_openscap_xccdf_rule_results rule
|
|
107
|
+
ON arf.id = rule.arf_report_id
|
|
108
|
+
LEFT OUTER JOIN foreman_openscap_xccdf_results result
|
|
109
|
+
ON rule.xccdf_result_id = result.id
|
|
110
|
+
GROUP BY arf.id;
|
|
111
|
+
SQL
|
|
112
|
+
|
|
113
|
+
ForemanOpenscap::ArfReport::RESULT.each do |n|
|
|
114
|
+
execute("INSERT INTO foreman_openscap_xccdf_results (name) VALUES ('#{n}');")
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
ForemanOpenscap::ArfReport.order('id').each do |arf|
|
|
118
|
+
execute("INSERT INTO foreman_openscap_arf_reports (asset_id, policy_id, date, digest, created_at, updated_at)
|
|
119
|
+
VALUES ('#{arf.host_id}', '#{arf.policy.id}', '#{arf.reported_at}',
|
|
120
|
+
'#{arf.policy_arf_report.digest}', '#{arf.created_at}', '#{arf.updated_at}');")
|
|
121
|
+
record = report(arf)
|
|
122
|
+
arf.logs.each do |log|
|
|
123
|
+
xccdf_result_item = execute("SELECT * FROM foreman_openscap_xccdf_results WHERE name = '#{log.result}';").first
|
|
124
|
+
xccdf_rule_item = execute("SELECT * FROM foreman_openscap_xccdf_rules WHERE xid = '#{log.source.value}';").first
|
|
125
|
+
unless xccdf_rule_item
|
|
126
|
+
execute("INSERT INTO foreman_openscap_xccdf_rules (xid) VALUES ('#{log.source.value}');")
|
|
127
|
+
xccdf_rule_item = execute("SELECT * FROM foreman_openscap_xccdf_rules WHERE xid = '#{log.source.value}';").first
|
|
128
|
+
end
|
|
129
|
+
execute("INSERT INTO foreman_openscap_xccdf_rule_results (arf_report_id, xccdf_result_id, xccdf_rule_id)
|
|
130
|
+
VALUES ('#{record['id']}', '#{xccdf_result_item['id']}', '#{xccdf_rule_item['id']}');")
|
|
131
|
+
msg = log.message
|
|
132
|
+
src = log.source
|
|
133
|
+
log.destroy
|
|
134
|
+
msg.destroy if msg.logs.empty?
|
|
135
|
+
src.destroy if src.logs.empty?
|
|
136
|
+
end
|
|
137
|
+
# arf.destroy fires arf_report_raw.destroy
|
|
138
|
+
execute("DELETE FROM reports WHERE id = '#{arf.id}';")
|
|
139
|
+
end
|
|
140
|
+
ForemanOpenscap::PolicyArfReport.all.map(&:destroy)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
private
|
|
144
|
+
|
|
145
|
+
def breakdown_to_metrics(report_id)
|
|
146
|
+
execute("SELECT passed, failed, othered FROM foreman_openscap_arf_report_breakdowns WHERE arf_report_id='#{report_id}';").first
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def xccdf_rule_results(report_id)
|
|
150
|
+
execute("SELECT arf_report_id, xccdf_result_id, xccdf_rule_id
|
|
151
|
+
FROM foreman_openscap_xccdf_rule_results
|
|
152
|
+
WHERE arf_report_id='#{report_id}';")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def xccdf_rules
|
|
156
|
+
execute("SELECT xid FROM foreman_openscap_xccdf_rules;")
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def xccdf_rule(rule_id)
|
|
160
|
+
execute("SELECT xid
|
|
161
|
+
FROM foreman_openscap_xccdf_rules
|
|
162
|
+
WHERE foreman_openscap_xccdf_rules.id = '#{rule_id}';").first
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def xccdf_result(result_id)
|
|
166
|
+
execute("SELECT name FROM foreman_openscap_xccdf_results WHERE id = '#{result_id}';").first
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def arfs_by_reported(time)
|
|
170
|
+
ForemanOpenscap::ArfReport.where(:reported_at => time)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def report(arf)
|
|
174
|
+
execute("SELECT id
|
|
175
|
+
FROM foreman_openscap_arf_reports
|
|
176
|
+
WHERE date = '#{arf.reported_at}' AND
|
|
177
|
+
digest = '#{arf.policy_arf_report.digest}';").first
|
|
178
|
+
end
|
|
179
|
+
end
|