foreman_monitoring 0.1.2 → 2.1.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 +4 -4
- data/README.md +16 -7
- data/Rakefile +0 -0
- data/app/controllers/api/v2/downtime_controller.rb +63 -0
- data/app/controllers/api/v2/monitoring_results_controller.rb +5 -4
- data/app/controllers/concerns/foreman_monitoring/find_host_by_client_cert.rb +60 -0
- data/app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb +21 -20
- data/app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb +16 -19
- data/app/lib/proxy_api/monitoring.rb +9 -6
- data/app/models/concerns/foreman_monitoring/host_extensions.rb +15 -14
- data/app/models/concerns/foreman_monitoring/hostgroup_extensions.rb +7 -3
- data/app/models/concerns/orchestration/monitoring.rb +22 -15
- data/app/models/host_status/monitoring_status.rb +7 -4
- data/app/models/monitoring_result.rb +13 -6
- data/app/models/setting/monitoring.rb +4 -2
- data/app/overrides/add_host_monitoring_result_tab.rb +8 -6
- data/app/overrides/add_host_multiple_power_set_downtime_checkbox.rb +5 -3
- data/app/overrides/add_host_set_downtime_modal.rb +4 -2
- data/app/services/monitoring.rb +3 -0
- data/app/views/hosts/_downtime_fields.html.erb +2 -2
- data/app/views/monitoring_results/_host_tab_pane.html.erb +2 -2
- data/config/routes.rb +3 -0
- data/db/migrate/20160817135723_create_monitoring_results.rb +5 -1
- data/db/migrate/20161220201510_add_monitoring_proxy_id_to_host_and_hostgroup.rb +3 -1
- data/db/migrate/201910180900_rename_downtime_host_permission.rb +15 -0
- data/db/seeds.d/60-monitoring_proxy_feature.rb +2 -0
- data/lib/foreman_monitoring.rb +2 -0
- data/lib/foreman_monitoring/engine.rb +32 -28
- data/lib/foreman_monitoring/version.rb +3 -1
- data/lib/tasks/foreman_monitoring_tasks.rake +5 -5
- data/locale/gemspec.rb +2 -0
- data/test/controllers/api/v2/downtime_controller_test.rb +73 -0
- data/test/factories/feature.rb +4 -2
- data/test/factories/host.rb +6 -4
- data/test/factories/monitoring_results.rb +9 -7
- data/test/factories/smart_proxy.rb +3 -1
- data/test/functional/hosts_controller_test.rb +65 -52
- data/test/lib/proxy_api/monitoring_test.rb +16 -14
- data/test/test_plugin_helper.rb +5 -3
- data/test/unit/host_status/monitoring_status_test.rb +18 -16
- data/test/unit/host_test.rb +6 -4
- data/test/unit/monitoring_result_test.rb +75 -0
- data/test/unit/monitoring_test.rb +5 -3
- metadata +62 -14
data/test/test_plugin_helper.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This calls the main test_helper in Foreman-core
|
2
4
|
require 'test_helper'
|
3
5
|
require 'database_cleaner'
|
4
6
|
|
5
|
-
# Add plugin to
|
6
|
-
|
7
|
-
|
7
|
+
# Add plugin to FactoryBot's paths
|
8
|
+
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
9
|
+
FactoryBot.reload
|
8
10
|
|
9
11
|
# Foreman's setup doesn't handle cleaning up for Minitest::Spec
|
10
12
|
DatabaseCleaner.strategy = :transaction
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class MonitoringStatusTest < ActiveSupport::TestCase
|
@@ -6,62 +8,62 @@ class MonitoringStatusTest < ActiveSupport::TestCase
|
|
6
8
|
disable_monitoring_orchestration
|
7
9
|
end
|
8
10
|
|
9
|
-
let(:host) {
|
11
|
+
let(:host) { FactoryBot.create(:host, :with_monitoring) }
|
10
12
|
let(:status) { HostStatus::MonitoringStatus.new(:host => host) }
|
11
13
|
|
12
14
|
context 'status changes' do
|
13
15
|
test '#to_status should change when monitoring results change' do
|
14
|
-
|
16
|
+
FactoryBot.create(:monitoring_result, :ok, :host => host)
|
15
17
|
assert_equal HostStatus::MonitoringStatus::OK, status.to_status
|
16
18
|
|
17
|
-
|
19
|
+
FactoryBot.create(:monitoring_result, :warning, :host => host)
|
18
20
|
assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
|
19
21
|
|
20
|
-
|
22
|
+
FactoryBot.create(:monitoring_result, :unknown, :host => host)
|
21
23
|
assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
|
22
24
|
|
23
|
-
|
25
|
+
FactoryBot.create(:monitoring_result, :critical, :host => host)
|
24
26
|
assert_equal HostStatus::MonitoringStatus::CRITICAL, status.to_status
|
25
27
|
end
|
26
28
|
|
27
29
|
test '#to_status should be warning with critical acknowledged' do
|
28
|
-
|
30
|
+
FactoryBot.create(:monitoring_result, :critical, :acknowledged, :host => host)
|
29
31
|
assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
|
30
32
|
end
|
31
33
|
|
32
34
|
test '#to_status should be ok with critical in downtime' do
|
33
|
-
|
35
|
+
FactoryBot.create(:monitoring_result, :critical, :downtime, :host => host)
|
34
36
|
assert_equal HostStatus::MonitoringStatus::OK, status.to_status
|
35
37
|
end
|
36
38
|
|
37
39
|
test '#to_global should change when monitoring results change' do
|
38
|
-
|
40
|
+
FactoryBot.create(:monitoring_result, :ok, :host => host)
|
39
41
|
status.refresh
|
40
42
|
assert_equal HostStatus::Global::OK, status.to_global
|
41
43
|
|
42
|
-
|
44
|
+
FactoryBot.create(:monitoring_result, :warning, :host => host)
|
43
45
|
status.refresh
|
44
46
|
assert_equal HostStatus::Global::WARN, status.to_global
|
45
47
|
|
46
|
-
|
48
|
+
FactoryBot.create(:monitoring_result, :unknown, :host => host)
|
47
49
|
status.refresh
|
48
50
|
assert_equal HostStatus::Global::WARN, status.to_global
|
49
51
|
|
50
|
-
|
52
|
+
FactoryBot.create(:monitoring_result, :critical, :host => host)
|
51
53
|
status.refresh
|
52
54
|
assert_equal HostStatus::Global::ERROR, status.to_global
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
58
|
context 'status with host with monitoring results' do
|
57
|
-
let(:host) {
|
59
|
+
let(:host) { FactoryBot.create(:host, :with_monitoring, :with_monitoring_results) }
|
58
60
|
|
59
61
|
test '#relevant? is only for hosts not in build mode' do
|
60
62
|
host.build = false
|
61
63
|
assert status.relevant?
|
62
64
|
|
63
65
|
host.build = true
|
64
|
-
|
66
|
+
assert_not status.relevant?
|
65
67
|
end
|
66
68
|
|
67
69
|
test '#host_known_in_monitoring? should be true' do
|
@@ -76,10 +78,10 @@ class MonitoringStatusTest < ActiveSupport::TestCase
|
|
76
78
|
context 'status with host without monitoring results' do
|
77
79
|
test '#relevant? is always false when build changes' do
|
78
80
|
host.build = false
|
79
|
-
|
81
|
+
assert_not status.relevant?
|
80
82
|
|
81
83
|
host.build = true
|
82
|
-
|
84
|
+
assert_not status.relevant?
|
83
85
|
end
|
84
86
|
|
85
87
|
test '#refresh! refreshes the date and persists the record' do
|
@@ -90,7 +92,7 @@ class MonitoringStatusTest < ActiveSupport::TestCase
|
|
90
92
|
end
|
91
93
|
|
92
94
|
test '#host_known_in_monitoring? should be false' do
|
93
|
-
|
95
|
+
assert_not status.host_known_in_monitoring?
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
data/test/unit/host_test.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class HostTest < ActiveSupport::TestCase
|
4
6
|
setup do
|
5
|
-
User.current =
|
7
|
+
User.current = FactoryBot.build(:user, :admin)
|
6
8
|
setup_settings
|
7
9
|
disable_orchestration
|
8
10
|
disable_monitoring_orchestration
|
9
11
|
end
|
10
12
|
|
11
13
|
context 'downtime handling' do
|
12
|
-
let(:host) {
|
14
|
+
let(:host) { FactoryBot.create(:host, :managed) }
|
13
15
|
|
14
16
|
test 'it should set a downtime when build status changes' do
|
15
17
|
host.expects(:downtime_host).once
|
@@ -22,7 +24,7 @@ class HostTest < ActiveSupport::TestCase
|
|
22
24
|
end
|
23
25
|
|
24
26
|
context 'a host with monitoring orchestration' do
|
25
|
-
let(:host) {
|
27
|
+
let(:host) { FactoryBot.build(:host, :managed, :with_monitoring) }
|
26
28
|
|
27
29
|
context 'with create/delete actions' do
|
28
30
|
setup do
|
@@ -125,7 +127,7 @@ class HostTest < ActiveSupport::TestCase
|
|
125
127
|
end
|
126
128
|
|
127
129
|
context 'a host without monitoring' do
|
128
|
-
let(:host) {
|
130
|
+
let(:host) { FactoryBot.build(:host, :managed) }
|
129
131
|
|
130
132
|
test 'should not queue any monitoring actions' do
|
131
133
|
assert_valid host
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
class MonitoringResultTest < ActiveSupport::TestCase
|
6
|
+
setup do
|
7
|
+
User.current = FactoryBot.build(:user, :admin)
|
8
|
+
setup_settings
|
9
|
+
disable_orchestration
|
10
|
+
disable_monitoring_orchestration
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#import' do
|
14
|
+
let(:host) { FactoryBot.create(:host, :managed, :with_monitoring) }
|
15
|
+
|
16
|
+
let(:initial) do
|
17
|
+
{
|
18
|
+
host: host.name,
|
19
|
+
service: 'cpu metrics',
|
20
|
+
timestamp: 1_516_365_380.8834700584,
|
21
|
+
result: 1,
|
22
|
+
acknowledged: true
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:acknowledegment_cleared) do
|
27
|
+
{
|
28
|
+
host: host.name,
|
29
|
+
service: 'cpu metrics',
|
30
|
+
timestamp: 1_516_365_971.2455039024,
|
31
|
+
acknowledged: false
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:state_change) do
|
36
|
+
{
|
37
|
+
host: host.name,
|
38
|
+
service: 'cpu metrics',
|
39
|
+
timestamp: 1_516_365_971.2461779118,
|
40
|
+
result: 0
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'imports a monitoring result' do
|
45
|
+
MonitoringResult.import(initial)
|
46
|
+
imported = host.monitoring_results.last
|
47
|
+
assert_equal true, imported.acknowledged?
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'handles ack and state change in correct order' do
|
51
|
+
MonitoringResult.import(initial)
|
52
|
+
MonitoringResult.import(acknowledegment_cleared)
|
53
|
+
MonitoringResult.import(state_change)
|
54
|
+
imported = host.monitoring_results.last
|
55
|
+
assert_equal :ok, imported.status
|
56
|
+
assert_equal false, imported.acknowledged?
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'handles ack and state change in reverse order' do
|
60
|
+
MonitoringResult.import(initial)
|
61
|
+
MonitoringResult.import(state_change)
|
62
|
+
MonitoringResult.import(acknowledegment_cleared)
|
63
|
+
imported = host.monitoring_results.last
|
64
|
+
assert_equal :ok, imported.status
|
65
|
+
assert_equal false, imported.acknowledged?
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'ignores old data' do
|
69
|
+
MonitoringResult.import(state_change)
|
70
|
+
MonitoringResult.import(initial)
|
71
|
+
imported = host.monitoring_results.last
|
72
|
+
assert_equal false, imported.acknowledged?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class MonitoringTest < ActiveSupport::TestCase
|
4
6
|
setup do
|
5
|
-
User.current =
|
7
|
+
User.current = FactoryBot.build(:user, :admin)
|
6
8
|
setup_settings
|
7
9
|
disable_monitoring_orchestration
|
8
10
|
end
|
9
11
|
|
10
|
-
let(:monitoring_proxy) {
|
11
|
-
let(:host) {
|
12
|
+
let(:monitoring_proxy) { FactoryBot.create(:smart_proxy, :monitoring) }
|
13
|
+
let(:host) { FactoryBot.create(:host, :managed, :with_monitoring, :monitoring_proxy => monitoring_proxy) }
|
12
14
|
let(:monitoring) { Monitoring.new(:monitoring_proxy => monitoring_proxy) }
|
13
15
|
|
14
16
|
test '#set_downtime_host should call proxy api' do
|
metadata
CHANGED
@@ -1,31 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_monitoring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.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:
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rubocop
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- -
|
31
|
+
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
33
|
+
version: 0.80.0
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- -
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
40
|
+
version: 0.80.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
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
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
73
|
- - ">="
|
@@ -62,7 +104,9 @@ files:
|
|
62
104
|
- LICENSE
|
63
105
|
- README.md
|
64
106
|
- Rakefile
|
107
|
+
- app/controllers/api/v2/downtime_controller.rb
|
65
108
|
- app/controllers/api/v2/monitoring_results_controller.rb
|
109
|
+
- app/controllers/concerns/foreman_monitoring/find_host_by_client_cert.rb
|
66
110
|
- app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb
|
67
111
|
- app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb
|
68
112
|
- app/lib/proxy_api/monitoring.rb
|
@@ -86,6 +130,7 @@ files:
|
|
86
130
|
- config/routes.rb
|
87
131
|
- db/migrate/20160817135723_create_monitoring_results.rb
|
88
132
|
- db/migrate/20161220201510_add_monitoring_proxy_id_to_host_and_hostgroup.rb
|
133
|
+
- db/migrate/201910180900_rename_downtime_host_permission.rb
|
89
134
|
- db/seeds.d/60-monitoring_proxy_feature.rb
|
90
135
|
- lib/foreman_monitoring.rb
|
91
136
|
- lib/foreman_monitoring/engine.rb
|
@@ -95,6 +140,7 @@ files:
|
|
95
140
|
- locale/en/foreman_monitoring.po
|
96
141
|
- locale/foreman_monitoring.pot
|
97
142
|
- locale/gemspec.rb
|
143
|
+
- test/controllers/api/v2/downtime_controller_test.rb
|
98
144
|
- test/factories/feature.rb
|
99
145
|
- test/factories/host.rb
|
100
146
|
- test/factories/monitoring_results.rb
|
@@ -104,10 +150,11 @@ files:
|
|
104
150
|
- test/test_plugin_helper.rb
|
105
151
|
- test/unit/host_status/monitoring_status_test.rb
|
106
152
|
- test/unit/host_test.rb
|
153
|
+
- test/unit/monitoring_result_test.rb
|
107
154
|
- test/unit/monitoring_test.rb
|
108
|
-
homepage:
|
155
|
+
homepage: https://github.com/theforeman/foreman_monitoring
|
109
156
|
licenses:
|
110
|
-
-
|
157
|
+
- GPL-3.0
|
111
158
|
metadata: {}
|
112
159
|
post_install_message:
|
113
160
|
rdoc_options: []
|
@@ -124,19 +171,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
171
|
- !ruby/object:Gem::Version
|
125
172
|
version: '0'
|
126
173
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.7.3
|
174
|
+
rubygems_version: 3.0.3
|
129
175
|
signing_key:
|
130
176
|
specification_version: 4
|
131
177
|
summary: Foreman plugin for monitoring system integration.
|
132
178
|
test_files:
|
133
|
-
- test/factories/feature.rb
|
134
179
|
- test/factories/host.rb
|
135
180
|
- test/factories/monitoring_results.rb
|
136
181
|
- test/factories/smart_proxy.rb
|
137
|
-
- test/
|
182
|
+
- test/factories/feature.rb
|
138
183
|
- test/lib/proxy_api/monitoring_test.rb
|
184
|
+
- test/functional/hosts_controller_test.rb
|
185
|
+
- test/controllers/api/v2/downtime_controller_test.rb
|
139
186
|
- test/test_plugin_helper.rb
|
140
|
-
- test/unit/
|
187
|
+
- test/unit/monitoring_result_test.rb
|
141
188
|
- test/unit/host_test.rb
|
142
189
|
- test/unit/monitoring_test.rb
|
190
|
+
- test/unit/host_status/monitoring_status_test.rb
|