foreman_monitoring 0.1.3 → 1.0.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -1
  3. data/Rakefile +0 -0
  4. data/app/controllers/api/v2/monitoring_results_controller.rb +1 -1
  5. data/app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb +15 -16
  6. data/app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb +9 -14
  7. data/app/lib/proxy_api/monitoring.rb +6 -6
  8. data/app/models/concerns/foreman_monitoring/host_extensions.rb +11 -13
  9. data/app/models/concerns/foreman_monitoring/hostgroup_extensions.rb +3 -3
  10. data/app/models/concerns/orchestration/monitoring.rb +11 -13
  11. data/app/models/host_status/monitoring_status.rb +2 -4
  12. data/app/models/monitoring_result.rb +3 -7
  13. data/app/models/setting/monitoring.rb +2 -2
  14. data/app/views/hosts/_downtime_fields.html.erb +2 -2
  15. data/db/migrate/20160817135723_create_monitoring_results.rb +3 -1
  16. data/db/migrate/20161220201510_add_monitoring_proxy_id_to_host_and_hostgroup.rb +1 -1
  17. data/lib/foreman_monitoring/engine.rb +15 -15
  18. data/lib/foreman_monitoring/version.rb +1 -1
  19. data/lib/tasks/foreman_monitoring_tasks.rake +2 -4
  20. data/test/factories/feature.rb +1 -1
  21. data/test/factories/host.rb +3 -3
  22. data/test/factories/monitoring_results.rb +1 -1
  23. data/test/factories/smart_proxy.rb +1 -1
  24. data/test/functional/hosts_controller_test.rb +53 -42
  25. data/test/lib/proxy_api/monitoring_test.rb +13 -13
  26. data/test/test_plugin_helper.rb +3 -3
  27. data/test/unit/host_status/monitoring_status_test.rb +12 -12
  28. data/test/unit/host_test.rb +4 -4
  29. data/test/unit/monitoring_test.rb +3 -3
  30. metadata +18 -20
  31. data/test/unit/monitoring_result_test.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4006edcbe7c896898b2b9a2d68c23e0649925364efbc0f18d5bc09311d183cc7
4
- data.tar.gz: 033ebafd117fdbab220bc2d64f9afdd844997c8f7af106f5df8f0bf53d48811b
3
+ metadata.gz: 83bf8624bc1c1ecbb9e8dc6c11340022a204244afe293789405cdaf9e80b10be
4
+ data.tar.gz: 0d3d42280a04d22a33792c03ed62aee41a9800cf6a307abb16a06589d03ea0af
5
5
  SHA512:
6
- metadata.gz: b1eb8d83ffb58a6e7e7ee2cd6fcf048662029256dcb15738c5b9cfec6f675e67a00f10f8fcbf9601a80efdef6d9db3b8e4926cfadcec49f2b00972d10de6e762
7
- data.tar.gz: bf7116a3092e7226a1513b6a83dde8f1cd51bfc05aac48c9c87cfd5890d6fb5b066ca96bc603d78b37edb061a3eb6e853361658408eda5b4a87fde2b7f0f2985
6
+ metadata.gz: 3ec31b7e2cf93786431ccbedbbb7ec36e4fdcce70bb4d2beb0c2faf741b9e3287ceec3878c5f168c09bcb2fe190694f1f5f77d435e3f686456d47dd0f90b57aa
7
+ data.tar.gz: 317ad1fdc9bf7a61008007b6b8edce1eec053aecf55cd0abcda95e97dfc670021c01100f5fbe2f30eebbc543ededbbe3e0f3a4811e44609716be9b570635ed77
data/README.md CHANGED
@@ -17,7 +17,7 @@ The gem name is `foreman_monitoring`.
17
17
 
18
18
  RPM users can install the `tfm-rubygem-foreman_monitoring` package.
19
19
 
20
- Deb users can install the `ruby-foreman_monitoring` package.
20
+ Deb users can install the `ruby-foreman-monitoring` package.
21
21
 
22
22
  If using the gem as installation source database enhancement and service restart must
23
23
  be done manually.
@@ -28,6 +28,13 @@ foreman-rake db:seed
28
28
  touch ~foreman/tmp/restart.txt
