foreman_monitoring 0.0.3 → 0.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 +28 -1
- data/app/controllers/api/v2/monitoring_results_controller.rb +8 -0
- data/app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb +140 -0
- data/app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb +35 -11
- data/app/lib/proxy_api/monitoring.rb +35 -0
- data/app/models/concerns/foreman_monitoring/host_extensions.rb +48 -8
- data/app/models/concerns/foreman_monitoring/hostgroup_extensions.rb +15 -0
- data/app/models/concerns/orchestration/monitoring.rb +105 -0
- data/app/models/host_status/monitoring_status.rb +5 -1
- data/app/models/setting/monitoring.rb +23 -6
- data/app/overrides/add_host_multiple_power_set_downtime_checkbox.rb +5 -0
- data/app/overrides/add_host_set_downtime_modal.rb +5 -0
- data/app/services/monitoring.rb +56 -3
- data/app/views/hosts/_downtime_fields.html.erb +3 -0
- data/app/views/hosts/_host_downtime_checkbox.html.erb +8 -0
- data/app/views/hosts/_set_host_downtime.html.erb +20 -0
- data/app/views/hosts/select_multiple_downtime.html.erb +5 -0
- data/app/views/hosts/select_multiple_monitoring_proxy.html.erb +5 -0
- data/app/views/monitoring_results/_host_tab.html.erb +2 -0
- data/app/views/monitoring_results/_host_tab_pane.html.erb +2 -0
- data/config/routes.rb +16 -0
- data/db/migrate/20161220201510_add_monitoring_proxy_id_to_host_and_hostgroup.rb +11 -0
- data/lib/foreman_monitoring/engine.rb +35 -3
- data/lib/foreman_monitoring/version.rb +1 -1
- data/test/factories/host.rb +6 -0
- data/test/functional/hosts_controller_test.rb +190 -0
- data/test/lib/proxy_api/monitoring_test.rb +30 -0
- data/test/test_plugin_helper.rb +4 -0
- data/test/unit/host_status/monitoring_status_test.rb +7 -2
- data/test/unit/host_test.rb +111 -5
- data/test/unit/monitoring_test.rb +9 -3
- metadata +19 -6
@@ -19,4 +19,34 @@ class ProxyApiDhcpTest < ActiveSupport::TestCase
|
|
19
19
|
returns(fake_rest_client_response({ 'result' => {} }))
|
20
20
|
assert_equal({ 'result' => {} }, @monitoring.create_host_downtime('example.com'))
|
21
21
|
end
|
22
|
+
|
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' => {} }))
|
26
|
+
assert_equal({ 'result' => {} }, @monitoring.remove_host_downtime('example.com', :comment => 'bla'))
|
27
|
+
end
|
28
|
+
|
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' => {} }))
|
32
|
+
assert_equal({ 'result' => {} }, @monitoring.create_host('example.com', :ip => '1.1.1.1'))
|
33
|
+
end
|
34
|
+
|
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' => {} }))
|
38
|
+
assert_equal({ 'result' => {} }, @monitoring.update_host('example.com', :ip => '1.1.1.1'))
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'delete_host should do delete' do
|
42
|
+
@monitoring.expects(:delete).with('host/example.com').
|
43
|
+
returns(fake_rest_client_response({ 'result' => {} }))
|
44
|
+
assert_equal({ 'result' => {} }, @monitoring.delete_host('example.com'))
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'query_host should do get' do
|
48
|
+
@monitoring.expects(:get).with('host/example.com').
|
49
|
+
returns(fake_rest_client_response({ 'result' => {} }))
|
50
|
+
assert_equal({ 'result' => {} }, @monitoring.query_host('example.com'))
|
51
|
+
end
|
22
52
|
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -3,9 +3,10 @@ require 'test_plugin_helper'
|
|
3
3
|
class MonitoringStatusTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
5
|
setup_settings
|
6
|
+
disable_monitoring_orchestration
|
6
7
|
end
|
7
8
|
|
8
|
-
let(:host) { FactoryGirl.create(:host) }
|
9
|
+
let(:host) { FactoryGirl.create(:host, :with_monitoring) }
|
9
10
|
let(:status) { HostStatus::MonitoringStatus.new(:host => host) }
|
10
11
|
|
11
12
|
context 'status changes' do
|
@@ -53,7 +54,7 @@ class MonitoringStatusTest < ActiveSupport::TestCase
|
|
53
54
|
end
|
54
55
|
|
55
56
|
context 'status with host with monitoring results' do
|
56
|
-
let(:host) { FactoryGirl.create(:host, :with_monitoring_results) }
|
57
|
+
let(:host) { FactoryGirl.create(:host, :with_monitoring, :with_monitoring_results) }
|
57
58
|
|
58
59
|
test '#relevant? is only for hosts not in build mode' do
|
59
60
|
host.build = false
|
@@ -66,6 +67,10 @@ class MonitoringStatusTest < ActiveSupport::TestCase
|
|
66
67
|
test '#host_known_in_monitoring? should be true' do
|
67
68
|
assert status.host_known_in_monitoring?
|
68
69
|
end
|
70
|
+
|
71
|
+
test '#host_monitored? should be true' do
|
72
|
+
assert status.host_monitored?
|
73
|
+
end
|
69
74
|
end
|
70
75
|
|
71
76
|
context 'status with host without monitoring results' do
|
data/test/unit/host_test.rb
CHANGED
@@ -4,16 +4,13 @@ class HostTest < ActiveSupport::TestCase
|
|
4
4
|
setup do
|
5
5
|
User.current = FactoryGirl.build(:user, :admin)
|
6
6
|
setup_settings
|
7
|
+
disable_orchestration
|
8
|
+
disable_monitoring_orchestration
|
7
9
|
end
|
8
10
|
|
9
11
|
context 'downtime handling' do
|
10
12
|
let(:host) { FactoryGirl.create(:host, :managed) }
|
11
13
|
|
12
|
-
test 'it should set a downtime when host is deleted' do
|
13
|
-
host.expects(:downtime_host).once
|
14
|
-
assert host.destroy
|
15
|
-
end
|
16
|
-
|
17
14
|
test 'it should set a downtime when build status changes' do
|
18
15
|
host.expects(:downtime_host).once
|
19
16
|
|
@@ -23,4 +20,113 @@ class HostTest < ActiveSupport::TestCase
|
|
23
20
|
assert host.save
|
24
21
|
end
|
25
22
|
end
|
23
|
+
|
24
|
+
context 'a host with monitoring orchestration' do
|
25
|
+
let(:host) { FactoryGirl.build(:host, :managed, :with_monitoring) }
|
26
|
+
|
27
|
+
context 'with create/delete actions' do
|
28
|
+
setup do
|
29
|
+
Setting[:monitoring_create_action] = 'create'
|
30
|
+
Setting[:monitoring_delete_action] = 'delete'
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'should queue monitoring create' do
|
34
|
+
ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns(nil)
|
35
|
+
assert_valid host
|
36
|
+
tasks = host.queue.all.map(&:name)
|
37
|
+
assert_includes tasks, "Create monitoring object for #{host}"
|
38
|
+
assert_equal 1, tasks.size
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'should queue monitoring update' do
|
42
|
+
fake_host_query_result = {
|
43
|
+
'ip' => '1.1.1.1',
|
44
|
+
'ip6' => '2001:db8::1',
|
45
|
+
}
|
46
|
+
ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns(fake_host_query_result)
|
47
|
+
host.save
|
48
|
+
host.queue.clear
|
49
|
+
assert_valid host
|
50
|
+
tasks = host.queue.all.map(&:name)
|
51
|
+
assert_includes tasks, "Monitoring update for #{host}"
|
52
|
+
assert_equal 1, tasks.size
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'should not queue monitoring update' do
|
56
|
+
ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns({})
|
57
|
+
host.save
|
58
|
+
host.queue.clear
|
59
|
+
fake_host_query_result = host.monitoring_attributes
|
60
|
+
ProxyAPI::Monitoring.any_instance.stubs(:query_host).returns(fake_host_query_result)
|
61
|
+
assert_valid host
|
62
|
+
tasks = host.queue.all.map(&:name)
|
63
|
+
assert_equal [], tasks
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'should queue monitoring destroy' do
|
67
|
+
assert_valid host
|
68
|
+
host.queue.clear
|
69
|
+
host.send(:queue_monitoring_destroy)
|
70
|
+
tasks = host.queue.all.map(&:name)
|
71
|
+
assert_includes tasks, "Removing monitoring object for #{host}"
|
72
|
+
assert_equal 1, tasks.size
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with none/downtime actions' do
|
77
|
+
setup do
|
78
|
+
Setting[:monitoring_create_action] = 'none'
|
79
|
+
Setting[:monitoring_delete_action] = 'downtime'
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
test 'should not queue monitoring create actions' do
|
84
|
+
assert_valid host
|
85
|
+
tasks = host.queue.all.map(&:name)
|
86
|
+
assert_equal [], tasks
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'should queue monitoring downtime on host destroy' do
|
90
|
+
assert_valid host
|
91
|
+
host.queue.clear
|
92
|
+
host.send(:queue_monitoring_destroy)
|
93
|
+
tasks = host.queue.all.map(&:name)
|
94
|
+
assert_includes tasks, "Set monitoring downtime for #{host}"
|
95
|
+
assert_equal 1, tasks.size
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'setMonitoring' do
|
100
|
+
ProxyAPI::Monitoring.any_instance.expects(:create_host).once
|
101
|
+
host.send(:setMonitoring)
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'delMonitoring' do
|
105
|
+
ProxyAPI::Monitoring.any_instance.expects(:delete_host).once
|
106
|
+
host.send(:delMonitoring)
|
107
|
+
end
|
108
|
+
|
109
|
+
test 'setMonitoringDowntime' do
|
110
|
+
ProxyAPI::Monitoring.any_instance.expects(:create_host_downtime).once
|
111
|
+
host.send(:setMonitoringDowntime)
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'delMonitoringDowntime' do
|
115
|
+
ProxyAPI::Monitoring.any_instance.expects(:remove_host_downtime).once
|
116
|
+
host.send(:delMonitoringDowntime)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'a host without monitoring' do
|
121
|
+
let(:host) { FactoryGirl.build(:host, :managed) }
|
122
|
+
|
123
|
+
test 'should not queue any monitoring actions' do
|
124
|
+
assert_valid host
|
125
|
+
host.queue.clear
|
126
|
+
host.send(:queue_monitoring)
|
127
|
+
host.send(:queue_monitoring_destroy)
|
128
|
+
tasks = host.queue.all.map(&:name)
|
129
|
+
assert_equal [], tasks
|
130
|
+
end
|
131
|
+
end
|
26
132
|
end
|
@@ -4,14 +4,20 @@ class MonitoringTest < ActiveSupport::TestCase
|
|
4
4
|
setup do
|
5
5
|
User.current = FactoryGirl.build(:user, :admin)
|
6
6
|
setup_settings
|
7
|
-
|
7
|
+
disable_monitoring_orchestration
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:
|
11
|
-
let(:
|
10
|
+
let(:monitoring_proxy) { FactoryGirl.create(:smart_proxy, :monitoring) }
|
11
|
+
let(:host) { FactoryGirl.create(:host, :managed, :with_monitoring, :monitoring_proxy => monitoring_proxy) }
|
12
|
+
let(:monitoring) { Monitoring.new(:monitoring_proxy => monitoring_proxy) }
|
12
13
|
|
13
14
|
test '#set_downtime_host should call proxy api' do
|
14
15
|
ProxyAPI::Monitoring.any_instance.expects(:create_host_downtime).returns({}).once
|
15
16
|
monitoring.set_downtime_host(host)
|
16
17
|
end
|
18
|
+
|
19
|
+
test '#query_host should call proxy api' do
|
20
|
+
ProxyAPI::Monitoring.any_instance.expects(:query_host).returns({}).once
|
21
|
+
monitoring.query_host(host)
|
22
|
+
end
|
17
23
|
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: 0.0
|
4
|
+
version: 0.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: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -63,18 +63,29 @@ files:
|
|
63
63
|
- README.md
|
64
64
|
- Rakefile
|
65
65
|
- app/controllers/api/v2/monitoring_results_controller.rb
|
66
|
+
- app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb
|
66
67
|
- app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb
|
67
68
|
- app/lib/proxy_api/monitoring.rb
|
68
69
|
- app/models/concerns/foreman_monitoring/host_extensions.rb
|
70
|
+
- app/models/concerns/foreman_monitoring/hostgroup_extensions.rb
|
71
|
+
- app/models/concerns/orchestration/monitoring.rb
|
69
72
|
- app/models/host_status/monitoring_status.rb
|
70
73
|
- app/models/monitoring_result.rb
|
71
74
|
- app/models/setting/monitoring.rb
|
72
75
|
- app/overrides/add_host_monitoring_result_tab.rb
|
76
|
+
- app/overrides/add_host_multiple_power_set_downtime_checkbox.rb
|
77
|
+
- app/overrides/add_host_set_downtime_modal.rb
|
73
78
|
- app/services/monitoring.rb
|
79
|
+
- app/views/hosts/_downtime_fields.html.erb
|
80
|
+
- app/views/hosts/_host_downtime_checkbox.html.erb
|
81
|
+
- app/views/hosts/_set_host_downtime.html.erb
|
82
|
+
- app/views/hosts/select_multiple_downtime.html.erb
|
83
|
+
- app/views/hosts/select_multiple_monitoring_proxy.html.erb
|
74
84
|
- app/views/monitoring_results/_host_tab.html.erb
|
75
85
|
- app/views/monitoring_results/_host_tab_pane.html.erb
|
76
86
|
- config/routes.rb
|
77
87
|
- db/migrate/20160817135723_create_monitoring_results.rb
|
88
|
+
- db/migrate/20161220201510_add_monitoring_proxy_id_to_host_and_hostgroup.rb
|
78
89
|
- db/seeds.d/60-monitoring_proxy_feature.rb
|
79
90
|
- lib/foreman_monitoring.rb
|
80
91
|
- lib/foreman_monitoring/engine.rb
|
@@ -88,6 +99,7 @@ files:
|
|
88
99
|
- test/factories/host.rb
|
89
100
|
- test/factories/monitoring_results.rb
|
90
101
|
- test/factories/smart_proxy.rb
|
102
|
+
- test/functional/hosts_controller_test.rb
|
91
103
|
- test/lib/proxy_api/monitoring_test.rb
|
92
104
|
- test/test_plugin_helper.rb
|
93
105
|
- test/unit/host_status/monitoring_status_test.rb
|
@@ -113,17 +125,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
125
|
version: '0'
|
114
126
|
requirements: []
|
115
127
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.6.11
|
117
129
|
signing_key:
|
118
130
|
specification_version: 4
|
119
131
|
summary: Foreman plugin for monitoring system integration.
|
120
132
|
test_files:
|
133
|
+
- test/factories/feature.rb
|
134
|
+
- test/factories/host.rb
|
121
135
|
- test/factories/monitoring_results.rb
|
122
136
|
- test/factories/smart_proxy.rb
|
123
|
-
- test/
|
124
|
-
- test/factories/feature.rb
|
125
|
-
- test/test_plugin_helper.rb
|
137
|
+
- test/functional/hosts_controller_test.rb
|
126
138
|
- test/lib/proxy_api/monitoring_test.rb
|
139
|
+
- test/test_plugin_helper.rb
|
127
140
|
- test/unit/host_status/monitoring_status_test.rb
|
128
141
|
- test/unit/host_test.rb
|
129
142
|
- test/unit/monitoring_test.rb
|