foreman_statistics 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_statistics/api/v2/statistics_controller.rb +8 -6
  3. data/app/helpers/foreman_statistics/trends_helper.rb +30 -20
  4. data/app/models/concerns/foreman_statistics/has_many_trends.rb +9 -0
  5. data/app/models/foreman_statistics/trend.rb +3 -1
  6. data/app/services/foreman_statistics/statistics/count_hosts.rb +26 -1
  7. data/app/services/foreman_statistics/statistics/count_puppet_classes.rb +1 -1
  8. data/app/services/foreman_statistics/statistics.rb +4 -2
  9. data/app/views/foreman_statistics/trends/_hosts.html.erb +1 -1
  10. data/app/views/foreman_statistics/trends/index.html.erb +0 -1
  11. data/app/views/foreman_statistics/trends/show.html.erb +6 -6
  12. data/config/jest.config.js +21 -0
  13. data/db/migrate/20210523143005_migrate_environments.rb +13 -0
  14. data/lib/foreman_statistics/engine.rb +17 -13
  15. data/lib/foreman_statistics/version.rb +1 -1
  16. data/locale/ca/LC_MESSAGES/foreman_statistics.mo +0 -0
  17. data/locale/ca/foreman_statistics.edit.po +263 -0
  18. data/locale/ca/foreman_statistics.po +202 -0
  19. data/locale/ca/foreman_statistics.po.time_stamp +0 -0
  20. data/locale/cs_CZ/LC_MESSAGES/foreman_statistics.mo +0 -0
  21. data/locale/cs_CZ/foreman_statistics.edit.po +267 -0
  22. data/locale/cs_CZ/foreman_statistics.po +206 -0
  23. data/locale/cs_CZ/foreman_statistics.po.time_stamp +0 -0
  24. data/locale/de/LC_MESSAGES/foreman_statistics.mo +0 -0
  25. data/locale/de/foreman_statistics.edit.po +271 -0
  26. data/locale/de/foreman_statistics.po +210 -0
  27. data/locale/de/foreman_statistics.po.time_stamp +0 -0
  28. data/locale/en/LC_MESSAGES/foreman_statistics.mo +0 -0
  29. data/locale/en/foreman_statistics.edit.po +1 -1
  30. data/locale/en/foreman_statistics.po +1 -1
  31. data/locale/en_GB/LC_MESSAGES/foreman_statistics.mo +0 -0
  32. data/locale/en_GB/foreman_statistics.edit.po +265 -0
  33. data/locale/en_GB/foreman_statistics.po +204 -0
  34. data/locale/en_GB/foreman_statistics.po.time_stamp +0 -0
  35. data/locale/es/LC_MESSAGES/foreman_statistics.mo +0 -0
  36. data/locale/es/foreman_statistics.edit.po +269 -0
  37. data/locale/es/foreman_statistics.po +208 -0
  38. data/locale/es/foreman_statistics.po.time_stamp +0 -0
  39. data/locale/foreman_statistics.pot +2 -2
  40. data/locale/fr/LC_MESSAGES/foreman_statistics.mo +0 -0
  41. data/locale/fr/foreman_statistics.edit.po +269 -0
  42. data/locale/fr/foreman_statistics.po +208 -0
  43. data/locale/fr/foreman_statistics.po.time_stamp +0 -0
  44. data/locale/gl/LC_MESSAGES/foreman_statistics.mo +0 -0
  45. data/locale/gl/foreman_statistics.edit.po +263 -0
  46. data/locale/gl/foreman_statistics.po +202 -0
  47. data/locale/gl/foreman_statistics.po.time_stamp +0 -0
  48. data/locale/it/LC_MESSAGES/foreman_statistics.mo +0 -0
  49. data/locale/it/foreman_statistics.edit.po +265 -0
  50. data/locale/it/foreman_statistics.po +204 -0
  51. data/locale/it/foreman_statistics.po.time_stamp +0 -0
  52. data/locale/ja/LC_MESSAGES/foreman_statistics.mo +0 -0
  53. data/locale/ja/foreman_statistics.edit.po +266 -0
  54. data/locale/ja/foreman_statistics.po +205 -0
  55. data/locale/ja/foreman_statistics.po.time_stamp +0 -0
  56. data/locale/ko/LC_MESSAGES/foreman_statistics.mo +0 -0
  57. data/locale/ko/foreman_statistics.edit.po +264 -0
  58. data/locale/ko/foreman_statistics.po +203 -0
  59. data/locale/ko/foreman_statistics.po.time_stamp +0 -0
  60. data/locale/nl_NL/LC_MESSAGES/foreman_statistics.mo +0 -0
  61. data/locale/nl_NL/foreman_statistics.edit.po +267 -0
  62. data/locale/nl_NL/foreman_statistics.po +206 -0
  63. data/locale/nl_NL/foreman_statistics.po.time_stamp +0 -0
  64. data/locale/pl/LC_MESSAGES/foreman_statistics.mo +0 -0
  65. data/locale/pl/foreman_statistics.edit.po +266 -0
  66. data/locale/pl/foreman_statistics.po +205 -0
  67. data/locale/pl/foreman_statistics.po.time_stamp +0 -0
  68. data/locale/pt_BR/LC_MESSAGES/foreman_statistics.mo +0 -0
  69. data/locale/pt_BR/foreman_statistics.edit.po +269 -0
  70. data/locale/pt_BR/foreman_statistics.po +208 -0
  71. data/locale/pt_BR/foreman_statistics.po.time_stamp +0 -0
  72. data/locale/ru/LC_MESSAGES/foreman_statistics.mo +0 -0
  73. data/locale/ru/foreman_statistics.edit.po +270 -0
  74. data/locale/ru/foreman_statistics.po +209 -0
  75. data/locale/ru/foreman_statistics.po.time_stamp +0 -0
  76. data/locale/sv_SE/LC_MESSAGES/foreman_statistics.mo +0 -0
  77. data/locale/sv_SE/foreman_statistics.edit.po +265 -0
  78. data/locale/sv_SE/foreman_statistics.po +204 -0
  79. data/locale/sv_SE/foreman_statistics.po.time_stamp +0 -0
  80. data/locale/zh_CN/LC_MESSAGES/foreman_statistics.mo +0 -0
  81. data/locale/zh_CN/foreman_statistics.edit.po +267 -0
  82. data/locale/zh_CN/foreman_statistics.po +206 -0
  83. data/locale/zh_CN/foreman_statistics.po.time_stamp +0 -0
  84. data/locale/zh_TW/LC_MESSAGES/foreman_statistics.mo +0 -0
  85. data/locale/zh_TW/foreman_statistics.edit.po +266 -0
  86. data/locale/zh_TW/foreman_statistics.po +205 -0
  87. data/locale/zh_TW/foreman_statistics.po.time_stamp +0 -0
  88. data/package.json +25 -24
  89. data/test/functional/foreman_statistics/api/v2/trends_controller_test.rb +1 -1
  90. data/test/functional/foreman_statistics/trends_controller_test.rb +0 -7
  91. data/test/unit/foreman_statistics/statistics_test.rb +24 -10
  92. data/webpack/src/Components/StatisticsChartsList/__snapshots__/StatisticsChartsList.test.js.snap +6 -0
  93. data/webpack/src/Router/StatisticsPage/__tests__/__snapshots__/StatisticsPage.test.js.snap +10 -0
  94. metadata +77 -92
  95. data/app/models/concerns/foreman_statistics/compute_resource_decorations.rb +0 -9
  96. data/app/models/concerns/foreman_statistics/environment_decorations.rb +0 -9
  97. data/app/models/concerns/foreman_statistics/general_setting_decorations.rb +0 -17
  98. data/app/models/concerns/foreman_statistics/hostgroup_decorations.rb +0 -9
  99. data/app/models/concerns/foreman_statistics/model_decorations.rb +0 -9
  100. data/app/models/concerns/foreman_statistics/operatingsystem_decorations.rb +0 -9
  101. data/app/models/concerns/foreman_statistics/setting_decorations.rb +0 -9
  102. data/webpack/__mocks__/foremanReact/API.js +0 -7
  103. data/webpack/__mocks__/foremanReact/common/HOC.js +0 -24
  104. data/webpack/__mocks__/foremanReact/common/I18n.js +0 -3
  105. data/webpack/__mocks__/foremanReact/common/helpers.js +0 -1
  106. data/webpack/__mocks__/foremanReact/common/urlHelpers.js +0 -1
  107. data/webpack/__mocks__/foremanReact/components/ChartBox/index.js +0 -2
  108. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +0 -2
  109. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +0 -10
  110. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +0 -4
  111. data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +0 -2
  112. data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +0 -2
  113. data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +0 -5
  114. data/webpack/__mocks__/foremanReact/components/common/MessageBox.js +0 -4
  115. data/webpack/__mocks__/foremanReact/components/common/dates/LongDateTime.js +0 -5
  116. data/webpack/__mocks__/foremanReact/components/common/dates/RelativeDateTime.js +0 -3
  117. data/webpack/__mocks__/foremanReact/components/common/table/actionsHelpers/actionTypeCreator.js +0 -7
  118. data/webpack/__mocks__/foremanReact/components/common/table.js +0 -5
  119. data/webpack/__mocks__/foremanReact/constants.js +0 -24
  120. data/webpack/__mocks__/foremanReact/readme.md +0 -11
  121. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +0 -8
  122. data/webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js +0 -10
  123. data/webpack/__mocks__/foremanReact/routes/common/PageLayout/components/ExportButton/ExportButton.js +0 -5
  124. data/webpack/__mocks__/foremanReact/routes/common/reducerHOC/withDataReducer.js +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16e30e607469d7d04baec4a0e68f5dfbf8b5bcbd992e6465978089db5852da01
