foreman_monitoring 0.0.1
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 +7 -0
- data/LICENSE +619 -0
- data/README.md +31 -0
- data/Rakefile +47 -0
- data/app/controllers/api/v2/monitoring_results_controller.rb +29 -0
- data/app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb +46 -0
- data/app/lib/proxy_api/monitoring.rb +14 -0
- data/app/models/concerns/foreman_monitoring/host_extensions.rb +42 -0
- data/app/models/host_status/monitoring_status.rb +72 -0
- data/app/models/monitoring_result.rb +74 -0
- data/app/models/setting/monitoring.rb +16 -0
- data/app/overrides/add_host_monitoring_result_tab.rb +11 -0
- data/app/services/monitoring.rb +13 -0
- data/app/views/monitoring_results/_host_tab.html.erb +1 -0
- data/app/views/monitoring_results/_host_tab_pane.html.erb +25 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20160817135723_create_monitoring_results.rb +12 -0
- data/db/seeds.d/60-monitoring_proxy_feature.rb +2 -0
- data/lib/foreman_monitoring/engine.rb +51 -0
- data/lib/foreman_monitoring/version.rb +3 -0
- data/lib/foreman_monitoring.rb +4 -0
- data/lib/tasks/foreman_monitoring_tasks.rake +35 -0
- data/locale/Makefile +62 -0
- data/locale/en/foreman_monitoring.po +19 -0
- data/locale/foreman_monitoring.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/factories/feature.rb +7 -0
- data/test/factories/host.rb +14 -0
- data/test/factories/monitoring_results.rb +30 -0
- data/test/factories/smart_proxy.rb +7 -0
- data/test/lib/proxy_api/monitoring_test.rb +22 -0
- data/test/test_plugin_helper.rb +24 -0
- data/test/unit/host_status/monitoring_status_test.rb +91 -0
- data/test/unit/host_test.rb +26 -0
- data/test/unit/monitoring_test.rb +17 -0
- metadata +115 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :monitoring_result do
|
3
|
+
sequence(:service) { |n| "Service #{n}" }
|
4
|
+
result { rand(0..3) }
|
5
|
+
|
6
|
+
trait :ok do
|
7
|
+
result 0
|
8
|
+
end
|
9
|
+
|
10
|
+
trait :warning do
|
11
|
+
result 1
|
12
|
+
end
|
13
|
+
|
14
|
+
trait :critical do
|
15
|
+
result 2
|
16
|
+
end
|
17
|
+
|
18
|
+
trait :unknown do
|
19
|
+
result 3
|
20
|
+
end
|
21
|
+
|
22
|
+
trait :downtime do
|
23
|
+
downtime true
|
24
|
+
end
|
25
|
+
|
26
|
+
trait :acknowledged do
|
27
|
+
acknowledged true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ProxyApiDhcpTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
@url = 'http://localhost:8443'
|
6
|
+
@monitoring = ProxyAPI::Monitoring.new({ :url => @url })
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'constructor should complete' do
|
10
|
+
assert_not_nil @monitoring
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'base url should equal /monitoring' do
|
14
|
+
assert_equal "#{@url}/monitoring", @monitoring.url
|
15
|
+
end
|
16
|
+
|
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' => {} }))
|
20
|
+
assert_equal({ 'result' => {} }, @monitoring.create_host_downtime('example.com'))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This calls the main test_helper in Foreman-core
|
2
|
+
require 'test_helper'
|
3
|
+
require 'database_cleaner'
|
4
|
+
|
5
|
+
# Add plugin to FactoryGirl's paths
|
6
|
+
FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
7
|
+
FactoryGirl.reload
|
8
|
+
|
9
|
+
# Foreman's setup doesn't handle cleaning up for Minitest::Spec
|
10
|
+
DatabaseCleaner.strategy = :transaction
|
11
|
+
|
12
|
+
def setup_settings
|
13
|
+
Setting::Monitoring.load_defaults
|
14
|
+
end
|
15
|
+
|
16
|
+
class Minitest::Spec
|
17
|
+
before :each do
|
18
|
+
DatabaseCleaner.start
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
DatabaseCleaner.clean
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class MonitoringStatusTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
setup_settings
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:host) { FactoryGirl.create(:host) }
|
9
|
+
let(:status) { HostStatus::MonitoringStatus.new(:host => host) }
|
10
|
+
|
11
|
+
context 'status changes' do
|
12
|
+
test '#to_status should change when monitoring results change' do
|
13
|
+
FactoryGirl.create(:monitoring_result, :ok, :host => host)
|
14
|
+
assert_equal HostStatus::MonitoringStatus::OK, status.to_status
|
15
|
+
|
16
|
+
FactoryGirl.create(:monitoring_result, :warning, :host => host)
|
17
|
+
assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
|
18
|
+
|
19
|
+
FactoryGirl.create(:monitoring_result, :unknown, :host => host)
|
20
|
+
assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
|
21
|
+
|
22
|
+
FactoryGirl.create(:monitoring_result, :critical, :host => host)
|
23
|
+
assert_equal HostStatus::MonitoringStatus::CRITICAL, status.to_status
|
24
|
+
end
|
25
|
+
|
26
|
+
test '#to_status should be warning with critical acknowledged' do
|
27
|
+
FactoryGirl.create(:monitoring_result, :critical, :acknowledged, :host => host)
|
28
|
+
assert_equal HostStatus::MonitoringStatus::WARNING, status.to_status
|
29
|
+
end
|
30
|
+
|
31
|
+
test '#to_status should be ok with critical in downtime' do
|
32
|
+
FactoryGirl.create(:monitoring_result, :critical, :downtime, :host => host)
|
33
|
+
assert_equal HostStatus::MonitoringStatus::OK, status.to_status
|
34
|
+
end
|
35
|
+
|
36
|
+
test '#to_global should change when monitoring results change' do
|
37
|
+
FactoryGirl.create(:monitoring_result, :ok, :host => host)
|
38
|
+
status.refresh
|
39
|
+
assert_equal HostStatus::Global::OK, status.to_global
|
40
|
+
|
41
|
+
FactoryGirl.create(:monitoring_result, :warning, :host => host)
|
42
|
+
status.refresh
|
43
|
+
assert_equal HostStatus::Global::WARN, status.to_global
|
44
|
+
|
45
|
+
FactoryGirl.create(:monitoring_result, :unknown, :host => host)
|
46
|
+
status.refresh
|
47
|
+
assert_equal HostStatus::Global::WARN, status.to_global
|
48
|
+
|
49
|
+
FactoryGirl.create(:monitoring_result, :critical, :host => host)
|
50
|
+
status.refresh
|
51
|
+
assert_equal HostStatus::Global::ERROR, status.to_global
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'status with host with monitoring results' do
|
56
|
+
let(:host) { FactoryGirl.create(:host, :with_monitoring_results) }
|
57
|
+
|
58
|
+
test '#relevant? is only for hosts not in build mode' do
|
59
|
+
host.build = false
|
60
|
+
assert status.relevant?
|
61
|
+
|
62
|
+
host.build = true
|
63
|
+
refute status.relevant?
|
64
|
+
end
|
65
|
+
|
66
|
+
test '#host_known_in_monitoring? should be true' do
|
67
|
+
assert status.host_known_in_monitoring?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'status with host without monitoring results' do
|
72
|
+
test '#relevant? is always false when build changes' do
|
73
|
+
host.build = false
|
74
|
+
refute status.relevant?
|
75
|
+
|
76
|
+
host.build = true
|
77
|
+
refute status.relevant?
|
78
|
+
end
|
79
|
+
|
80
|
+
test '#refresh! refreshes the date and persists the record' do
|
81
|
+
status.expects(:refresh)
|
82
|
+
status.refresh!
|
83
|
+
|
84
|
+
assert status.persisted?
|
85
|
+
end
|
86
|
+
|
87
|
+
test '#host_known_in_monitoring? should be false' do
|
88
|
+
refute status.host_known_in_monitoring?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class HostTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryGirl.build(:user, :admin)
|
6
|
+
setup_settings
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'downtime handling' do
|
10
|
+
let(:host) { FactoryGirl.create(:host, :managed) }
|
11
|
+
|
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
|
+
test 'it should set a downtime when build status changes' do
|
18
|
+
host.expects(:downtime_host).once
|
19
|
+
|
20
|
+
host.build = false
|
21
|
+
assert host.save
|
22
|
+
host.build = true
|
23
|
+
assert host.save
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class MonitoringTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryGirl.build(:user, :admin)
|
6
|
+
setup_settings
|
7
|
+
@proxy = FactoryGirl.create(:smart_proxy, :monitoring)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:host) { FactoryGirl.create(:host, :managed) }
|
11
|
+
let(:monitoring) { Monitoring.new }
|
12
|
+
|
13
|
+
test '#set_downtime_host should call proxy api' do
|
14
|
+
ProxyAPI::Monitoring.any_instance.expects(:create_host_downtime).returns({}).once
|
15
|
+
monitoring.set_downtime_host(host)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman_monitoring
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timo Goebel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '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'
|
41
|
+
description: Foreman plugin for monitoring system integration.
|
42
|
+
email:
|
43
|
+
- timo.goebel@dm.de
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/controllers/api/v2/monitoring_results_controller.rb
|
52
|
+
- app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb
|
53
|
+
- app/lib/proxy_api/monitoring.rb
|
54
|
+
- app/models/concerns/foreman_monitoring/host_extensions.rb
|
55
|
+
- app/models/host_status/monitoring_status.rb
|
56
|
+
- app/models/monitoring_result.rb
|
57
|
+
- app/models/setting/monitoring.rb
|
58
|
+
- app/overrides/add_host_monitoring_result_tab.rb
|
59
|
+
- app/services/monitoring.rb
|
60
|
+
- app/views/monitoring_results/_host_tab.html.erb
|
61
|
+
- app/views/monitoring_results/_host_tab_pane.html.erb
|
62
|
+
- config/routes.rb
|
63
|
+
- db/migrate/20160817135723_create_monitoring_results.rb
|
64
|
+
- db/seeds.d/60-monitoring_proxy_feature.rb
|
65
|
+
- lib/foreman_monitoring.rb
|
66
|
+
- lib/foreman_monitoring/engine.rb
|
67
|
+
- lib/foreman_monitoring/version.rb
|
68
|
+
- lib/tasks/foreman_monitoring_tasks.rake
|
69
|
+
- locale/Makefile
|
70
|
+
- locale/en/foreman_monitoring.po
|
71
|
+
- locale/foreman_monitoring.pot
|
72
|
+
- locale/gemspec.rb
|
73
|
+
- test/factories/feature.rb
|
74
|
+
- test/factories/host.rb
|
75
|
+
- test/factories/monitoring_results.rb
|
76
|
+
- test/factories/smart_proxy.rb
|
77
|
+
- test/lib/proxy_api/monitoring_test.rb
|
78
|
+
- test/test_plugin_helper.rb
|
79
|
+
- test/unit/host_status/monitoring_status_test.rb
|
80
|
+
- test/unit/host_test.rb
|
81
|
+
- test/unit/monitoring_test.rb
|
82
|
+
homepage: http://www.github.com/theforeman/foreman_monitoring
|
83
|
+
licenses: []
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Foreman plugin for monitoring system integration.
|
105
|
+
test_files:
|
106
|
+
- test/factories/feature.rb
|
107
|
+
- test/factories/host.rb
|
108
|
+
- test/factories/monitoring_results.rb
|
109
|
+
- test/factories/smart_proxy.rb
|
110
|
+
- test/lib/proxy_api/monitoring_test.rb
|
111
|
+
- test/test_plugin_helper.rb
|
112
|
+
- test/unit/host_status/monitoring_status_test.rb
|
113
|
+
- test/unit/host_test.rb
|
114
|
+
- test/unit/monitoring_test.rb
|
115
|
+
has_rdoc:
|