foreman_openscap 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0895db81e437924a55b31bb9abe2f1a4f217d6e6108b1324fc52af3950aacd33'
4
- data.tar.gz: 5031307c30cddd992d58e0cd4b855b3cdc7e43dfe766947df66adf8154d8a048
3
+ metadata.gz: 629a167f8a2ea481556fa422d375bc3a85ad1c9a2ed78d3976796d7a1631c7f1
4
+ data.tar.gz: bed0c059fae8275515b39faa672553a805e6a4b91612e4b1d0b9b8bd6ed4ba30
5
5
  SHA512:
6
- metadata.gz: fa6478fc462f96ca1ba815c8369476e58e253bb1ed01307e81895c28ed6e7684602029949233a7e7d89ba8cba6f73d197f5fef76746273120f94ab26aa3acec8
7
- data.tar.gz: 0a97a049d86e101f303316b4b49d0b21864c207884fd1ca45b19456735159f8cb1e2b4d762057d078668dcfe7c729b50665d3f7290dab2c20e2b3995ee15128f
6
+ metadata.gz: 25197b4a417ebfdb3f1a757015caab03dba232e2a2e667b01e84a4f666a8d3dea713aab3bd6794ed0809e1e147d9306e830318f75f7a46f57126914e572f4f5d
7
+ data.tar.gz: 136a1b268b7164ae19ba5daf4f13dac82fdc08f20697370b8820d6ff49cb6f28189af63821cc91c0097177cb22fa766774a18d944ebc8e4d4f6a55b966a30e6f
@@ -1,4 +1,4 @@
1
1
  $(function() {
2
2
  // Not sure about this ugly hack.
3
- $('.col-md-4 .stats-well').height($('.col-md-8 .stats-well').height() + 28);
3
+ $('.col-md-4 .stats-well').height($('.col-md-8 .stats-well').height());
4
4
  });
@@ -0,0 +1,26 @@
1
+ .scap-breakdown-chart {
2
+ margin: 25px auto 12px;
3
+ width: 240px;
4
+ }
5
+
6
+ #arf-report-breakdown-chart {
7
+ margin-top: 58px;
8
+ padding-bottom: 50px;
9
+ }
10
+
11
+ .scap-breakdown-chart-col {
12
+ min-width: 340px;
13
+ }
14
+
15
+ .arf-report-rule-chart-col {
16
+ min-width: 440px;
17
+ }
18
+
19
+ .metrics-stats-row {
20
+ padding-top: 20px;
21
+ }
22
+
23
+ #arf-report-rule-chart .bar-chart-pf {
24
+ max-width: fit-content;
25
+ margin: auto;
26
+ }
@@ -5,13 +5,28 @@ module ArfReportDashboardHelper
5
5
  :othered => '#DB843D',
6
6
  }.freeze
7
7
 
8
- def reports_breakdown_chart(report, options = {})
9
- data = []
10
- [[:failed, _('Failed')],
11
- [:passed, _('Passed')],
12
- [:othered, _('Othered')],].each do |i|
13
- data << { :label => i[1], :data => report[i[0]], :color => COLORS[i[0]] }
8
+ def breakdown_chart_data(categories, report, colors = COLORS)
9
+ data = categories.reduce([]) do |memo, (key, value)|
10
+ memo << [value, report[key], colors[key]]
14
11
  end
15
- flot_pie_chart 'overview', _('Compliance reports breakdown'), data, options
12
+
13
+ data.to_json
14
+ end
15
+
16
+ def donut_breakdown_chart_data(report)
17
+ categories = {
18
+ :failed => _('Failed'),
19
+ :passed => _('Passed'),
20
+ :othered => _('Other')
21
+ }
22
+ breakdown_chart_data categories, report
23
+ end
24
+
25
+ def arf_report_status_chart_data(status)
26
+ {
27
+ :data => status.to_a,
28
+ :yAxisLabel => _("Number of Events"),
29
+ :xAxisLabel => _("Rule Results"),
30
+ }.to_json
16
31
  end
