foreman_monitoring 2.1.0 → 3.1.0

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: 6bc195afe4c0af30313894eaf37dcf99c36625fe510998783df94932111c9891
4
- data.tar.gz: 8d37c47d99c8d48163242ce490159c59a6a4e6c2588709daac0bac841a450c5a
3
+ metadata.gz: b8c19621c4296a6cc5d051522ee0176ef3a4726f24bc73eda2c1182c812939c5
4
+ data.tar.gz: 1691af6f9079acd23c0f826b6052605d99eff64346c127a5b50a2fbac4e38344
5
5
  SHA512:
6
- metadata.gz: cf715511ef2835a64702b2f865c6380c178dd8c70b2038428ea3a0c9a72fefcef4715ec4c2bcca82fbf687c9ea5a463c5e041009fe7e795cb6aab6484020d6f3
7
- data.tar.gz: 8c4c4cbaad0dffa2f7d338d19e116cc58c05272b262d36d5bf221137391577a414dcd3ba83c34d78c46207bf8298675529a988d42fd736961751687325b615b1
6
+ metadata.gz: 57746ee94c93571b9e8fa14050f2ff1358d265fa710908175fa26b9baa799c5597d31ef2b8a71c3d31b9a57c6c6e4e46fc7377700d1a4f686e1db2a18835f54c
7
+ data.tar.gz: 14c121e8aaf4c486e1fdd74ce09747578658cc8f8d7c5c9e471d897ea55fe27d8e5c5a3068c87373988af09d6b96bfee113fb90428680abed618eca0c825ebbd
data/README.md CHANGED
@@ -36,6 +36,8 @@ touch ~foreman/tmp/restart.txt
36
36
  | >= 1.17 | ~> 1.0 |
37
37
  | >= 2.0 | ~> 2.0 |
38
38
  | >= 2.2 | ~> 2.1 |
39
+ | >= 3.0 | ~> 3.0 |
40
+ | >= 3.6 | ~> 3.1 |
39
41
 
40
42
  # Usage
41
43
 
@@ -10,6 +10,7 @@ module Api
10
10
  before_action :find_host, :only => [:create]
11
11
 
12
12
  api :POST, '/downtime', N_('Schedule host downtime')
13
+ param :all_services, [true, false], :desc => N_('Set downtime for all services'), :required => false
13
14
  param :duration, :number, :desc => N_('Downtime duration (seconds)'), :required => false
14
15
  param :reason, String, :desc => N_('Downtime reason'), :required => false
15
16
 
@@ -18,6 +19,7 @@ module Api
18
19
  options = {
19
20
  :comment => downtime_params[:reason] || _('Host requested downtime')
20
21
  }
22
+ options[:all_services] = downtime_params[:all_services] if downtime_params.key? :all_services
21
23
  if downtime_params.key? :duration
22
24
  options[:start_time] = Time.now.to_i
23
25
  options[:end_time] = Time.now.to_i + downtime_params[:duration].to_i
@@ -35,7 +37,7 @@ module Api
35
37
  private
36
38
 
37
39
  def downtime_params
38
- params.permit(:duration, :reason)
40
+ params.permit(:all_services, :duration, :reason)
39
41
  end
40
42
 
41
43
  def find_host
@@ -3,7 +3,7 @@
3
3
  module ProxyAPI
4
4
  class Monitoring < ProxyAPI::Resource
5
5
  def initialize(args)
6
- @url = args[:url] + '/monitoring'
6
+ @url = "#{args[:url]}/monitoring"
7
7
  super args
8
8
  end
9
9
 
@@ -56,7 +56,7 @@ module ForemanMonitoring
56
56
  end
57
57
 
58
58
  def monitoring_attributes
