foreman_monitoring 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bba72edc0a48bb00f5818a0662ef643ea892cef4f457b474fd35332471bf1751
4
- data.tar.gz: b62364ba84ac51878993cd2d6d7be654cfb10aa2c2a565b2ec71f6dc38f933a1
3
+ metadata.gz: 685e5be086aa9ee637a3ef119df3310475334138a687f2583e21148ba63e1743
4
+ data.tar.gz: 2dd299e15e6a4701e15ff7fc04e95c733c72454bd718f15082315fada5db2e4a
5
5
  SHA512:
6
- metadata.gz: d1d0834a1dc76d2009dc1bd1bbd35c0fbcfc166e1b1206c87a3ba1fd7d8543c693d22550cd899129b41d9dcbf76d0a379ab7c0ef6a7d83e2ffa1960c0b8ec3a2
7
- data.tar.gz: 8715c42a9d55a3f491a860373c74dcda03351be2752a14e2dc798781f1ab807b55ff332822ead436637b1d479702920cbe9c19b6b30bff4844418acbe3d8611f
6
+ metadata.gz: 612b798a6f43d52b223c248e63298606fafe545caf2350633c9f24ec08b0f35de0a8459a560171b519a24972e39cc84c974b902c39c578adb680586cfc51f238
7
+ data.tar.gz: def3221fb65d2d545ee7b404725d173de31f444008dff5140fcbfe6e315d20574cba95f2e8f5a14ad580c3d180fc89022ec8827a51d1ad541df51a08964679fc
data/README.md CHANGED
@@ -37,6 +37,7 @@ touch ~foreman/tmp/restart.txt
37
37
  | >= 2.0 | ~> 2.0 |
38
38
  | >= 2.2 | ~> 2.1 |
39
39
  | >= 3.0 | ~> 3.0 |
40
+ | >= 3.6 | ~> 3.1 |
40
41
 
41
42
  # Usage
42
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
@@ -97,7 +97,8 @@ module ForemanMonitoring
97
97
  :comment => params[:downtime][:comment],
98
98
  :author => "Foreman User #{User.current}",
99
99
  :start_time => Time.zone.parse(params[:downtime][:starttime]).to_i,
100
- :end_time => Time.zone.parse(params[:downtime][:endtime]).to_i
100
+ :end_time => Time.zone.parse(params[:downtime][:endtime]).to_i,
101
+ **(params[:downtime][:all_services] == '1' ? { :all_services => true } : {})
101
102
  }
102
103
  end
103
104
 
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanMonitoring
4
+ module HostsHelper
5
+ def monitoring_hosts_multiple_actions
6
+ actions = []
7
+ actions << { action: [_('Set downtime'), select_multiple_downtime_hosts_path], priority: 1000 } \
8
+ if authorized_for(:controller => :hosts, :action => :select_multiple_downtime)
9
+ actions << { action: [_('Change Monitoring Proxy'), select_multiple_monitoring_proxy_hosts_path], priority: 1000 } \
10
+ if authorized_for(:controller => :hosts, :action => :select_multiple_monitoring_proxy)
11
+ actions
12
+ end
13
+
14
+ def host_title_actions(host)
15
+ title_actions(
16
+ button_group(
17
+ display_link_if_authorized(
18
+ _('Downtime'),
19
+ hash_for_host_path(:id => host).merge(
20
+ :auth_object => host,
21
+ :permission => :manage_downtime_hosts,
22
+ :anchor => 'set_host_downtime'
23
+ ),
24
+ :class => 'btn btn-default',
25
+ :disabled => !host.monitored?,
26
+ :title => _('Set a downtime for this host'),
27
+ :id => 'host-downtime',
28
+ :data => {
29
+ :toggle => 'modal',
30
+ :target => '#set_host_downtime',
31
+ }
32
+ )
33
+ )
34
+ )
35
+ super
36
+ end
37
+
38
+ def host_monitoring_result_icon_class(result)
39
+ icon_class = case result
40
+ when :ok
41
+ 'pficon-ok'
42
+ when :warning
43
+ 'pficon-info'
44
+ when :critical
45
+ 'pficon-error-circle-o'
46
+ else
47
+ 'pficon-help'
48
+ end
49
+
50
+ "host-status #{icon_class} #{host_monitoring_result_class(result)}"
51
+ end
52
+
53
+ def host_monitoring_result_class(result)
54
+ case result
55
+ when :ok
56
+ 'status-ok'
57
+ when :warning
58
+ 'status-warn'
59
+ when :critical
60
+ 'status-error'
61
+ else
62
+ 'status-question'
63
+ end
64
+ end
65
+
66
+ def monitoring_datetime_f(f, attr, options = {})
67
+ field(f, attr, options) do
68
+ addClass options, 'form-control'
69
+ f.datetime_field attr, options
70
+ end
71
+ end
72
+ end
73
+ end
@@ -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
 
@@ -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
 
@@ -1,3 +1,4 @@
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
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
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 %>
4
+ <%= checkbox_f f, :all_services, :size => "col-md-5", :label => _('All services'), :help_inline => _("Set downtime for all host's services.") %>
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
@@ -2,8 +2,6 @@
2
2
 
3
3
  class FixMonitoringSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4
4
  def up
5
- # rubocop:disable Rails/SkipsModelValidations
6
- Setting.where(category: 'Setting::Monitoring').update_all(category: 'Setting')
7
- # rubocop:enable Rails/SkipsModelValidations
5
+ Setting.where(category: 'Setting::Monitoring').update_all(category: 'Setting') if column_exists?(:settings, :category)
8
6
  end
9
7
  end