17
32
  end
@@ -1,25 +1,21 @@
1
1
  module ComplianceHostsHelper
2
- def host_policy_breakdown_chart(report, options = {})
3
- data = []
4
- [[:passed, _('Passed')],
5
- [:failed, _('Failed')],
6
- [:othered, _('Other')],].each do |i|
7
- data << { :label => i[1], :data => report[i[0]], :color => ArfReportDashboardHelper::COLORS[i[0]] }
8
- end
9
- flot_pie_chart 'overview', _('Compliance reports breakdown'), data, options
10
- end
11
-
12
- def host_arf_reports_chart(policy_id)
2
+ def host_arf_reports_chart_data(policy_id)
13
3
  passed = []
14
4
  failed = []
15
5
  othered = []
6
+ date = []
16
7
  @host.arf_reports.of_policy(policy_id).each do |report|
17
- passed << [report.created_at.to_i * 1000, report.passed]
18
- failed << [report.created_at.to_i * 1000, report.failed]
19
- othered << [report.created_at.to_i * 1000, report.othered]
8
+ passed << report.passed
9
+ failed << report.failed
10
+ othered << report.othered
11
+ date << report.created_at.to_i * 1000
20
12
  end
21
- [{ :label => _("Passed"), :data => passed, :color => ArfReportDashboardHelper::COLORS[:passed] },
22
- { :label => _("Failed"), :data => failed, :color => ArfReportDashboardHelper::COLORS[:failed] },
23
- { :label => _("Othered"), :data => othered, :color => ArfReportDashboardHelper::COLORS[:othered] }]
13
+ data = [
14
+ [_("Passed"), passed, ArfReportDashboardHelper::COLORS[:passed]],
15
+ [_("Failed"), failed, ArfReportDashboardHelper::COLORS[:failed]],
16
+ [_("Othered"), othered, ArfReportDashboardHelper::COLORS[:othered]],
17
+ ['dates', date, nil]
18
+ ]
19
+ { :data => data, :xAxisDataLabel => 'dates', :config => 'timeseries' }.to_json
24
20
  end
25
21
  end
@@ -6,15 +6,15 @@ module PolicyDashboardHelper
6
6
  :report_missing => '#92A8CD',
7
7
  }.freeze
8
8
 
9
- def host_breakdown_chart(report, options = {})
10
- data = []
11
- [[:compliant_hosts, _('Compliant hosts')],
12
- [:incompliant_hosts, _('Incompliant hosts')],
13
- [:inconclusive_hosts, _('Inconclusive')],
14
- [:report_missing, _('Not audited')],].each do |i|
15
- data << { :label => i[1], :data => report[i[0]], :color => COLORS[i[0]] }
16
- end
17
- flot_pie_chart 'overview', _('Compliance Status'), data, options
9
+ def policy_breakdown_chart_data(report)
10
+ categories = {
11
+ :compliant_hosts => _('Compliant hosts'),
12
+ :incompliant_hosts => _('Incompliant hosts'),
13
+ :inconclusive_hosts => _('Inconclusive'),
14
+ :report_missing => _('Not audited'),
15
+ }
16
+
17
+ breakdown_chart_data categories, report, COLORS
18
18
  end
19
19
 
20
20
  def status_link(name, label, path)
@@ -1,19 +1,21 @@
1
- <div class="row">
2
- <div class="col-md-4">
1
+ <% stylesheet 'foreman_openscap/scap_breakdown_chart' %>
2
+
3
+ <div class="row metrics-stats-row">
4
+ <div class="col-md-5 scap-breakdown-chart-col">
3
5
  <div class="stats-well">
4
6
  <h4 class="ca" ><%= _('Report Metrics') %></h4>
5
- <div style="margin-top:50px;padding-bottom: 40px;">
6
- <%= reports_breakdown_chart(metrics, :class => 'statistics-pie small') %>
7
- </div>
7
+ <div id="arf-report-breakdown-chart" class="scap-breakdown-chart"></div>
8
+ <%= mount_react_component('DonutChart', "#arf-report-breakdown-chart", donut_breakdown_chart_data(metrics)) %>
8
9
  </div>