29
29
  ```
30
30
 
31
+ ## Compatibility
32
+
33
+ | Foreman Version | Plugin Version |
34
+ | --------------- | --------------:|
35
+ | >= 1.15 | ~> 0.1 |
36
+ | >= 1.17 | ~> 1.0 |
37
+
31
38
  # Usage
32
39
 
33
40
  For managing a host in the monitoring solution a Smart Proxy providing
data/Rakefile CHANGED
File without changes
@@ -18,7 +18,7 @@ module Api
18
18
  def create
19
19
  begin
20
20
  MonitoringResult.import(monitoring_result_params.with_indifferent_access)
21
- rescue => e
21
+ rescue StandardError => e
22
22
  logger.error "Failed to import monitoring result: #{e.message}"
23
23
  logger.debug e.backtrace.join("\n")
24
24
  render :json => { 'message' => e.message }, :status => :unprocessable_entity
@@ -1,18 +1,17 @@
1
1
  module ForemanMonitoring
2
2
  module HostsControllerExtensions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- before_action :find_resource_with_monitoring, :only => [:downtime]
7
- before_action :find_multiple_with_monitoring, :only => %i[select_multiple_downtime update_multiple_downtime
8
- select_multiple_monitoring_proxy update_multiple_monitoring_proxy]
9
- before_action :validate_host_downtime_params, :only => [:downtime]
10
- before_action :validate_hosts_downtime_params, :only => [:update_multiple_downtime]
11
- before_action :validate_multiple_monitoring_proxy, :only => :update_multiple_monitoring_proxy
12
-
13
- alias_method :find_resource_with_monitoring, :find_resource
14
- alias_method :find_multiple_with_monitoring, :find_multiple
15
- alias_method_chain :update_multiple_power_state, :monitoring
3
+ def self.prepended(base)
4
+ base.class_eval do
5
+ before_action :find_resource_with_monitoring, :only => [:downtime]
6
+ before_action :find_multiple_with_monitoring, :only => %i[select_multiple_downtime update_multiple_downtime
7
+ select_multiple_monitoring_proxy update_multiple_monitoring_proxy]
8
+ before_action :validate_host_downtime_params, :only => [:downtime]
9
+ before_action :validate_hosts_downtime_params, :only => [:update_multiple_downtime]
10
+ before_action :validate_multiple_monitoring_proxy, :only => :update_multiple_monitoring_proxy
11
+
12
+ alias_method :find_resource_with_monitoring, :find_resource
13
+ alias_method :find_multiple_with_monitoring, :find_multiple
14
+ end
16
15
  end
17
16
 
18
17
  def downtime
@@ -39,7 +38,7 @@ module ForemanMonitoring
39
38
  failed_hosts[host.name] = error_message
40
39
  logger.error "Failed to set a host downtime for #{host}: #{error_message}"
41
40
  end
42
- rescue => error
41
+ rescue StandardError => error
43
42
  failed_hosts[host.name] = error
44
43
  Foreman::Logging.exception(_('Failed to set a host downtime for %s.') % host, error)
45
44
  end
@@ -65,7 +64,7 @@ module ForemanMonitoring
65
64
  update_multiple_proxy(_('Monitoring'), :monitoring_proxy=)
66
65
  end
67
66
 
68
- def update_multiple_power_state_with_monitoring
67
+ def update_multiple_power_state
69
68
  options = {
70
69
  :comment => 'Power state changed in Foreman',
71
70
  :author => "Foreman User #{User.current}",
@@ -86,7 +85,7 @@ module ForemanMonitoring
86
85
  end
87
86
  end
88
87
  end
89
- update_multiple_power_state_without_monitoring
88
+ super
90
89
  end
91
90
 
92
91
  private
@@ -1,18 +1,13 @@
1
1
  module ForemanMonitoring
2
2
  module HostsHelperExt
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- alias_method_chain :host_title_actions, :monitoring
7
- alias_method_chain :multiple_actions, :monitoring
8
- end
9
-
10
- def multiple_actions_with_monitoring
11
- return multiple_actions_without_monitoring unless authorized_for(:controller => :hosts, :action => :select_multiple_downtime)
12
- multiple_actions_without_monitoring + [[_('Set downtime'), select_multiple_downtime_hosts_path], [_('Change Monitoring Proxy'), select_multiple_monitoring_proxy_hosts_path]]
3
+ def multiple_actions
4
+ actions = super
5
+ actions << [_('Set downtime'), select_multiple_downtime_hosts_path] if authorized_for(:controller => :hosts, :action => :select_multiple_downtime)
6
+ actions << [_('Change Monitoring Proxy'), select_multiple_monitoring_proxy_hosts_path] if authorized_for(:controller => :hosts, :action => :select_multiple_monitoring_proxy)
7
+ actions
13
8
  end
14
9
 
15
- def host_title_actions_with_monitoring(host)
10
+ def host_title_actions(host)
16
11
  title_actions(
17
12
  button_group(
18
13
  display_link_if_authorized(_('Downtime'),
@@ -27,7 +22,7 @@ module ForemanMonitoring
27
22
  :target => '#set_host_downtime' })
28
23
  )
29
24
  )
30
- host_title_actions_without_monitoring(host)
25
+ super
31
26
  end
32
27
 
33
28
  def host_monitoring_result_icon_class(result)
@@ -58,10 +53,10 @@ module ForemanMonitoring
58
53
  end
59
54
  end
60
55
 
61
- def monitoring_datetime_f(f, attr, options = {})
56
+ def datetime_f(f, attr, options = {})
62
57
  field(f, attr, options) do
63
58
  addClass options, 'form-control'
64
- f.datetime_field attr, options
59
+ f.datetime_local_field attr, options
65
60
  end
66
61
  end
67
62
  end
@@ -7,25 +7,25 @@ module ProxyAPI
7
7
 
8
8
  def create_host_downtime(host, args = {})
9
9
  parse(post(args, "downtime/host/#{host}"))
10
- rescue => e
10
+ rescue StandardError => e
11
11
  raise ProxyException.new(url, e, N_('Unable to set downtime for %s') % host)
12
12
  end
13
13
 
14
14
  def remove_host_downtime(host, args = {})
15
15
  parse(delete("downtime/host/#{host}?#{args.to_query}"))
16
- rescue => e
16
+ rescue StandardError => e
17
17
  raise ProxyException.new(url, e, N_('Unable to remove downtime for %s') % host)
18
18
  end
19
19
 
20
20
  def create_host(host, attributes = {})
21
21
  parse(put({ :attributes => attributes }, "host/#{host}"))
22
- rescue => e
22
+ rescue StandardError => e
23
23
  raise ProxyException.new(url, e, N_('Unable to create monitoring host object for %s') % host)
24
24
  end
25
25
 
26
26
  def update_host(host, attributes = {})
27
27
  parse(post({ :attributes => attributes }, "host/#{host}"))
28
- rescue => e
28
+ rescue StandardError => e
29
29
  raise ProxyException.new(url, e, N_('Unable to update monitoring host object for %s') % host)
30
30
  end
31
31
 
@@ -34,7 +34,7 @@ module ProxyAPI
34
34
  parse(delete("host/#{host}"))
35
35
  rescue RestClient::ResourceNotFound
36
36
  true
37
- rescue => e
37
+ rescue StandardError => e
38
38
  raise ProxyException.new(url, e, N_('Unable to delete monitoring host object for %s') % host)
39
39
  end
40
40
 
@@ -42,7 +42,7 @@ module ProxyAPI
42
42
  parse(get("host/#{host}"))
43
43
  rescue RestClient::ResourceNotFound
44
44
  nil
45
- rescue => e
45
+ rescue StandardError => e
46
46
  raise ProxyException.new(url, e, N_('Unable to query monitoring host object for %{host}: %{message}') % { :host => host, :message => e.try(:response) || e.try(:message) })
47
47
  end
48
48
  end
@@ -1,15 +1,13 @@
1
1
  module ForemanMonitoring
2
2
  module HostExtensions
3
- extend ActiveSupport::Concern
4
- included do
5
- include Orchestration::Monitoring
3
+ def self.prepended(base)
4
+ base.class_eval do
5
+ include Orchestration::Monitoring
6
6
 
7
- after_build :downtime_host_build
7
+ after_build :downtime_host_build
8
8
 
9
- alias_method_chain :smart_proxy_ids, :monitoring_proxy
10
- alias_method_chain :hostgroup_inherited_attributes, :monitoring
11
-
12
- has_many :monitoring_results, :dependent => :destroy, :foreign_key => 'host_id'
9
+ has_many :monitoring_results, :dependent => :destroy, :foreign_key => 'host_id', :inverse_of => :host
10
+ end
13
11
  end
14
12
 
15
13
  def monitoring_status(options = {})
@@ -42,12 +40,12 @@ module ForemanMonitoring
42
40
  monitoring_proxy.present?
43
41
  end
44
42
 
45
- def hostgroup_inherited_attributes_with_monitoring
46
- hostgroup_inherited_attributes_without_monitoring + ['monitoring_proxy_id']
43
+ def hostgroup_inherited_attributes
44
+ super + ['monitoring_proxy_id']
47
45
  end
48
46
 
49
- def smart_proxy_ids_with_monitoring_proxy
50
- ids = smart_proxy_ids_without_monitoring_proxy
47
+ def smart_proxy_ids
48
+ ids = super
51
49
  [monitoring_proxy, hostgroup.try(:monitoring_proxy)].compact.each do |proxy|
52
50
  ids << proxy.id
53
51
  end
@@ -66,7 +64,7 @@ module ForemanMonitoring
66
64
  :compute_resource => compute_resource.try(:to_label),
67
65
  :hostgroup => hostgroup.try(:to_label),
68
66
  :organization => organization.try(:name),
69
- :location => location.try(:name),
67
+ :location => organization.try(:name),
70
68
  :comment => comment,
71
69
  :environment => environment.try(:to_s),
72
70
  :owner_name => owner.try(:name)
@@ -3,12 +3,12 @@ module ForemanMonitoring
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def monitoring_proxy
6
- return super unless ancestry.present?
7
- SmartProxy.find_by_id(inherited_monitoring_proxy_id)
6
+ return super if ancestry.blank?
7
+ SmartProxy.find_by(id: inherited_monitoring_proxy_id)
8
8
  end
9
9
 
10
10
  def inherited_monitoring_proxy_id
11
- return monitoring_proxy_id unless ancestry.present?
11
+ return monitoring_proxy_id if ancestry.blank?
12
12
  self[:monitoring_proxy_id] || self.class.sort_by_ancestry(ancestors.where('monitoring_proxy_id is not NULL')).last.try(:monitoring_proxy_id)
13
13
  end
14
14
  end
@@ -23,10 +23,9 @@ module Orchestration::Monitoring
23
23
  def queue_monitoring_update
24
24
  return unless monitoring_update_required?(monitoring_object[:attrs], monitoring_attributes)
25
25
  Rails.logger.debug('Detected a change to the monitoring object is required.')
26
- if ::Monitoring.create_action?(:create)
27
- queue.create(:name => _('Monitoring update for %s') % old, :priority => 2,
28
- :action => [self, :setMonitoringUpdate])
29
- end
26
+ return unless ::Monitoring.create_action?(:create)
27
+ queue.create(:name => _('Monitoring update for %s') % old, :priority => 2,
28
+ :action => [self, :setMonitoringUpdate])
30
29
  end
31
30
 
32
31
  def queue_monitoring_destroy
@@ -35,30 +34,29 @@ module Orchestration::Monitoring
35
34
  queue.create(:name => _('Removing monitoring object for %s') % self, :priority => 2,
36
35
  :action => [self, :delMonitoring])
37
36
  end
38
- if ::Monitoring.delete_action?(:downtime)
39
- queue.create(:name => _('Set monitoring downtime for %s') % self, :priority => 2,
40
- :action => [self, :setMonitoringDowntime])
41
- end
37
+ return unless ::Monitoring.delete_action?(:downtime)
38
+ queue.create(:name => _('Set monitoring downtime for %s') % self, :priority => 2,
39
+ :action => [self, :setMonitoringDowntime])
42
40
  end
43
41
 
44
42
  def setMonitoring
45
43
  Rails.logger.info "Adding Monitoring object for #{name}"
46
44
  monitoring.create_host(self)
47
- rescue => e
45
+ rescue StandardError => e
48
46
  failure format(_("Failed to create a monitoring object %{name}: %{message}\n "), :name => name, :message => e.message), e
49
47
  end
50
48
 
51
49
  def delMonitoring
52
50
  Rails.logger.info "Deleting Monitoring object for #{name}"
53
51
  monitoring.delete_host(self)
54
- rescue => e
52
+ rescue StandardError => e
55
53
  failure format(_("Failed to delete a monitoring object %{name}: %{message}\n "), :name => name, :message => e.message), e
56
54
  end
57
55
 
58
56
  def setMonitoringUpdate
59
57
  Rails.logger.info "Updating Monitoring object for #{name}"
60
58
  monitoring.update_host(self)
61
- rescue => e
59
+ rescue StandardError => e
62
60
  failure format(_("Failed to update a monitoring object %{name}: %{message}\n "), :name => name, :message => e.message), e
63
61
  end
64
62
 
@@ -67,14 +65,14 @@ module Orchestration::Monitoring
67
65
  def setMonitoringDowntime
68
66
  Rails.logger.info "Setting Monitoring downtime for #{name}"
69
67
  monitoring.set_downtime_host(self, monitoring_downtime_defaults)
70
- rescue => e
68
+ rescue StandardError => e
71
69
  failure format(_("Failed to set a monitoring downtime for %{name}: %{message}\n "), :name => name, :message => e.message), e
72
70
  end
73
71
 
74
72
  def delMonitoringDowntime
75
73
  Rails.logger.info "Deleting Monitoring downtime for #{name}"
76
74
  monitoring.del_downtime_host(self, monitoring_downtime_defaults)
77
- rescue => e
75
+ rescue StandardError => e
78
76
  failure format(_("Failed to set a monitoring downtime for %{name}: %{message}\n "), :name => name, :message => e.message), e
79
77
  end
80
78
 
@@ -11,7 +11,7 @@ module HostStatus
11
11
 
12
12
  def to_status(_options = {})
13
13
  state = OK
14
- grouped_results.each do |resultset, _count|
14
+ grouped_results.each_key do |resultset|
15
15
  result, downtime, acknowledged = resultset
16
16
  next if downtime
17
17
  result = map_result_to_status(result)
@@ -60,9 +60,7 @@ module HostStatus
60
60
  host.monitoring_results.any?
61
61
  end
62
62
 
63
- def host_monitored?
64
- host.monitored?
65
- end
63
+ delegate :monitored?, to: :host, prefix: true
66
64
 
67
65
  def should_affect_global_status?
68
66
  Setting[:monitoring_affect_global_status]
@@ -1,11 +1,10 @@
1
- class MonitoringResult < ActiveRecord::Base
1
+ class MonitoringResult < ApplicationRecord
2
2
  enum :result => %i[ok warning critical unknown]
3
3
 
4
4
  belongs_to_host
5
5
 
6
- # rubocop:disable Metrics/AbcSize
7
6
  def self.import(result)
8
- host = Host.find_by_name(result[:host])
7
+ host = Host.find_by(name: result[:host])
9
8
 
10
9
  if host.nil?
11
10
  logger.error "Unable to find host #{result[:host]}"
@@ -28,8 +27,7 @@ class MonitoringResult < ActiveRecord::Base
28
27
  end
29
28
 
30
29
  created = MonitoringResult.where(:host => host, :service => result[:service]).first_or_create
31
- # rubocop:disable Rails/Date
32
- if created.timestamp.blank? || updates[:timestamp].blank? || (created.timestamp.to_time - updates[:timestamp].to_time) < 2
30
+ if created.timestamp.blank? || updates[:timestamp].blank? || created.timestamp < updates[:timestamp]
33
31
  created.update_attributes(updates)
34
32
 
35
33
  if created.persisted?
@@ -39,9 +37,7 @@ class MonitoringResult < ActiveRecord::Base
39
37
  else
40
38
  logger.debug "Skipping monitoring result import for #{host} as it is older than what we have."
41
39
  end
42
- # rubocop:enable Rails/Date
43
40
  end
44
- # rubocop:enable Metrics/AbcSize
45
41
 
46
42
  def status
47
43
  return :ok if downtime
@@ -7,10 +7,10 @@ class Setting
7
7
  true, N_('Monitoring status should affect global status')),
8
8
  set('monitoring_create_action',
9
9
  _('What action should be taken when a host is created'),
10
- 'create', N_('Host Create Action'), nil, { :collection => proc { ::Monitoring::CREATE_ACTIONS } }),
10
+ 'create', N_('Host Create Action'), nil, :collection => proc { ::Monitoring::CREATE_ACTIONS }),
11
11
  set('monitoring_delete_action',
12
12
  _('What action should be taken when a host is deleted'),
13
- 'delete', N_('Host Delete Action'), nil, { :collection => proc { ::Monitoring::DELETE_ACTIONS } })
13
+ 'delete', N_('Host Delete Action'), nil, :collection => proc { ::Monitoring::DELETE_ACTIONS })
14
14
  ]
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  <%= text_f f, :comment, :size => "col-md-5", :label => _('Comment'), :help_inline => _('Short description that explains why the downtime was set.'), :required => true %>
2
- <%= monitoring_datetime_f f, :starttime, :size => "col-md-5", :label => _('Starttime'), :help_inline => _('Time when the downtime should start.'), :min => DateTime.now, :value => Time.current, :required => true %>
3
- <%= monitoring_datetime_f f, :endtime, :size => "col-md-5", :label => _('Endtime'), :help_inline => _('Time when the downtime should end.'), :value => Time.current.advance(:hours => 2), :required => true %>
2
+ <%= datetime_f f, :starttime, :size => "col-md-5", :label => _('Starttime'), :help_inline => _('Time when the downtime should start.'), :value => Time.current.strftime("%Y-%m-%dT%H:%M"), :required => true %>
3
+ <%= datetime_f f, :endtime, :size => "col-md-5", :label => _('Endtime'), :help_inline => _('Time when the downtime should end.'), :value => Time.current.advance(:hours => 2).strftime("%Y-%m-%dT%H:%M"), :required => true %>
@@ -1,5 +1,6 @@
1
- class CreateMonitoringResults < ActiveRecord::Migration
1
+ class CreateMonitoringResults < ActiveRecord::Migration[4.2]
2
2
  def change
3
+ # rubocop:disable Rails/CreateTableWithTimestamps
3
4
  create_table :monitoring_results do |t|
4
5
  t.references :host, :null => false
5
6
  t.string :service, :null => false
@@ -8,5 +9,6 @@ class CreateMonitoringResults < ActiveRecord::Migration
8
9
  t.boolean :acknowledged, :default => false, :null => false
9
10
  t.datetime :timestamp
10
11
  end
12
+ # rubocop:enable Rails/CreateTableWithTimestamps
11
13
  end
12
14
  end
@@ -1,4 +1,4 @@
1
- class AddMonitoringProxyIdToHostAndHostgroup < ActiveRecord::Migration
1
+ class AddMonitoringProxyIdToHostAndHostgroup < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  add_column :hosts, :monitoring_proxy_id, :integer
4
4
  add_column :hostgroups, :monitoring_proxy_id, :integer
@@ -17,10 +17,10 @@ module ForemanMonitoring
17
17
  end
18
18
 
19
19
  initializer 'foreman_monitoring.load_default_settings',
20
- :before => :load_config_initializers do |_app|
20
+ :before => :load_config_initializers do |_app|
21
21
  if begin
22
22
  Setting.table_exists?
23
- rescue
23
+ rescue StandardError
24
24
  false
25
25
  end
26
26
  require_dependency File.expand_path('../../../app/models/setting/monitoring.rb', __FILE__)
@@ -29,22 +29,22 @@ module ForemanMonitoring
29
29
 
30
30
  initializer 'foreman_monitoring.register_plugin', :before => :finisher_hook do |_app|
31
31
  Foreman::Plugin.register :foreman_monitoring do
32
- requires_foreman '>= 1.15'
32
+ requires_foreman '>= 1.17'
33
33
 
34
34
  apipie_documented_controllers ["#{ForemanMonitoring::Engine.root}/app/controllers/api/v2/*.rb"]
35
35
 
36
36
  security_block :foreman_monitoring do
37
37
  permission :view_monitoring_results,
38
- {},
39
- :resource_type => 'Host'
38
+ {},
39
+ :resource_type => 'Host'
40
40
  permission :manage_host_downtimes,
41
- { :hosts => [:downtime, :select_multiple_downtime, :update_multiple_downtime] },
42
- :resource_type => 'Host'
41
+ { :hosts => [:downtime, :select_multiple_downtime, :update_multiple_downtime] },
42
+ :resource_type => 'Host'
43
43
  permission :upload_monitoring_results,
44
- :'api/v2/monitoring_results' => [:create]
44
+ :'api/v2/monitoring_results' => [:create]
45
45
  permission :edit_hosts,
46
- { :hosts => [:select_multiple_monitoring_proxy, :update_multiple_monitoring_proxy] },
47
- :resource_type => 'Host'
46
+ { :hosts => [:select_multiple_monitoring_proxy, :update_multiple_monitoring_proxy] },
47
+ :resource_type => 'Host'
48
48
  end
49
49
 
50
50
  role 'Monitoring viewer', [:view_monitoring_results]
@@ -71,11 +71,11 @@ module ForemanMonitoring
71
71
 
72
72
  config.to_prepare do
73
73
  begin
74
- ::Host::Managed.send :include, ForemanMonitoring::HostExtensions
75
- ::Hostgroup.send :include, ForemanMonitoring::HostgroupExtensions
76
- ::HostsHelper.send(:include, ForemanMonitoring::HostsHelperExt)
77
- ::HostsController.send :include, ForemanMonitoring::HostsControllerExtensions
78
- rescue => e
74
+ ::Host::Managed.send(:prepend, ForemanMonitoring::HostExtensions)
75
+ ::Hostgroup.send(:include, ForemanMonitoring::HostgroupExtensions)
76
+ ::HostsHelper.send(:prepend, ForemanMonitoring::HostsHelperExt)
77
+ ::HostsController.send(:prepend, ForemanMonitoring::HostsControllerExtensions)
78
+ rescue StandardError => e
79
79
  Rails.logger.warn "ForemanMonitoring: skipping engine hook (#{e})"
80
80
  end
81
81
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanMonitoring
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -19,7 +19,7 @@ namespace :foreman_monitoring do
19
19
  "#{ForemanMonitoring::Engine.root}/lib/**/*.rb",
20
20
  "#{ForemanMonitoring::Engine.root}/test/**/*.rb"]
21
21
  end
22
- rescue
22
+ rescue StandardError
23
23
  puts 'Rubocop not loaded.'
24
24
  end
25
25
 
@@ -30,6 +30,4 @@ end
30
30
  Rake::Task[:test].enhance ['test:foreman_monitoring']
31
31
 
32
32
  load 'tasks/jenkins.rake'
33
- if Rake::Task.task_defined?(:'jenkins:unit')
34
- Rake::Task['jenkins:unit'].enhance ['test:foreman_monitoring', 'foreman_monitoring:rubocop']
35
- end
33
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_monitoring', 'foreman_monitoring:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
@@ -1,4 +1,4 @@
1
- FactoryGirl.modify do
1
+ FactoryBot.modify do
2
2
  factory :feature do
3
3
  trait :monitoring do
4
4
  name 'Monitoring'
@@ -1,8 +1,8 @@
1
- FactoryGirl.modify do
1
+ FactoryBot.modify do
2
2
  factory :host do
3
3
  trait :with_monitoring do
4
4
  monitoring_proxy do
5
- FactoryGirl.create(:smart_proxy, :monitoring)
5
+ FactoryBot.create(:smart_proxy, :monitoring)
6
6
  end
7
7
  end
8
8
 
@@ -12,7 +12,7 @@ FactoryGirl.modify do
12
12
  end
13
13
  after(:create) do |host, evaluator|
14
14
  evaluator.monitoring_result_count.times do
15
- FactoryGirl.create(:monitoring_result, :host => host)
15
+ FactoryBot.create(:monitoring_result, :host => host)
16
16
  end
17
17
  end
18
18
  end
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :monitoring_result do
3
3
  sequence(:service) { |n| "Service #{n}" }
4
4
  result { rand(0..3) }
@@ -1,4 +1,4 @@
1
- FactoryGirl.modify do
1
+ FactoryBot.modify do
2
2
  factory :smart_proxy do
3
3
  trait :monitoring do
4
4
  features { |sp| [sp.association(:feature, :monitoring)] }
@@ -8,7 +8,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
8
8
  ProxyAPI::Monitoring.stubs(:create_host).returns(true)
9
9
  ProxyAPI::Monitoring.stubs(:update_host).returns(true)
10
10
  ProxyAPI::Monitoring.stubs(:delete_host).returns(true)
11
- @host = FactoryGirl.create(:host, :managed)
11
+ @host = FactoryBot.create(:host, :managed)
12
12
  end
13
13
 
14
14
  context 'when setting a host downtime' do
@@ -18,14 +18,16 @@ class HostsControllerExtensionsTest < ActionController::TestCase
18
18
 
19
19
  test 'the flash should inform it' do
20
20
  Host::Managed.any_instance.stubs(:downtime_host).returns(true)
21
- put :downtime, {
22
- :id => @host.name,
23
- :downtime => {
24
- :comment => 'Maintenance work.',
25
- :starttime => Time.current,
26
- :endtime => Time.current.advance(:hours => 2)
27
- }
28
- }, set_session_user
21
+ put :downtime,
22
+ params: {
23
+ :id => @host.name,
24
+ :downtime => {
25
+ :comment => 'Maintenance work.',
26
+ :starttime => Time.current,
27
+ :endtime => Time.current.advance(:hours => 2)
28
+ }
29
+ },
30
+ session: set_session_user
29
31
  assert_response :found
30
32
  assert_redirected_to host_path(:id => @host)
31
33
  assert_nil flash[:error]
@@ -34,7 +36,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
34
36
  end
35
37
 
36
38
  test 'with missing comment param the flash should inform it' do
37
- put :downtime, { :id => @host.name }, set_session_user
39
+ put :downtime, params: { :id => @host.name }, session: set_session_user
38
40
  assert_response :found
39
41
  assert_redirected_to host_path(:id => @host)
40
42
  assert_not_nil flash[:error]
@@ -42,7 +44,9 @@ class HostsControllerExtensionsTest < ActionController::TestCase
42
44
  end
43
45
 
44
46
  test 'with missing date params the flash should inform it' do
45
- put :downtime, { :id => @host.name, :downtime => { :comment => 'Maintenance work.' } }, set_session_user
47
+ put :downtime,
48
+ params: { :id => @host.name, :downtime => { :comment => 'Maintenance work.' } },
49
+ session: set_session_user
46
50
  assert_response :found
47
51
  assert_redirected_to host_path(:id => @host)
48
52
  assert_not_nil flash[:error]
@@ -50,14 +54,16 @@ class HostsControllerExtensionsTest < ActionController::TestCase
50
54
  end
51
55
 
52
56
  test 'with invalid starttime the flash should inform it' do
53
- put :downtime, {
54
- :id => @host.name,
55
- :downtime => {
56
- :comment => 'Maintenance work.',
57
- :starttime => 'invalid',
58
- :endtime => 'invalid'
59
- }
60
- }, set_session_user
57
+ put :downtime,
58
+ params: {
59
+ :id => @host.name,
60
+ :downtime => {
61
+ :comment => 'Maintenance work.',
62
+ :starttime => 'invalid',
63
+ :endtime => 'invalid'
64
+ }
65
+ },
66
+ session: set_session_user
61
67
  assert_response :found
62
68
  assert_redirected_to host_path(:id => @host)
63
69
  assert_not_nil flash[:error]
@@ -65,28 +71,34 @@ class HostsControllerExtensionsTest < ActionController::TestCase
65
71
  end
66
72
 
67
73
  test 'should parse the times in the correct time zone' do
68
- User.current.update_attribute(:timezone, 'Berlin')
74
+ User.current.timezone = 'Berlin'
75
+ User.current.save
69
76
  Host::Managed.any_instance.expects(:downtime_host).with(has_entries(:start_time => 1_492_676_100, :end_time => 1_492_683_300))
70
- put :downtime, {
71
- :id => @host.name,
72
- :downtime => {
73
- :comment => 'Maintenance work.',
74
- :starttime => '2017-04-20T10:15',
75
- :endtime => '2017-04-20T12:15'
76
- }
77
- }, set_session_user
77
+ put :downtime,
78
+ params: {
79
+ :id => @host.name,
80
+ :downtime => {
81
+ :comment => 'Maintenance work.',
82
+ :starttime => '2017-04-20T10:15',
83
+ :endtime => '2017-04-20T12:15'
84
+ }
85
+ },
86
+ session: set_session_user
78
87
  end
79
88
  end
80
89
 
81
90
  describe 'setting a downtime on multiple hosts' do
82
91
  before do
83
- @hosts = FactoryGirl.create_list(:host, 2, :with_monitoring)
92
+ @hosts = FactoryBot.create_list(:host, 2, :with_monitoring)
84
93
  @request.env['HTTP_REFERER'] = hosts_path
85
94
  end
86
95
 
87
96
  test 'show a host selection' do
88
97
  host_ids = @hosts.map(&:id)
89
- xhr :post, :select_multiple_downtime, { :host_ids => host_ids }, set_session_user
98
+ post :select_multiple_downtime,
99
+ params: { :host_ids => host_ids },
100
+ session: set_session_user,
101
+ xhr: true
90
102
  assert_response :success
91
103
  assert_includes response.body, @hosts.first.name
92
104
  assert_includes response.body, @hosts.last.name
@@ -103,8 +115,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
103
115
  }
104
116
  }
105
117
 
106
- post :update_multiple_downtime, params,
107
- set_session_user
118
+ post :update_multiple_downtime, params: params, session: set_session_user
108
119
 
109
120
  assert_response :found
110
121
  assert_redirected_to hosts_path
@@ -116,7 +127,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
116
127
 
117
128
  describe 'changing the power state on multiple hosts' do
118
129
  before do
119
- @hosts = FactoryGirl.create_list(:host, 2, :with_monitoring)
130
+ @hosts = FactoryBot.create_list(:host, 2, :with_monitoring)
120
131
  @request.env['HTTP_REFERER'] = hosts_path
121
132
 
122
133
  power_mock = mock('power')
@@ -135,8 +146,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
135
146
  }
136
147
  }
137
148
 
138
- post :update_multiple_power_state, params,
139
- set_session_user
149
+ post :update_multiple_power_state, params: params, session: set_session_user
140
150
 
141
151
  assert_response :found
142
152
  assert_redirected_to hosts_path
@@ -155,8 +165,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
155
165
  }
156
166
  }
157
167
 
158
- post :update_multiple_power_state, params,
159
- set_session_user
168
+ post :update_multiple_power_state, params: params, session: set_session_user
160
169
 
161
170
  assert_response :found
162
171
  assert_redirected_to hosts_path
@@ -167,15 +176,18 @@ class HostsControllerExtensionsTest < ActionController::TestCase
167
176
  end
168
177
 
169
178
  describe 'changing the monitoring proxy of multiple hosts' do
170
- let(:hosts) { FactoryGirl.create_list(:host, 2, :with_monitoring) }
171
- let(:monitoring_proxy) { FactoryGirl.create(:smart_proxy, :monitoring, :organizations => [hosts.first.organization], :locations => [hosts.first.location]) }
179
+ let(:hosts) { FactoryBot.create_list(:host, 2, :with_monitoring) }
180
+ let(:monitoring_proxy) { FactoryBot.create(:smart_proxy, :monitoring, :organizations => [hosts.first.organization], :locations => [hosts.first.location]) }
172
181
  before do
173
182
  @request.env['HTTP_REFERER'] = hosts_path
174
183
  end
175
184
 
176
185
  test 'show a host selection' do
177
186
  host_ids = hosts.map(&:id)
178
- xhr :post, :select_multiple_monitoring_proxy, { :host_ids => host_ids }, set_session_user
187
+ post :select_multiple_monitoring_proxy,
188
+ params: { :host_ids => host_ids },
189
+ session: set_session_user,
190
+ xhr: true
179
191
  assert_response :success
180
192
  hosts.each do |host|
181
193
  assert response.body =~ /#{host.name}/m
@@ -192,8 +204,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase
192
204
  :proxy => { :proxy_id => monitoring_proxy.id }
193
205
  }
194
206
 
195
- post :update_multiple_monitoring_proxy, params,
196
- set_session_user
207
+ post :update_multiple_monitoring_proxy, params: params, session: set_session_user
197
208
 
198
209
  assert_response :found
199
210
  assert_redirected_to hosts_path
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class ProxyApiDhcpTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  @url = 'http://localhost:8443'
6
- @monitoring = ProxyAPI::Monitoring.new({ :url => @url })
6
+ @monitoring = ProxyAPI::Monitoring.new(:url => @url)
7
7
  end
8
8
 
9
9
  test 'constructor should complete' do
@@ -15,38 +15,38 @@ class ProxyApiDhcpTest < ActiveSupport::TestCase
15
15
  end
16
16
 
17
17
  test 'create_host_downtime should do post' do
18
- @monitoring.expects(:post).with({}, 'downtime/host/example.com').
19
- returns(fake_rest_client_response({ 'result' => {} }))
18
+ @monitoring.expects(:post).with({}, 'downtime/host/example.com')
19
+ .returns(fake_rest_client_response('result' => {}))
20
20
  assert_equal({ 'result' => {} }, @monitoring.create_host_downtime('example.com'))
21
21
  end
22
22
 
23
23
  test 'remove_host_downtime should do delete' do
24
- @monitoring.expects(:delete).with('downtime/host/example.com?comment=bla').
25
- returns(fake_rest_client_response({ 'result' => {} }))
24
+ @monitoring.expects(:delete).with('downtime/host/example.com?comment=bla')
25
+ .returns(fake_rest_client_response('result' => {}))
26
26
  assert_equal({ 'result' => {} }, @monitoring.remove_host_downtime('example.com', :comment => 'bla'))
27
27
  end
28
28
 
29
29
  test 'create_host should do put' do
30
- @monitoring.expects(:put).with({ :attributes => { :ip => '1.1.1.1' } }, 'host/example.com').
31
- returns(fake_rest_client_response({ 'result' => {} }))
30
+ @monitoring.expects(:put).with({ :attributes => { :ip => '1.1.1.1' } }, 'host/example.com')
31
+ .returns(fake_rest_client_response('result' => {}))
32
32
  assert_equal({ 'result' => {} }, @monitoring.create_host('example.com', :ip => '1.1.1.1'))
33
33
  end
34
34
 
35
35
  test 'update_host should do post' do
36
- @monitoring.expects(:post).with({ :attributes => { :ip => '1.1.1.1' } }, 'host/example.com').
37
- returns(fake_rest_client_response({ 'result' => {} }))
36
+ @monitoring.expects(:post).with({ :attributes => { :ip => '1.1.1.1' } }, 'host/example.com')
37
+ .returns(fake_rest_client_response('result' => {}))
38
38
  assert_equal({ 'result' => {} }, @monitoring.update_host('example.com', :ip => '1.1.1.1'))
39
39
  end
40
40
 
41
41
  test 'delete_host should do delete' do
42
- @monitoring.expects(:delete).with('host/example.com').
43
- returns(fake_rest_client_response({ 'result' => {} }))
42
+ @monitoring.expects(:delete).with('host/example.com')
43
+ .returns(fake_rest_client_response('result' => {}))
44
44
  assert_equal({ 'result' => {} }, @monitoring.delete_host('example.com'))
45
45
  end
46
46
 
47
47
  test 'query_host should do get' do
48
- @monitoring.expects(:get).with('host/example.com').
49
- returns(fake_rest_client_response({ 'result' => {} }))
48
+ @monitoring.expects(:get).with('host/example.com')
49
+ .returns(fake_rest_client_response('result' => {}))
50
50
  assert_equal({ 'result' => {} }, @monitoring.query_host('example.com'))
51
51
  end
52
52
  end
@@ -2,9 +2,9 @@
2
2
  require 'test_helper'
3
3
  require 'database_cleaner'
4
4
 
5
- # Add plugin to FactoryGirl's paths
6
- FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
7
- FactoryGirl.reload
5
+ # Add plugin to FactoryBot's paths
6
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
7
+ FactoryBot.reload
8
8
 
9
9
  # Foreman's setup doesn't handle cleaning up for Minitest::Spec
10
10
  DatabaseCleaner.strategy = :transaction
@@ -6,55 +6,55 @@ class MonitoringStatusTest < ActiveSupport::TestCase
6
6
  disable_monitoring_orchestration
7
7
  end
8
8
 
9
- let(:host) { FactoryGirl.create(:host, :with_monitoring) }
9
+ let(:host) { FactoryBot.create(:host, :with_monitoring) }
10
10
  let(:status) { HostStatus::MonitoringStatus.new(:host => host) }
11
11
 
12
12
  context 'status changes' do
13
13
  test '#to_status should change when monitoring results change' do
14
- FactoryGirl.create(:monitoring_result, :ok, :host => host)
14
+ FactoryBot.create(:monitoring_result, :ok, :host => host)
15
15
  assert_equal HostStatus::MonitoringStatus::OK, status.to_status
16
16
 
17
- FactoryGirl.create(:monitoring_result, :warning, :host => host)
17
+ FactoryBot.create(:monitoring_result, :warning, :host => host)
18
18
  assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
19
19
 
20
- FactoryGirl.create(:monitoring_result, :unknown, :host => host)
20
+ FactoryBot.create(:monitoring_result, :unknown, :host => host)
21
21
  assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
22
22
 
23
- FactoryGirl.create(:monitoring_result, :critical, :host => host)
23
+ FactoryBot.create(:monitoring_result, :critical, :host => host)
24
24
  assert_equal HostStatus::MonitoringStatus::CRITICAL, status.to_status
25
25
  end
26
26
 
27
27
  test '#to_status should be warning with critical acknowledged' do
28
- FactoryGirl.create(:monitoring_result, :critical, :acknowledged, :host => host)
28
+ FactoryBot.create(:monitoring_result, :critical, :acknowledged, :host => host)
29
29
  assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
30
30
  end
31
31
 
32
32
  test '#to_status should be ok with critical in downtime' do
33
- FactoryGirl.create(:monitoring_result, :critical, :downtime, :host => host)
33
+ FactoryBot.create(:monitoring_result, :critical, :downtime, :host => host)
34
34
  assert_equal HostStatus::MonitoringStatus::OK, status.to_status
35
35
  end
36
36
 
37
37
  test '#to_global should change when monitoring results change' do
38
- FactoryGirl.create(:monitoring_result, :ok, :host => host)
38
+ FactoryBot.create(:monitoring_result, :ok, :host => host)
39
39
  status.refresh
40
40
  assert_equal HostStatus::Global::OK, status.to_global
41
41
 
42
- FactoryGirl.create(:monitoring_result, :warning, :host => host)
42
+ FactoryBot.create(:monitoring_result, :warning, :host => host)
43
43
  status.refresh
44
44
  assert_equal HostStatus::Global::WARN, status.to_global
45
45
 
46
- FactoryGirl.create(:monitoring_result, :unknown, :host => host)
46
+ FactoryBot.create(:monitoring_result, :unknown, :host => host)
47
47
  status.refresh
48
48
  assert_equal HostStatus::Global::WARN, status.to_global
49
49
 
50
- FactoryGirl.create(:monitoring_result, :critical, :host => host)
50
+ FactoryBot.create(:monitoring_result, :critical, :host => host)
51
51
  status.refresh
52
52
  assert_equal HostStatus::Global::ERROR, status.to_global
53
53
  end
54
54
  end
55
55
 
56
56
  context 'status with host with monitoring results' do
57
- let(:host) { FactoryGirl.create(:host, :with_monitoring, :with_monitoring_results) }
57
+ let(:host) { FactoryBot.create(:host, :with_monitoring, :with_monitoring_results) }
58
58
 
59
59
  test '#relevant? is only for hosts not in build mode' do
60
60
  host.build = false
@@ -2,14 +2,14 @@ require 'test_plugin_helper'
2
2
 
3
3
  class HostTest < ActiveSupport::TestCase
4
4
  setup do
5
- User.current = FactoryGirl.build(:user, :admin)
5
+ User.current = FactoryBot.build(:user, :admin)
6
6
  setup_settings
7
7
  disable_orchestration
8
8
  disable_monitoring_orchestration
9
9
  end
10
10
 
11
11
  context 'downtime handling' do
12
- let(:host) { FactoryGirl.create(:host, :managed) }
12
+ let(:host) { FactoryBot.create(:host, :managed) }
13
13
 
14
14
  test 'it should set a downtime when build status changes' do
15
15
  host.expects(:downtime_host).once
@@ -22,7 +22,7 @@ class HostTest < ActiveSupport::TestCase
22
22
  end
23
23
 
24
24
  context 'a host with monitoring orchestration' do
25
- let(:host) { FactoryGirl.build(:host, :managed, :with_monitoring) }
25
+ let(:host) { FactoryBot.build(:host, :managed, :with_monitoring) }
26
26
 
27
27
  context 'with create/delete actions' do
28
28
  setup do
@@ -125,7 +125,7 @@ class HostTest < ActiveSupport::TestCase
125
125
  end
126
126
 
127
127
  context 'a host without monitoring' do
128
- let(:host) { FactoryGirl.build(:host, :managed) }
128
+ let(:host) { FactoryBot.build(:host, :managed) }
129
129
 
130
130
  test 'should not queue any monitoring actions' do
131
131
  assert_valid host
@@ -2,13 +2,13 @@ require 'test_plugin_helper'
2
2
 
3
3
  class MonitoringTest < ActiveSupport::TestCase
4
4
  setup do
5
- User.current = FactoryGirl.build(:user, :admin)
5
+ User.current = FactoryBot.build(:user, :admin)
6
6
  setup_settings
7
7
  disable_monitoring_orchestration
8
8
  end
9
9
 
10
- let(:monitoring_proxy) { FactoryGirl.create(:smart_proxy, :monitoring) }
11
- let(:host) { FactoryGirl.create(:host, :managed, :with_monitoring, :monitoring_proxy => monitoring_proxy) }
10
+ let(:monitoring_proxy) { FactoryBot.create(:smart_proxy, :monitoring) }
11
+ let(:host) { FactoryBot.create(:host, :managed, :with_monitoring, :monitoring_proxy => monitoring_proxy) }
12
12
  let(:monitoring) { Monitoring.new(:monitoring_proxy => monitoring_proxy) }
13
13
 
14
14
  test '#set_downtime_host should call proxy api' do
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubocop
14
+ name: rdoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.49.1
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.49.1
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rdoc
28
+ name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.52.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.52.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: deface
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,6 @@ files:
104
104
  - test/test_plugin_helper.rb
105
105
  - test/unit/host_status/monitoring_status_test.rb
106
106
  - test/unit/host_test.rb
107
- - test/unit/monitoring_result_test.rb
108
107
  - test/unit/monitoring_test.rb
109
108
  homepage: http://www.github.com/theforeman/foreman_monitoring
110
109
  licenses:
@@ -131,14 +130,13 @@ signing_key:
131
130
  specification_version: 4
132
131
  summary: Foreman plugin for monitoring system integration.
133
132
  test_files:
134
- - test/unit/host_test.rb
135
- - test/unit/monitoring_result_test.rb
136
- - test/unit/host_status/monitoring_status_test.rb
137
- - test/unit/monitoring_test.rb
138
- - test/factories/smart_proxy.rb
139
- - test/factories/monitoring_results.rb
140
133
  - test/factories/feature.rb
141
134
  - test/factories/host.rb
135
+ - test/factories/monitoring_results.rb
136
+ - test/factories/smart_proxy.rb
137
+ - test/functional/hosts_controller_test.rb
142
138
  - test/lib/proxy_api/monitoring_test.rb
143
139
  - test/test_plugin_helper.rb
144
- - test/functional/hosts_controller_test.rb
140
+ - test/unit/host_status/monitoring_status_test.rb
141
+ - test/unit/host_test.rb
142
+ - test/unit/monitoring_test.rb
@@ -1,73 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class MonitoringResultTest < ActiveSupport::TestCase
4
- setup do
5
- User.current = FactoryBot.build(:user, :admin)
6
- setup_settings
7
- disable_orchestration
8
- disable_monitoring_orchestration
9
- end
10
-
11
- context '#import' do
12
- let(:host) { FactoryBot.create(:host, :managed, :with_monitoring) }
13
-
14
- let(:initial) do
15
- {
16
- host: host.name,
17
- service: 'cpu metrics',
18
- timestamp: 1_516_365_380.8834700584,
19
- result: 1,
20
- acknowledged: true
21
- }
22
- end
23
-
24
- let(:acknowledegment_cleared) do
25
- {
26
- host: host.name,
27
- service: 'cpu metrics',
28
- timestamp: 1_516_365_971.2455039024,
29
- acknowledged: false
30
- }
31
- end
32
-
33
- let(:state_change) do
34
- {
35
- host: host.name,
36
- service: 'cpu metrics',
37
- timestamp: 1_516_365_971.2461779118,
38
- result: 0
39
- }
40
- end
41
-
42
- test 'imports a monitoring result' do
43
- MonitoringResult.import(initial)
44
- imported = host.monitoring_results.last
45
- assert_equal true, imported.acknowledged?
46
- end
47
-
48
- test 'handles ack and state change in correct order' do
49
- MonitoringResult.import(initial)
50
- MonitoringResult.import(acknowledegment_cleared)
51
- MonitoringResult.import(state_change)
52
- imported = host.monitoring_results.last
53
- assert_equal :ok, imported.status
54
- assert_equal false, imported.acknowledged?
55
- end
56
-
57
- test 'handles ack and state change in reverse order' do
58
- MonitoringResult.import(initial)
59
- MonitoringResult.import(state_change)
60
- MonitoringResult.import(acknowledegment_cleared)
61
- imported = host.monitoring_results.last
62
- assert_equal :ok, imported.status
63
- assert_equal false, imported.acknowledged?
64
- end
65
-
66
- test 'ignores old data' do
67
- MonitoringResult.import(state_change)
68
- MonitoringResult.import(initial)
69
- imported = host.monitoring_results.last
70
- assert_equal false, imported.acknowledged?
71
- end
72
- end
73
- end