59
- {
59
+ attributes = {
60
60
  :ip => ip,
61
61
  :ip6 => ip6,
62
62
  :architecture => architecture.try(:name),
@@ -69,9 +69,12 @@ module ForemanMonitoring
69
69
  :organization => organization.try(:name),
70
70
  :location => location.try(:name),
71
71
  :comment => comment,
72
- :environment => environment.try(:to_s),
73
72
  :owner_name => owner.try(:name)
74
73
  }
74
+
75
+ attributes[:environment] = environment.try(:to_s) if defined?(ForemanPuppet)
76
+
77
+ attributes
75
78
  end
76
79
 
77
80
  private
@@ -30,7 +30,6 @@ class MonitoringResult < ApplicationRecord
30
30
  end
31
31
 
32
32
  created = MonitoringResult.where(:host => host, :service => result[:service]).first_or_create
33
- # rubocop:disable Rails/Date
34
33
  if created.timestamp.blank? || updates[:timestamp].blank? || (created.timestamp.to_time - updates[:timestamp].to_time) < 2
35
34
  created.update(updates)
36
35
 
@@ -41,7 +40,6 @@ class MonitoringResult < ApplicationRecord
41
40
  else
42
41
  logger.debug "Skipping monitoring result import for #{host} as it is older than what we have."
43
42
  end
44
- # rubocop:enable Rails/Date
45
43
  end
46
44
  # rubocop:enable Metrics/AbcSize
47
45
 
data/config/routes.rb CHANGED
@@ -12,7 +12,7 @@ Rails.application.routes.draw do
12
12
  end
13
13
 
14
14
  scope '/monitoring' do
15
- constraints(:id => %r{[^\/]+}) do
15
+ constraints(:id => %r{[^/]+}) do
16
16
  resources :hosts, :only => [] do
17
17
  member do
18
18
  put 'downtime'
@@ -2,14 +2,10 @@
2
2
 
3
3
  class RenameDowntimeHostPermission < ActiveRecord::Migration[5.2]
4
4
  def up
5
- # rubocop:disable Rails/SkipsModelValidations
6
5
  Permission.where(name: 'manage_host_downtimes').update_all(name: 'manage_downtime_hosts') if table_exists?(:permissions)
7
- # rubocop:enable Rails/SkipsModelValidations
8
6
  end
9
7
 
10
8
  def down
11
- # rubocop:disable Rails/SkipsModelValidations
12
9
  Permission.where(name: 'manage_downtime_hosts').update_all(name: 'manage_host_downtimes') if table_exists?(:permissions)
13
- # rubocop:enable Rails/SkipsModelValidations
14
10
  end
15
11
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FixMonitoringSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4
+ def up
5
+ Setting.where(category: 'Setting::Monitoring').update_all(category: 'Setting') if column_exists?(:settings, :category)
6
+ end
7
+ end
@@ -18,19 +18,31 @@ module ForemanMonitoring
18
18
  end
19
19
  end
20
20
 
21
- initializer 'foreman_monitoring.load_default_settings',
22
- :before => :load_config_initializers do |_app|
23
- setting_table_exists = begin
24
- Setting.table_exists?
25
- rescue StandardError
26
- false
27
- end
28
- require_dependency File.expand_path('../../app/models/setting/monitoring.rb', __dir__) if setting_table_exists
29
- end
30
-
31
21
  initializer 'foreman_monitoring.register_plugin', :before => :finisher_hook do |_app|
32
22
  Foreman::Plugin.register :foreman_monitoring do
33
- requires_foreman '>= 2.2'
23
+ requires_foreman '>= 3.0'
24
+
25
+ settings do
26
+ category(:monitoring, N_('Monitoring')) do
27
+ setting('monitoring_affect_global_status',
28
+ type: :boolean,
29
+ description: N_("Monitoring status will affect a host's global status when enabled"),
30
+ default: true,
31
+ full_name: N_('Monitoring status should affect global status'))
32
+ setting('monitoring_create_action',
33
+ type: :string,
34
+ description: N_('What action should be taken when a host is created'),
35
+ default: 'create',
36
+ full_name: N_('Host Create Action'),
37
+ collection: proc { ::Monitoring::CREATE_ACTIONS })
38
+ setting('monitoring_delete_action',
39
+ type: :string,
40
+ description: N_('What action should be taken when a host is deleted'),
41
+ default: 'delete',
42
+ full_name: N_('Host Delete Action'),
43
+ collection: proc { ::Monitoring::DELETE_ACTIONS })
44
+ end
45
+ end
34
46
 
35
47
  apipie_documented_controllers ["#{ForemanMonitoring::Engine.root}/app/controllers/api/v2/*.rb"]
36
48
 
@@ -74,14 +86,12 @@ module ForemanMonitoring
74
86
  end
75
87
 
76
88
  config.to_prepare do
77
- begin
78
- ::Host::Managed.prepend(ForemanMonitoring::HostExtensions)
79
- ::Hostgroup.include(ForemanMonitoring::HostgroupExtensions)
80
- ::HostsHelper.prepend(ForemanMonitoring::HostsHelperExt)
81
- ::HostsController.prepend(ForemanMonitoring::HostsControllerExtensions)
82
- rescue StandardError => e
83
- Rails.logger.warn "ForemanMonitoring: skipping engine hook (#{e})"
84
- end
89
+ ::Host::Managed.prepend(ForemanMonitoring::HostExtensions)
90
+ ::Hostgroup.include(ForemanMonitoring::HostgroupExtensions)
91
+ ::HostsHelper.prepend(ForemanMonitoring::HostsHelperExt)
92
+ ::HostsController.prepend(ForemanMonitoring::HostsControllerExtensions)
93
+ rescue StandardError => e
94
+ Rails.logger.warn "ForemanMonitoring: skipping engine hook (#{e})"
85
95
  end
86
96
 
87
97
  initializer 'foreman_monitoring.register_gettext', after: :load_config_initializers do |_app|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanMonitoring
4
- VERSION = '2.1.0'
4
+ VERSION = '3.1.0'
5
5
  end
@@ -34,6 +34,26 @@ class Api::V2::DowntimeControllerTest < ActionController::TestCase
34
34
  end
35
35
  end
36
36
 
37
+ context '#create with all_services' do
38
+ test 'should create downtime without all_services value if none given' do
39
+ Host::Managed.any_instance.expects(:downtime_host).with { |params| !params.key? :all_services }
40
+ post :create
41
+ assert_response :success
42
+ end
43
+
44
+ test 'should create downtime with given all_services value' do
45
+ Host::Managed.any_instance.expects(:downtime_host).with { |params| params[:all_services] }
46
+ post :create, params: { all_services: true }
47
+ assert_response :success
48
+ end
49
+
50
+ test 'should create downtime with given all_services value even if false' do
51
+ Host::Managed.any_instance.expects(:downtime_host).with { |params| params[:all_services] == false }
52
+ post :create, params: { all_services: false }
53
+ assert_response :success
54
+ end
55
+ end
56
+
37
57
  context '#create with duration' do
38
58
  test 'should create downtime with given duration' do
39
59
  Host::Managed.any_instance.expects(:downtime_host).with { |params| params[:end_time] - params[:start_time] == 3600 }
@@ -11,10 +11,6 @@ FactoryBot.reload
11
11
  # Foreman's setup doesn't handle cleaning up for Minitest::Spec
12
12
  DatabaseCleaner.strategy = :transaction
13
13
 
14
- def setup_settings
15
- Setting::Monitoring.load_defaults
16
- end
17
-
18
14
  def disable_monitoring_orchestration
19
15
  ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns({})
20
16
  end
@@ -4,7 +4,6 @@ require 'test_plugin_helper'
4
4
 
5
5
  class MonitoringStatusTest < ActiveSupport::TestCase
6
6
  setup do
7
- setup_settings
8
7
  disable_monitoring_orchestration
9
8
  end
10
9
 
@@ -5,7 +5,6 @@ require 'test_plugin_helper'
5
5
  class HostTest < ActiveSupport::TestCase
6
6
  setup do
7
7
  User.current = FactoryBot.build(:user, :admin)
8
- setup_settings
9
8
  disable_orchestration
10
9
  disable_monitoring_orchestration
11
10
  end
@@ -62,7 +61,7 @@ class HostTest < ActiveSupport::TestCase
62
61
  ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns(fake_host_query_result)
63
62
  assert_valid host
64
63
  tasks = host.queue.all.map(&:name)
65
- assert_equal [], tasks
64
+ assert_empty tasks
66
65
  end
67
66
 
68
67
  test 'should queue monitoring destroy' do
@@ -84,7 +83,7 @@ class HostTest < ActiveSupport::TestCase
84
83
  test 'should not queue monitoring create actions' do
85
84
  assert_valid host
86
85
  tasks = host.queue.all.map(&:name)
87
- assert_equal [], tasks
86
+ assert_empty tasks
88
87
  end
89
88
 
90
89
  test 'should queue monitoring downtime on host destroy' do
@@ -135,7 +134,7 @@ class HostTest < ActiveSupport::TestCase
135
134
  host.send(:queue_monitoring)
136
135
  host.send(:queue_monitoring_destroy)
137
136
  tasks = host.queue.all.map(&:name)
138
- assert_equal [], tasks
137
+ assert_empty tasks
139
138
  end
140
139
  end
141
140
  end
@@ -5,7 +5,6 @@ require 'test_plugin_helper'
5
5
  class MonitoringResultTest < ActiveSupport::TestCase
6
6
  setup do
7
7
  User.current = FactoryBot.build(:user, :admin)
8
- setup_settings
9
8
  disable_orchestration
10
9
  disable_monitoring_orchestration
11
10
  end
@@ -5,7 +5,6 @@ require 'test_plugin_helper'
5
5
  class MonitoringTest < ActiveSupport::TestCase
6
6
  setup do
7
7
  User.current = FactoryBot.build(:user, :admin)
8
- setup_settings
9
8
  disable_monitoring_orchestration
10
9
  end
11
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-01 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.80.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.80.0
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop-minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop-performance
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-rails
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
27
  - !ruby/object:Gem::Dependency
84
28
  name: deface
85
29
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +59,6 @@ files:
115
59
  - app/models/concerns/orchestration/monitoring.rb
116
60
  - app/models/host_status/monitoring_status.rb
117
61
  - app/models/monitoring_result.rb
118
- - app/models/setting/monitoring.rb
119
62
  - app/overrides/add_host_monitoring_result_tab.rb
120
63
  - app/overrides/add_host_multiple_power_set_downtime_checkbox.rb
121
64
  - app/overrides/add_host_set_downtime_modal.rb
@@ -131,6 +74,7 @@ files:
131
74
  - db/migrate/20160817135723_create_monitoring_results.rb
132
75
  - db/migrate/20161220201510_add_monitoring_proxy_id_to_host_and_hostgroup.rb
133
76
  - db/migrate/201910180900_rename_downtime_host_permission.rb
77
+ - db/migrate/20221026065954_fix_monitoring_settings_category_to_dsl.rb
134
78
  - db/seeds.d/60-monitoring_proxy_feature.rb
135
79
  - lib/foreman_monitoring.rb
136
80
  - lib/foreman_monitoring/engine.rb
@@ -156,7 +100,7 @@ homepage: https://github.com/theforeman/foreman_monitoring
156
100
  licenses:
157
101
  - GPL-3.0
158
102
  metadata: {}
159
- post_install_message:
103
+ post_install_message:
160
104
  rdoc_options: []
161
105
  require_paths:
162
106
  - lib
@@ -164,27 +108,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
108
  requirements:
165
109
  - - ">="
166
110
  - !ruby/object:Gem::Version
167
- version: '0'
111
+ version: '2.7'
112
+ - - "<"
113
+ - !ruby/object:Gem::Version
114
+ version: '4'
168
115
  required_rubygems_version: !ruby/object:Gem::Requirement
169
116
  requirements:
170
117
  - - ">="
171
118
  - !ruby/object:Gem::Version
172
119
  version: '0'
173
120
  requirements: []
174
- rubygems_version: 3.0.3
175
- signing_key:
121
+ rubygems_version: 3.5.9
122
+ signing_key:
176
123
  specification_version: 4
177
124
  summary: Foreman plugin for monitoring system integration.
178
125
  test_files:
126
+ - test/controllers/api/v2/downtime_controller_test.rb
127
+ - test/factories/feature.rb
179
128
  - test/factories/host.rb
180
129
  - test/factories/monitoring_results.rb
181
130
  - test/factories/smart_proxy.rb
182
- - test/factories/feature.rb
183
- - test/lib/proxy_api/monitoring_test.rb
184
131
  - test/functional/hosts_controller_test.rb
185
- - test/controllers/api/v2/downtime_controller_test.rb
132
+ - test/lib/proxy_api/monitoring_test.rb
186
133
  - test/test_plugin_helper.rb
187
- - test/unit/monitoring_result_test.rb
134
+ - test/unit/host_status/monitoring_status_test.rb
188
135
  - test/unit/host_test.rb
136
+ - test/unit/monitoring_result_test.rb
189
137
  - test/unit/monitoring_test.rb
190
- - test/unit/host_status/monitoring_status_test.rb
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Setting
4
- class Monitoring < ::Setting
5
- def self.default_settings
6
- [
7
- set('monitoring_affect_global_status',
8
- _("Monitoring status will affect a host's global status when enabled"),
9
- true, N_('Monitoring status should affect global status')),
10
- set('monitoring_create_action',
11
- _('What action should be taken when a host is created'),
12
- 'create', N_('Host Create Action'), nil, :collection => proc { ::Monitoring::CREATE_ACTIONS }),
13
- set('monitoring_delete_action',
14
- _('What action should be taken when a host is deleted'),
15
- 'delete', N_('Host Delete Action'), nil, :collection => proc { ::Monitoring::DELETE_ACTIONS })
16
- ]
17
- end
18
-
19
- def self.load_defaults
20
- # Check the table exists
21
- return unless super
22
-
23
- self.transaction do
24
- default_settings.each { |s| self.create! s.update(:category => 'Setting::Monitoring') }
25
- end
26
-
27
- true
28
- end
29
-
30
- def self.humanized_category
31
- N_('Monitoring')
32
- end
33
- end
34
- end