9
10
  </div>
10
- <div class="col-md-4">
11
+ <div class="col-md-5 arf-report-rule-chart-col">
11
12
  <div class="stats-well">
12
13
  <h4 class="ca" ><%= _('Report Status') %></h4>
13
- <%= flot_bar_chart("status" ,"", _("Number of Events"), status, :class => "statistics-bar")%>
14
+ <div id="arf-report-rule-chart"></div>
15
+ <%= mount_react_component('BarChart', "#arf-report-rule-chart", arf_report_status_chart_data(status), :flatten_data => true) %>
14
16
  </div>
15
17
  </div>
16
- <div class="col-md-4">
18
+ <div class="col-md-2">
17
19
  <table class='<%= table_css_classes %>'>
18
20
  <tbody>
19
21
  <% metrics.sort.each do |title, value|%>
@@ -1,4 +1,5 @@
1
- <% javascript 'charts', 'dashboard', 'foreman_openscap/scap_hosts_show' %>
1
+ <% javascript 'charts', 'foreman_openscap/scap_hosts_show' %>
2
+ <% stylesheet 'foreman_openscap/scap_breakdown_chart' %>
2
3
 
3
4
  <%= breadcrumbs(:resource_url => api_hosts_path,
4
5
  :resource_filter => "is_compliance_host = true",
@@ -23,14 +24,18 @@
23
24
  hash_for_arf_report_path(:id => data.latest_report.id)
24
25
  .merge(:auth_object => data.latest_report)) %></h4>
25
26
  <% report = data.report %>
26
- <%= host_policy_breakdown_chart(report, :class => 'statistics-pie small') %>
27
+ <% id = "host-policy-breakdown-chart-#{policy.id}" %>
28
+ <div id="<%= id %>" class="scap-breakdown-chart"></div>
29
+ <%= mount_react_component('DonutChart', "##{id}", donut_breakdown_chart_data(report)) %>
27
30
  </div>
28
31
  </div>
29
32
 
30
33
  <div class="col-md-8">
31
34
  <div class="stats-well">
32
35
  <h4 class="ca"><%= _("%s reports over time") % policy %></h4>
33
- <%= flot_chart('resource_graph', '', '', host_arf_reports_chart(policy.id)) %>
36
+ <% reports_graph_id = "arf-reports-over-time-#{policy.id}" %>
37
+ <div id="<%= reports_graph_id %>"></div>
38
+ <%= mount_react_component('LineChart', "##{reports_graph_id}", host_arf_reports_chart_data(policy.id), :flatten_data => true) %>
34
39
  </div>
35
40
  </div>
36
41
  <% else %>
@@ -1,4 +1,7 @@
1
+ <% stylesheet 'foreman_openscap/scap_breakdown_chart'%>
2
+
1
3
  <div id='status-chart'>
2
4
  <h4 class="header ca"><%= _('Host Breakdown Chart') %></h4>