4
- data.tar.gz: b3454888914a4426634f90493134f6c41f5b1fff1e23d4b4804821e1830ce3d2
3
+ metadata.gz: 755640806f3a97794bb4b955ebb99ed37c522ad48683772b7ab457d45cba3b3b
4
+ data.tar.gz: 7360f71bb358f1c13706bcdacd16e9fb7f36e62dbb6e9314e8cb85de55e034fc
5
5
  SHA512:
6
- metadata.gz: 75cadf6efe100a11c4fff5e0d0902bf24caa7aeff4f7fb3be8dc0eebc095c51d24731dbc617e6cf83c3555813c32c5bb75ce512f1e4e50098e97eb81d58de6a4
7
- data.tar.gz: 1b087e7a64d26f1f5c57ae873edb975ffd947609bae07d1aea8a038a8dbdae4a4476fa5790b24a42372f424852a55861536332baf7d7b9cc8834144337b8f7e2
6
+ metadata.gz: 83f1c16448f74158231ec49156f31c1dcb9f595485b938ae0986e1930e554b7ec7a7832f2e52a8661e80d7834beccb5c282626497ff2ee99266379b9b615f19b
7
+ data.tar.gz: 920cdba7dbdf1df8204485f3b2b5519d98816ac8468efa587aa307618ec49460b5dbdad7c70a6673c738fc48b1743e1d3cefc40097050f9982646090cd390e25
@@ -11,10 +11,12 @@ module ForemanStatistics
11
11
 