@@ -82,18 +82,19 @@ module ForemanMonitoring
82
82
  smart_proxy_for Hostgroup, :monitoring_proxy, monitoring_proxy_options
83
83
 
84
84
  add_controller_action_scope('HostsController', :index) { |base_scope| base_scope.includes(:monitoring_proxy) }
85
+
86
+ describe_host do
87
+ multiple_actions_provider :monitoring_hosts_multiple_actions
88
+ end
85
89
  end
86
90
  end
87
91
 
88
92
  config.to_prepare do
89
- begin
90
- ::Host::Managed.prepend(ForemanMonitoring::HostExtensions)
91
- ::Hostgroup.include(ForemanMonitoring::HostgroupExtensions)
92
- ::HostsHelper.prepend(ForemanMonitoring::HostsHelperExt)
93
- ::HostsController.prepend(ForemanMonitoring::HostsControllerExtensions)
94
- rescue StandardError => e
95
- Rails.logger.warn "ForemanMonitoring: skipping engine hook (#{e})"
96
- end
93
+ ::Host::Managed.prepend(ForemanMonitoring::HostExtensions)
94
+ ::Hostgroup.include(ForemanMonitoring::HostgroupExtensions)
95
+ ::HostsController.prepend(ForemanMonitoring::HostsControllerExtensions)
96
+ rescue StandardError => e
97
+ Rails.logger.warn "ForemanMonitoring: skipping engine hook (#{e})"
97
98
  end
98
99
 
99
100
  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 = '3.0.0'
4
+ VERSION = '3.2.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 }
@@ -61,7 +61,7 @@ class HostTest < ActiveSupport::TestCase
61
61
  ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns(fake_host_query_result)
62
62
  assert_valid host
63
63
  tasks = host.queue.all.map(&:name)
64
- assert_equal [], tasks
64
+ assert_empty tasks
65
65
  end
66
66
 
67
67
  test 'should queue monitoring destroy' do
@@ -83,7 +83,7 @@ class HostTest < ActiveSupport::TestCase
83
83
  test 'should not queue monitoring create actions' do
84
84
  assert_valid host
85
85
  tasks = host.queue.all.map(&:name)
86
- assert_equal [], tasks
86
+ assert_empty tasks
87
87
  end
88
88
 
89
89
  test 'should queue monitoring downtime on host destroy' do
@@ -134,7 +134,7 @@ class HostTest < ActiveSupport::TestCase
134
134
  host.send(:queue_monitoring)
135
135
  host.send(:queue_monitoring_destroy)
136
136
  tasks = host.queue.all.map(&:name)
137
- assert_equal [], tasks
137
+ assert_empty tasks
138
138
  end
139
139
  end
140
140
  end
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: 3.0.0
4
+ version: 3.2.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: 2022-11-02 00:00:00.000000000 Z
11
+ date: 2024-05-31 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
@@ -108,7 +52,7 @@ files:
108
52
  - app/controllers/api/v2/monitoring_results_controller.rb
109
53
  - app/controllers/concerns/foreman_monitoring/find_host_by_client_cert.rb
110
54
  - app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb
111
- - app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb
55
+ - app/helpers/foreman_monitoring/hosts_helper.rb
112
56
  - app/lib/proxy_api/monitoring.rb
113
57
  - app/models/concerns/foreman_monitoring/host_extensions.rb
114
58
  - app/models/concerns/foreman_monitoring/hostgroup_extensions.rb
@@ -164,14 +108,17 @@ 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.2.33
121
+ rubygems_version: 3.2.3
175
122
  signing_key:
176
123
  specification_version: 4
177
124
  summary: Foreman plugin for monitoring system integration.
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ForemanMonitoring
4
- module HostsHelperExt
5
- def multiple_actions
6
- actions = super
7
- actions << [_('Set downtime'), select_multiple_downtime_hosts_path] if authorized_for(:controller => :hosts, :action => :select_multiple_downtime)
8
- actions << [_('Change Monitoring Proxy'), select_multiple_monitoring_proxy_hosts_path] if authorized_for(:controller => :hosts, :action => :select_multiple_monitoring_proxy)
9
- actions
10
- end
11
-
12
- def host_title_actions(host)
13
- title_actions(
14
- button_group(
15
- display_link_if_authorized(_('Downtime'),
16
- hash_for_host_path(:id => host).merge(:auth_object => host,
17
- :permission => :manage_downtime_hosts,
18
- :anchor => 'set_host_downtime'),
19
- :class => 'btn btn-default',
20
- :disabled => !host.monitored?,
21
- :title => _('Set a downtime for this host'),
22
- :id => 'host-downtime',
23
- :data => { :toggle => 'modal',
24
- :target => '#set_host_downtime' })
25
- )
26
- )
27
- super
28
- end
29
-
30
- def host_monitoring_result_icon_class(result)
31
- icon_class = case result
32
- when :ok
33
- 'pficon-ok'
34
- when :warning
35
- 'pficon-info'
36
- when :critical
37
- 'pficon-error-circle-o'
38
- else
39
- 'pficon-help'
40
- end
41
-
42
- "host-status #{icon_class} #{host_monitoring_result_class(result)}"
43
- end
44
-
45
- def host_monitoring_result_class(result)
46
- case result
47
- when :ok
48
- 'status-ok'
49
- when :warning
50
- 'status-warn'
51
- when :critical
52
- 'status-error'
53
- else
54
- 'status-question'
55
- end
56
- end
57
-
58
- def monitoring_datetime_f(f, attr, options = {})
59
- field(f, attr, options) do
60
- addClass options, 'form-control'
61
- f.datetime_field attr, options
62
- end
63
- end
64
- end
65
- end