3
- <%= host_breakdown_chart(@report, :class => 'statistics-pie small') %>
5
+ <div id="policy-breakdown-chart" class="scap-breakdown-chart"></div>
6
+ <%= mount_react_component('DonutChart', "#policy-breakdown-chart", policy_breakdown_chart_data(@report)) %>
4
7
  </div>
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "1.0.6".freeze
2
+ VERSION = "1.0.7".freeze
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ArfReportDashboardHelperTest < ActionView::TestCase
4
+ include ArfReportDashboardHelper
5
+
6
+ test 'should return breakdown chart data with custom colors as json' do
7
+ categories = { :passed => 'passed', :failed => 'failed' }
8
+ report = { :passed => 23, :failed => 24 }
9
+ colors = { :passed => '#FFF', :failed => '#000' }
10
+ res = JSON.parse(breakdown_chart_data(categories, report, colors))
11
+ assert_equal ["passed", 23, "#FFF"], res.first
12
+ assert_equal ["failed", 24, "#000"], res.last
13
+ end
14
+
15
+ test 'should return breakdown chart data for donut as json' do
16
+ report = { :passed => 4, :failed => 7, :othered => 5 }
17
+ res = JSON.parse(donut_breakdown_chart_data(report))
18
+ assert_equal 3, res.size
19
+ assert_include res, ["Passed", 4, ArfReportDashboardHelper::COLORS[:passed]]
20
+ assert_include res, ["Failed", 7, ArfReportDashboardHelper::COLORS[:failed]]
21
+ assert_include res, ["Other", 5, ArfReportDashboardHelper::COLORS[:othered]]
22
+ end
23
+
24
+ test 'should return data for report status chart' do
25
+ res = JSON.parse(arf_report_status_chart_data(:passed => 6, :failed => 7, :othered => 8))
26
+ assert_equal "Number of Events", res['yAxisLabel']
27
+ assert_equal "Rule Results", res['xAxisLabel']
28
+ assert_equal 3, res['data'].size
29
+ assert_include res['data'], ["passed", 6]
30
+ assert_include res['data'], ["failed", 7]
31
+ assert_include res['data'], ["othered", 8]
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class PolicyDashboardHelperTest < ActionView::TestCase
4
+ include ArfReportDashboardHelper
5
+ include PolicyDashboardHelper
6
+
7
+ test 'should return data for policy breakdown chart' do
8
+ report = {
9
+ :compliant_hosts => 5,
10
+ :incompliant_hosts => 6,
11
+ :inconclusive_hosts => 7,
12
+ :report_missing => 8
13
+ }
14
+ res = JSON.parse(policy_breakdown_chart_data(report))
15
+ assert_equal 4, res.size
16
+ assert_include res, ['Compliant hosts', 5, PolicyDashboardHelper::COLORS[:compliant_hosts]]
17
+ assert_include res, ['Incompliant hosts', 6, PolicyDashboardHelper::COLORS[:incompliant_hosts]]
18
+ assert_include res, ['Inconclusive', 7, PolicyDashboardHelper::COLORS[:inconclusive_hosts]]
19
+ assert_include res, ['Not audited', 8, PolicyDashboardHelper::COLORS[:report_missing]]
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openscap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - slukasik@redhat.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-05 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -43,6 +43,7 @@ files:
43
43
  - app/assets/stylesheets/foreman_openscap/policy.css
44
44
  - app/assets/stylesheets/foreman_openscap/policy_dashboard.css
45
45
  - app/assets/stylesheets/foreman_openscap/reports.css
46
+ - app/assets/stylesheets/foreman_openscap/scap_breakdown_chart.css
46
47
  - app/controllers/api/v2/compliance/arf_reports_controller.rb
47
48
  - app/controllers/api/v2/compliance/policies_controller.rb
48
49
  - app/controllers/api/v2/compliance/scap_contents_controller.rb
@@ -329,6 +330,8 @@ files:
329
330
  - test/functional/arf_reports_controller_test.rb
330
331
  - test/functional/openscap_proxies_controller_test.rb
331
332
  - test/functional/tailoring_files_controller_test.rb
333
+ - test/helpers/arf_report_dashboard_helper_test.rb
334
+ - test/helpers/policy_dashboard_helper_test.rb
332
335
  - test/lib/foreman_openscap/bulk_upload_test.rb
333
336
  - test/test_plugin_helper.rb
334
337
  - test/unit/arf_report_status_calculator_test.rb
@@ -371,6 +374,8 @@ signing_key:
371
374
  specification_version: 4
372
375
  summary: Foreman plug-in for displaying OpenSCAP audit reports
373
376
  test_files:
377
+ - test/helpers/arf_report_dashboard_helper_test.rb
378
+ - test/helpers/policy_dashboard_helper_test.rb
374
379
  - test/lib/foreman_openscap/bulk_upload_test.rb
375
380
  - test/unit/message_cleaner_test.rb
376
381
  - test/unit/scap_content_test.rb