12
12
  api :GET, '/statistics/', N_('Get statistics')
13
13
  def index
14
- @os_count = Host.authorized(:view_hosts).count_distribution :operatingsystem
15
- @arch_count = Host.authorized(:view_hosts).count_distribution :architecture
16
- @env_count = Host.authorized(:view_hosts).count_distribution :environment
17
- @klass_count = Host.authorized(:view_hosts).count_habtm 'puppetclass'
14
+ @os_count = Statistics::CountHosts.new(count_by: :operatingsystem)
15
+ @arch_count = Statistics::CountHosts.new(count_by: :architecture)
16
+ if defined?(ForemanPuppet)
17
+ @env_count = Statistics::CountHosts.new(count_by: :environment)
18
+ @klass_count = Statistics::CountPuppetClasses.new(id: :puppetclass)
19
+ end
18
20
  @cpu_count = FactValue.authorized(:view_facts).my_facts.count_each 'processorcount'
19
21
  @model_count = FactValue.authorized(:view_facts).my_facts.count_each 'manufacturer'
20
22
  @mem_size = FactValue.authorized(:view_facts).my_facts.mem_average 'memorysize'
@@ -23,8 +25,8 @@ module ForemanStatistics
23
25
  @swap_free = FactValue.authorized(:view_facts).my_facts.mem_average 'swapfree'
24
26
  @mem_totsize = FactValue.authorized(:view_facts).my_facts.mem_sum 'memorysize'
25
27
  @mem_totfree = FactValue.authorized(:view_facts).my_facts.mem_sum 'memoryfree'
26
- render :json => { :os_count => @os_count, :arch_count => @arch_count, :swap_size => @swap_size,
27
- :env_count => @env_count, :klass_count => @klass_count, :cpu_count => @cpu_count,
28
+ render :json => { :os_count => @os_count.calculate, :arch_count => @arch_count.calculate, :swap_size => @swap_size,
29
+ :env_count => @env_count&.calculate, :klass_count => @klass_count&.calculate, :cpu_count => @cpu_count,
28
30
  :model_count => @model_count, :mem_size => @mem_size, :mem_free => @mem_free,
29
31
  :swap_free => @swap_free, :mem_totsize => @mem_totsize, :mem_totfree => @mem_totfree }
30
32
  end
@@ -3,16 +3,18 @@ module ForemanStatistics
3
3
  include ::CommonParametersHelper
4
4
 
5
5
  def trendable_types
6
- options = { _('Environment') => 'Environment', _('Operating system') => 'Operatingsystem',
7
- _('Model') => 'Model', _('Facts') => 'FactName', _('Host group') => 'Hostgroup', _('Compute resource') => 'ComputeResource' }
8
6
  existing = ForemanTrend.types.pluck(:trendable_type)
7
+ options = {}
8
+ options = { _('Environment') => 'ForemanPuppet::Environment' } if Foreman::Plugin.find(:foreman_puppet)
9
+ options.merge!({ _('Operating system') => 'Operatingsystem', _('Model') => 'Model', _('Facts') => 'FactName',
10
+ _('Host group') => 'Hostgroup', _('Compute resource') => 'ComputeResource' })
9
11
  options.delete_if { |_k, v| existing.include?(v) }
10
12
  end
11
13
 
12
14
  def trend_days_filter(trend)
13
15
  form_tag trend, :id => 'days_filter', :method => :get, :class => 'form form-inline' do
14
16
  content_tag(:span, (_('Trend of the last %s days.') %
15
- select(nil, 'range', 1..Setting[:max_trend], { :selected => range },
17
+ select(nil, 'range', 1..Setting[:max_trend], { :selected => trends_range },
16
18
  { :onchange => "$('#days_filter').submit();$(this).attr('disabled','disabled');;" })).html_safe)
17
19
  end
18
20
  end
@@ -25,28 +27,36 @@ module ForemanStatistics
25
27
  end
26
28
  end
27
29
 
28
- def chart_data(trend, from = Setting[:max_trend], _to = Time.now.utc)
29
- chart_colors = ['#4572A7', '#AA4643', '#89A54E', '#80699B', '#3D96AE', '#DB843D', '#92A8CD', '#A47D7C', '#B5CA92']
30
- values = trend.values
31
- labels = {}
32
- values.includes(:trendable).each { |v| labels[v.id] = [CGI.escapeHTML(v.to_label), trend_path(:id => v)] }
33
- values.includes(:trend_counters).where(['trend_counters.interval_end > ? or trend_counters.interval_end is null', from])
34
- .reorder('trend_counters.interval_start')
35
- .each_with_index.map do |value, idx|
36
- data = []
30
+ ##
31
+ # Returns data in format:
32
+ #
33
+ # [
34
+ # [time, <time_int>, <time_int>],
35
+ # [trend_val1, <host_count>, <host_count>],
36
+ # [trend_val2, 5, 2],
37
+ # [trend_valx, 213, 3]
38
+ # ]
39
+ def trend_chart_data(trend, from = Setting[:max_trend])
40
+ data = {}
41
+ names = {}
42
+ trend.values.preload(:trendable).each { |value| names[value.id] = CGI.escapeHTML(value.to_label) }
43
+ trend.values.preload(:trend_counters).joins(:trend_counters)
44
+ .where(['trend_counters.interval_end > ? or trend_counters.interval_end is null', from])
45
+ .reorder('trend_counters.interval_start')
46
+ .each do |value|
37
47
  value.trend_counters.each do |counter|
38
- # cut the left side of the graph
39
- interval_start = (counter.interval_start || from) > from ? counter.interval_start : from
48
+ current_data = data[counter.interval_start.to_i] ||= {}
40
49
  next_timestamp = counter.try(:interval_end) || Time.now.utc
41
- # transform the timestamp values to flot format - from seconds in Ruby to milliseconds in flot
42
- data << [interval_start.to_i * 1000, counter.count]
43
- data << [next_timestamp.to_i * 1000 - 1, counter.count]
50
+ next_data = data[next_timestamp.to_i] ||= {}
51
+ current_data[value.id] = next_data[value.id] = counter.count
44
52
  end
45
- { :label => labels[value.id][0], :href => labels[value.id][1], :data => data, :color => chart_colors[idx % chart_colors.size] } unless data.empty?
46
- end.compact
53
+ end
54
+ times = data.keys.sort
55
+ result = names.map { |id, label| [label].concat(times.map { |time| data[time][id].to_f }) }
56
+ result.unshift(['time'].concat(times))
47
57
  end
48
58
 
49
- def range
59
+ def trends_range
50
60
  params['range'].empty? ? Setting[:max_trend] : params['range'].to_i
51
61
  end
52
62
  end
@@ -0,0 +1,9 @@
1
+ module ForemanStatistics
2
+ module HasManyTrends
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :trends, as: :trendable, class_name: 'ForemanStatistics::ForemanTrend', dependent: :destroy
7
+ end
8
+ end
9
+ end
@@ -25,7 +25,9 @@ module ForemanStatistics
25
25
  end
26
26
 
27
27
  def self.build_trend(trend_params = {})
28
- trend_params[:trendable_type] == 'FactName' ? FactTrend.new(trend_params) : ForemanTrend.new(trend_params)
28
+ params = trend_params.dup
29
+ params[:trendable_type] = 'ForemanPuppet::Environment' if params[:trendable_type] == 'Environment'
30
+ params[:trendable_type] == 'FactName' ? FactTrend.new(params) : ForemanTrend.new(params)
29
31
  end
30
32
 
31
33
  private
@@ -2,7 +2,32 @@ module ForemanStatistics
2
2
  module Statistics
3
3
  class CountHosts < Base
4
4
  def calculate
5
- Host.authorized(:view_hosts, Host).count_distribution(count_by)
5
+ count_distribution(Host.authorized(:view_hosts, Host), count_by)
6
+ end
7
+
8
+ private
9
+
10
+ def count_distribution(scope, association)
11
+ case association.to_sym
12
+ when :environment
13
+ klass = ForemanPuppet::Environment
14
+ scope = scope.joins(:puppet)
15
+ grouping = ForemanPuppet::HostPuppetFacet.arel_table[:environment_id]
16
+ else
17
+ klass = association.to_s.camelize.constantize
18
+ grouping = Host::Managed.arel_table["#{association}_id"]
19
+ end
20
+
21
+ output = []
22
+ data = scope.reorder('').group(grouping).count
23
+ associations = klass.where(id: data.keys).to_a
24
+ data.each do |k, v|
25
+ output << { label: associations.detect { |a| a.id == k }.to_label, data: v } unless v.zero?
26
+ rescue StandardError => e
27
+ Rails.logger.info "skipped '#{association} - #{k}' as it has has no label"
28
+ Rails.logger.debug e
29
+ end
30
+ output
6
31
  end
7
32
  end
8
33
  end
@@ -9,7 +9,7 @@ module ForemanStatistics
9
9
  end
10
10
 
11
11
  def calculate
12
- Puppetclass.authorized(:view_puppetclasses).map do |pc|
12
+ ForemanPuppet::Puppetclass.authorized(:view_puppetclasses).map do |pc|
13
13
  count = pc.hosts_count
14
14
  next if count.zero?
15
15
  {
@@ -4,17 +4,19 @@ module ForemanStatistics
4
4
  charts = [
5
5
  CountHosts.new(:count_by => :operatingsystem, :title => 'OS Distribution', :search => 'os_title=~VAL~', :organization_id => org_id, :location_id => loc_id),
6
6
  CountHosts.new(:count_by => :architecture, :title => _('Architecture Distribution'), :search => 'facts.architecture=~VAL~', :organization_id => org_id, :location_id => loc_id),
7
- CountHosts.new(:count_by => :environment, :title => _('Environment Distribution'), :search => 'environment=~VAL~', :organization_id => org_id, :location_id => loc_id),
8
7
  CountHosts.new(:count_by => :hostgroup, :title => _('Host Group Distribution'), :search => 'hostgroup_title=~VAL~', :organization_id => org_id, :location_id => loc_id),
9
8
  CountHosts.new(:count_by => :compute_resource, :title => _('Compute Resource Distribution'), :search => 'compute_resource=~VAL~', :organization_id => org_id, :location_id => loc_id),
10
9
  CountFacts.new(:count_by => :processorcount, :unit => Nn_('%s core', '%s cores'), :title => _('Number of CPUs'), :search => 'facts.processorcount=~VAL1~', :organization_id => org_id, :location_id => loc_id),
11
10
  CountFacts.new(:count_by => :manufacturer, :title => _('Hardware'), :search => 'facts.manufacturer~~VAL~', :organization_id => org_id, :location_id => loc_id),
12
11
  CountNumericalFactPair.new(:count_by => :memory, :title => _('Average Memory Usage'), :organization_id => org_id, :location_id => loc_id),
13
12
  CountNumericalFactPair.new(:count_by => :swap, :title => _('Average Swap Usage'), :organization_id => org_id, :location_id => loc_id),
14
- CountPuppetClasses.new(:id => :puppetclass, :title => _('Class Distribution'), :search => 'class=~VAL1~', :organization_id => org_id, :location_id => loc_id),
15
13
  CountHosts.new(:count_by => :location, :title => _('Location Distribution'), :search => 'location=~VAL~', :organization_id => org_id, :location_id => loc_id),
16
14
  CountHosts.new(:count_by => :organization, :title => _('Organization Distribution'), :search => 'organization=~VAL~', :organization_id => org_id, :location_id => loc_id)
17
15
  ]
16
+ if defined?(ForemanPuppet)
17
+ charts << CountHosts.new(:count_by => :environment, :title => _('Environment Distribution'), :search => 'environment=~VAL~', :organization_id => org_id, :location_id => loc_id)
18
+ charts << CountPuppetClasses.new(:id => :puppetclass, :title => _('Class Distribution'), :search => 'class=~VAL1~', :organization_id => org_id, :location_id => loc_id)
19
+ end
18
20
  charts
19
21
  end
20
22
  end
@@ -4,7 +4,7 @@
4
4
  <% group.each do |host| %>
5
5
  <ul class="base">
6
6
  <li>
7
- <%= link_to(host, host_path(:id => host), :title => _("Show Host")) %>
7
+ <%= link_to(host, main_app.host_path(id: host), title: _("Show Host")) %>
8
8
  </li>
9
9
  </ul>
10
10
  <% end %>
@@ -1,4 +1,3 @@
1
- <%= javascript 'charts' %>
2
1
  <% title _("Trends") %>
3
2
  <% title_actions new_link(_("Add Trend Counter"), engine: foreman_statistics),
4
3
  documentation_button('4.1.3Trends') %>
@@ -1,14 +1,14 @@
1
- <%= javascript 'charts' %>
2
1
  <% title(_("Trends for %s") % trend_title(@trend)) %>
3
2
  <% content_for(:search_bar) { trend_days_filter(@trend) } %>
4
3
  <div class="row">
5
- <div class="stats-well col-md-12">
6
- <h4 class="ca"><%= "#{trend_title(@trend)}" %></h4>
7
- <h6 class="ca"><%= n_("last %s day", "last %s days", range) % range %></h6>
8
- <%= flot_chart 'trend_graph','' ,_('Number of Hosts') , chart_data(@trend, range.days.ago), :class=>'statistics-chart stack', :legend => 'external' %>
4
+ <div class="col-md-12">
5
+ <div class="stats-well trends-chart">
6
+ <h4 class="ca"><%= "#{trend_title(@trend)}" %></h4>
7
+ <h6 class="ca"><%= n_("last %s day", "last %s days", trends_range) % trends_range %></h6>
8
+ <%= react_component('AreaChart', yAxisLabel: _('Number of Hosts'), data: trend_chart_data(@trend, trends_range.days.ago), searchUrl: trend_path(id: '~VAL~')) %>
9
+ </div>
9
10
  </div>
10
11
  </div>
11
- <div id="legendContainer"></div>
12
12
  <table class="table">
13
13
  <% unless @trend.fact_value.nil? %>
14
14
  <thead>
@@ -0,0 +1,21 @@
1
+ const tfmConfig = require('@theforeman/test/src/pluginConfig');
2
+
3
+ // Find where foreman is located
4
+ const { foremanRelativePath, foremanLocation } = require('@theforeman/find-foreman');
5
+ const foremanReactRelative = 'webpack/assets/javascripts/react_app';
6
+ const foremanFull = foremanLocation();
7
+ const foremanReactFull = foremanRelativePath(foremanReactRelative);
8
+
9
+ // Find correct path to foremanReact so we do not have to mock it in tests
10
+ tfmConfig.moduleNameMapper['^foremanReact(.*)$'] = `${foremanReactFull}/$1`;
11
+
12
+ // Do not use default resolver
13
+ tfmConfig.resolver = null;
14
+ // Specify module dirs instead
15
+ tfmConfig.moduleDirectories = [
16
+ `${foremanFull}/node_modules`,
17
+ `${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`,
18
+ 'node_modules',
19
+ ]
20
+
21
+ module.exports = tfmConfig;
@@ -0,0 +1,13 @@
1
+ class MigrateEnvironments < ActiveRecord::Migration[6.0]
2
+ class FakeTrend < ApplicationRecord
3
+ self.table_name = 'trends'
4
+ end
5
+
6
+ def up
7
+ FakeTrend.where(trendable_type: 'Environment').update_all(trendable_type: 'ForemanPuppet::Environment')
8
+ end
9
+
10
+ def down
11
+ FakeTrend.where(trendable_type: 'ForemanPuppet::Environment').update_all(trendable_type: 'Environment')
12
+ end
13
+ end
@@ -19,7 +19,7 @@ module ForemanStatistics
19
19
 
20
20
  initializer 'foreman_statistics.register_plugin', :before => :finisher_hook do |_app|
21
21
  Foreman::Plugin.register :foreman_statistics do
22
- requires_foreman '>= 2.1.0'
22
+ requires_foreman '>= 3.1.0'
23
23
 
24
24
  # ==== Core cleanups
25
25
  # TODO: clean up when this gets removed from core
@@ -70,6 +70,17 @@ module ForemanStatistics
70
70
  :engine => ForemanStatistics::Engine, :parent => :monitor_menu, :after => :trends,
71
71
  :url_hash => { :controller => 'foreman_statistics/statistics', :action => :index }
72
72
  }
73
+
74
+ settings do
75
+ category(:general) do
76
+ setting('max_trend',
77
+ type: :integer,
78
+ default: 30,
79
+ description: N_('Max days for Trends graphs'),
80
+ full_name: N_('Max trends'),
81
+ validate: { numericality: { greater_than: 0 } })
82
+ end
83
+ end
73
84
  end
74
85
  end
75
86
 
@@ -87,18 +98,11 @@ module ForemanStatistics
87
98
 
88
99
  # Include concerns in this config.to_prepare block
89
100
  config.to_prepare do
90
- ::ComputeResource.include ForemanStatistics::ComputeResourceDecorations
91
- ::Environment.include ForemanStatistics::EnvironmentDecorations
92
- ::Hostgroup.include ForemanStatistics::HostgroupDecorations
93
- ::Model.include ForemanStatistics::ModelDecorations
94
- ::Operatingsystem.include ForemanStatistics::OperatingsystemDecorations
95
- ::Setting.include ForemanStatistics::SettingDecorations
96
- ::Setting::General.prepend ForemanStatistics::GeneralSettingDecorations
97
- begin
98
- ::Setting::General.load_defaults
99
- rescue ActiveRecord::NoDatabaseError => e
100
- Rails.logger.warn e
101
- end
101
+ ::ComputeResource.include ForemanStatistics::HasManyTrends
102
+ ::Hostgroup.include ForemanStatistics::HasManyTrends
103
+ ::Model.include ForemanStatistics::HasManyTrends
104
+ ::Operatingsystem.include ForemanStatistics::HasManyTrends
105
+ 'ForemanPuppet::Environment'.safe_constantize&.include ForemanStatistics::HasManyTrends
102
106
  end
103
107
 
104
108
  rake_tasks do
@@ -1,3 +1,3 @@
1
1
  module ForemanStatistics
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
@@ -0,0 +1,263 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the foreman_statistics package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ # Translators:
7
+ # Robert Antoni Buj Gelonch <rbuj@fedoraproject.org>, 2021
8
+ #
9
+ msgid ""
10
+ msgstr ""
11
+ "Project-Id-Version: foreman_statistics 1.1.1\n"
12
+ "Report-Msgid-Bugs-To: \n"
13
+ "POT-Creation-Date: 2021-02-04 02:22+0100\n"
14
+ "PO-Revision-Date: 2021-02-03 22:59+0000\n"
15
+ "Last-Translator: Robert Antoni Buj Gelonch <rbuj@fedoraproject.org>, 2021\n"
16
+ "Language-Team: Catalan (https://www.transifex.com/foreman/teams/114/ca/)\n"
17
+ "MIME-Version: 1.0\n"
18
+ "Content-Type: text/plain; charset=UTF-8\n"
19
+ "Content-Transfer-Encoding: 8bit\n"
20
+ "Language: ca\n"
21
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
22
+
23
+ #: ../app/controllers/foreman_statistics/api/v2/statistics_controller.rb:12
24
+ msgid "Get statistics"
25
+ msgstr "Obtén les estadístiques"
26
+
27
+ #: ../app/controllers/foreman_statistics/api/v2/trends_controller.rb:20
28
+ msgid "List of trends counters"
29
+ msgstr ""
30
+
31
+ #: ../app/controllers/foreman_statistics/api/v2/trends_controller.rb:25
32
+ msgid "Show a trend"
33
+ msgstr ""
34
+
35
+ #: ../app/controllers/foreman_statistics/api/v2/trends_controller.rb:29
36
+ msgid "Create a trend counter"
37
+ msgstr ""
38
+
39
+ #: ../app/controllers/foreman_statistics/api/v2/trends_controller.rb:42
40
+ msgid "Delete a trend counter"
41
+ msgstr ""
42
+
43
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:6
44
+ msgid "Environment"
45
+ msgstr "Entorn"
46
+
47
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:6
48
+ msgid "Operating system"
49
+ msgstr "Sistema operatiu"
50
+
51
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:7
52
+ msgid "Model"
53
+ msgstr "Model"
54
+
55
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:7
56
+ msgid "Facts"
57
+ msgstr "Objectes d'interès"
58
+
59
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:7
60
+ msgid "Host group"
61
+ msgstr "Grup d'amfitrions"
62
+
63
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:7
64
+ msgid "Compute resource"
65
+ msgstr "Recurs computacional"
66
+
67
+ #: ../app/helpers/foreman_statistics/trends_helper.rb:14
68
+ msgid "Trend of the last %s days."
69
+ msgstr ""
70
+
71
+ #: ../app/jobs/foreman_statistics/trend_counter_job.rb:20
72
+ msgid "Trend Counter Job"
73
+ msgstr ""
74
+
75
+ #: ../app/models/concerns/foreman_statistics/general_setting_decorations.rb:12
76
+ msgid "Max days for Trends graphs"
77
+ msgstr "Nombre màxim de dies per als gràfics de les tendències"
78
+
79
+ #: ../app/models/concerns/foreman_statistics/general_setting_decorations.rb:12
80
+ msgid "Max trends"
81
+ msgstr "Tendències màx."
82
+
83
+ #: ../app/services/foreman_statistics/statistics.rb:6
84
+ msgid "Architecture Distribution"
85
+ msgstr "Distribució de l'arquitectura"
86
+
87
+ #: ../app/services/foreman_statistics/statistics.rb:7
88
+ msgid "Environment Distribution"
89
+ msgstr ""
90
+
91
+ #: ../app/services/foreman_statistics/statistics.rb:8
92
+ msgid "Host Group Distribution"
93
+ msgstr ""
94
+
95
+ #: ../app/services/foreman_statistics/statistics.rb:9
96
+ msgid "Compute Resource Distribution"
97
+ msgstr ""
98
+
99
+ #: ../app/services/foreman_statistics/statistics.rb:10
100
+ msgid "Number of CPUs"
101
+ msgstr "Nombre de CPU"
102
+
103
+ #: ../app/services/foreman_statistics/statistics.rb:11
104
+ msgid "Hardware"
105
+ msgstr "Maquinari"
106
+
107
+ #: ../app/services/foreman_statistics/statistics.rb:12
108
+ msgid "Average Memory Usage"
109
+ msgstr ""
110
+
111
+ #: ../app/services/foreman_statistics/statistics.rb:13
112
+ msgid "Average Swap Usage"
113
+ msgstr ""
114
+
115
+ #: ../app/services/foreman_statistics/statistics.rb:14
116
+ msgid "Class Distribution"
117
+ msgstr "Distribució de la classe"
118
+
119
+ #: ../app/services/foreman_statistics/statistics.rb:15
120
+ msgid "Location Distribution"
121
+ msgstr ""
122
+
123
+ #: ../app/services/foreman_statistics/statistics.rb:16
124
+ msgid "Organization Distribution"
125
+ msgstr ""
126
+
127
+ #: ../app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb:22
128
+ msgid "free memory"
129
+ msgstr "memòria lliure"
130
+
131
+ #: ../app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb:26
132
+ msgid "used memory"
133
+ msgstr "memòria utilitzada"
134
+
135
+ #: ../app/views/foreman_statistics/trends/_empty_data.html.erb:1 ../app/views/foreman_statistics/trends/show.html.erb:2
136
+ msgid "Trends for %s"
137
+ msgstr "Tendències per %s"
138
+
139
+ #: ../app/views/foreman_statistics/trends/_empty_data.html.erb:4
140
+ msgid "No data for this trend."
141
+ msgstr "No hi ha dades per aquesta tendència."
142
+
143
+ #: ../app/views/foreman_statistics/trends/_form.html.erb:4
144
+ msgid "Please Select"
145
+ msgstr "Si us plau, seleccioneu"
146
+
147
+ #: ../app/views/foreman_statistics/trends/_hosts.html.erb:7
148
+ msgid "Show Host"
149
+ msgstr "Mosta l'amfitrió"
150
+
151
+ #: ../app/views/foreman_statistics/trends/edit.html.erb:1
152
+ msgid "Edit Trend %s"
153
+ msgstr "Edita la tendència %s"
154
+
155
+ #: ../app/views/foreman_statistics/trends/edit.html.erb:8
156
+ msgid "Fact Name"
157
+ msgstr "Nom de l'objecte d'interès"
158
+
159
+ #: ../app/views/foreman_statistics/trends/edit.html.erb:9 ../app/views/foreman_statistics/trends/edit.html.erb:30
160
+ msgid "Display Name"
161
+ msgstr ""
162
+
163
+ #: ../app/views/foreman_statistics/trends/edit.html.erb:43
164
+ msgid "Cancel"
165
+ msgstr "Cancel·la"
166
+
167
+ #: ../app/views/foreman_statistics/trends/edit.html.erb:44
168
+ msgid "Submit"
169
+ msgstr "Envia"
170
+
171
+ #: ../app/views/foreman_statistics/trends/index.html.erb:2 ../app/views/foreman_statistics/trends/welcome.html.erb:1 ../app/views/foreman_statistics/trends/welcome.html.erb:6 ../lib/foreman_statistics/engine.rb:63
172
+ msgid "Trends"
173
+ msgstr "Tendències"
174
+
175
+ #: ../app/views/foreman_statistics/trends/index.html.erb:3 ../app/views/foreman_statistics/trends/welcome.html.erb:10
176
+ msgid "Add Trend Counter"
177
+ msgstr ""
178
+
179
+ #: ../app/views/foreman_statistics/trends/index.html.erb:9
180
+ msgid "Name"
181
+ msgstr "Nom"
182
+
183
+ #: ../app/views/foreman_statistics/trends/index.html.erb:10
184
+ msgid "Action"
185
+ msgstr "Acció"
186
+
187
+ #: ../app/views/foreman_statistics/trends/index.html.erb:16
188
+ msgid "Show Trends"
189
+ msgstr "Mostra les tendències"
190
+
191
+ #: ../app/views/foreman_statistics/trends/index.html.erb:19
192
+ msgid "Edit"
193
+ msgstr "Edita"
194
+
195
+ #: ../app/views/foreman_statistics/trends/index.html.erb:20
196
+ msgid "Delete all the trend history for %s?"
197
+ msgstr ""
198
+
199
+ #: ../app/views/foreman_statistics/trends/index.html.erb:28
200
+ msgid "Last update:"
201
+ msgstr ""
202
+
203
+ #: ../app/views/foreman_statistics/trends/new.html.erb:1
204
+ msgid "Create Trend"
205
+ msgstr "Crea una tendència"
206
+
207
+ #: ../app/views/foreman_statistics/trends/show.html.erb:7
208
+ msgid "last %s day"
209
+ msgid_plural "last %s days"
210
+ msgstr[0] ""
211
+ msgstr[1] ""
212
+
213
+ #: ../app/views/foreman_statistics/trends/show.html.erb:8
214
+ msgid "Number of Hosts"
215
+ msgstr "Nombre d'amfitrions"
216
+
217
+ #: ../app/views/foreman_statistics/trends/show.html.erb:16
218
+ msgid "Hosts"
219
+ msgstr "Amfitrions"
220
+
221
+ #: ../app/views/foreman_statistics/trends/welcome.html.erb:7
222
+ msgid "Trends in Foreman allow you to track changes in your infrastructure over time. It allows you to track both Foreman related information and to any fact. The Trend pages give a graph of how the number of hosts with that value have changed over time, and list the current hosts."
223
+ msgstr ""
224
+
225
+ #: ../app/views/foreman_statistics/trends/welcome.html.erb:8
226
+ msgid "Learn more about this in the documentation."
227
+ msgstr "Obteniu més informació sobre això a la documentació."
228
+
229
+ #: ../lib/foreman_statistics/engine.rb:69 ../webpack/src/Router/StatisticsPage/StatisticsPage.js:8
230
+ msgid "Statistics"
231
+ msgstr "Estadístiques"
232
+
233
+ #: ../webpack/src/Components/StatisticsChartsList/index.js:14
234
+ msgid "No data available"
235
+ msgstr "Sense dades disponibles"
236
+
237
+ #: ../webpack/src/Components/StatisticsChartsList/index.js:15
238
+ msgid "Expand the chart"
239
+ msgstr "Expandeix la gràfica"
240
+
241
+ #: ../webpack/src/Router/StatisticsPage/Statistics/Statistics.js:13
242
+ msgid "No Charts To Load"
243
+ msgstr ""
244
+
245
+ #: action_names.rb:2
246
+ msgid "Action with sub plans"
247
+ msgstr ""
248
+
249
+ #: action_names.rb:3
250
+ msgid "Import facts"
251
+ msgstr ""
252
+
253
+ #: action_names.rb:4
254
+ msgid "Import Puppet classes"
255
+ msgstr ""
256
+
257
+ #: action_names.rb:5
258
+ msgid "Remote action:"
259
+ msgstr ""
260
+
261
+ #: gemspec.rb:2
262
+ msgid "Statistics and Trends for Foreman gives users overview of their infrastructure."
263
+ msgstr ""