foreman_icinga 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/LICENSE +619 -0
- data/README.md +35 -0
- data/Rakefile +47 -0
- data/app/models/concerns/foreman_icinga/host_extensions.rb +11 -4
- data/app/models/host_status/icinga_status.rb +8 -3
- data/app/models/setting/icinga.rb +30 -33
- data/app/services/icinga.rb +5 -1
- data/lib/foreman_icinga.rb +2 -1
- data/lib/foreman_icinga/engine.rb +19 -7
- data/lib/foreman_icinga/version.rb +3 -0
- data/lib/tasks/foreman_icinga_tasks.rake +39 -0
- data/locale/Makefile +62 -0
- data/locale/en/foreman_icinga.po +19 -0
- data/locale/foreman_icinga.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/test_plugin_helper.rb +20 -0
- data/test/unit/concerns/host_extensions_test.rb +63 -0
- data/test/unit/host_status/icinga_status_test.rb +45 -0
- data/test/unit/icinga_test.rb +45 -0
- metadata +66 -7
data/locale/gemspec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This calls the main test_helper in Foreman-core
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
# Add plugin to FactoryGirl's paths
|
5
|
+
FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
6
|
+
FactoryGirl.reload
|
7
|
+
|
8
|
+
def setup_default_settings
|
9
|
+
mock_icinga_setting :icinga_address, 'http://example.com/'
|
10
|
+
mock_icinga_setting :icinga_token, '123456'
|
11
|
+
mock_icinga_setting :icinga_enabled, true
|
12
|
+
mock_icinga_setting :icinga_ignore_failed_action, false
|
13
|
+
end
|
14
|
+
|
15
|
+
def mock_icinga_setting(name, value)
|
16
|
+
FactoryGirl.create(:setting,
|
17
|
+
:name => name.to_s,
|
18
|
+
:value => value,
|
19
|
+
:category => 'Setting::Icinga')
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class IcingaHostExtensionsTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryGirl.build(:user, :admin)
|
6
|
+
setup_default_settings
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when icinga is configured and enabled' do
|
10
|
+
setup do
|
11
|
+
Setting[:icinga_enabled] = true
|
12
|
+
Setting[:icinga_ignore_failed_action] = false
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'it should be configured and enabled' do
|
16
|
+
host = Host.new
|
17
|
+
assert host.send(:icinga_configured?)
|
18
|
+
assert host.send(:icinga_enabled?)
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'it should set a downtime when host is deleted' do
|
22
|
+
host = FactoryGirl.create(:host)
|
23
|
+
mock_successful_icinga_result
|
24
|
+
assert host.destroy
|
25
|
+
assert_empty host.errors
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'it should not delete host and add errors when icinga_ignore_failed_action is false' do
|
29
|
+
host = FactoryGirl.create(:host)
|
30
|
+
mock_failed_icinga_result
|
31
|
+
refute host.destroy
|
32
|
+
assert_includes host.errors[:base], 'Error from Icinga server: \'A random error occured.\''
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'it should delete host add no errors when icinga_ignore_failed_action is true' do
|
36
|
+
Setting[:icinga_ignore_failed_action] = true
|
37
|
+
host = FactoryGirl.create(:host)
|
38
|
+
mock_failed_icinga_result
|
39
|
+
assert host.destroy
|
40
|
+
assert_empty host.errors
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def mock_successful_icinga_result
|
45
|
+
icinga_result = {
|
46
|
+
'success' => true,
|
47
|
+
'host' => 'localhost',
|
48
|
+
'downtime_comment' => 'deployment',
|
49
|
+
'downtime_duration' => 1200,
|
50
|
+
'downtime_start' => 1427989338,
|
51
|
+
'downtime_end' => 1427990238
|
52
|
+
}
|
53
|
+
Icinga.any_instance.expects(:call).once.returns(icinga_result)
|
54
|
+
end
|
55
|
+
|
56
|
+
def mock_failed_icinga_result
|
57
|
+
icinga_result = {
|
58
|
+
'status' => 'error',
|
59
|
+
'message' => 'A random error occured.',
|
60
|
+
}
|
61
|
+
Icinga.any_instance.expects(:call).once.returns(icinga_result)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class IcingaStatusTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@host = FactoryGirl.create(:host)
|
6
|
+
@status = HostStatus::IcingaStatus.new(:host => @host)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'is valid' do
|
10
|
+
assert_valid @status
|
11
|
+
end
|
12
|
+
|
13
|
+
test '#relevant? is only for hosts not in build mode' do
|
14
|
+
@host.build = false
|
15
|
+
assert @status.relevant?
|
16
|
+
|
17
|
+
@host.build = true
|
18
|
+
refute @status.relevant?
|
19
|
+
end
|
20
|
+
|
21
|
+
test '#to_label returns string representation of status code' do
|
22
|
+
assert_kind_of String, @status.to_label
|
23
|
+
end
|
24
|
+
|
25
|
+
test '#to_global returns global OK when disabled by setting' do
|
26
|
+
mock_icinga_setting :icinga_affect_global_status, false
|
27
|
+
@status.status = HostStatus::IcingaStatus::WARNING
|
28
|
+
assert_equal HostStatus::Global::OK, @status.to_global
|
29
|
+
end
|
30
|
+
|
31
|
+
test '#to_global returns correct global status' do
|
32
|
+
mock_icinga_setting :icinga_affect_global_status, true
|
33
|
+
@status.status = HostStatus::IcingaStatus::OK
|
34
|
+
assert_equal HostStatus::Global::OK, @status.to_global
|
35
|
+
|
36
|
+
@status.status = HostStatus::IcingaStatus::WARNING
|
37
|
+
assert_equal HostStatus::Global::WARN, @status.to_global
|
38
|
+
|
39
|
+
@status.status = HostStatus::IcingaStatus::CRITICAL
|
40
|
+
assert_equal HostStatus::Global::ERROR, @status.to_global
|
41
|
+
|
42
|
+
@status.status = HostStatus::IcingaStatus::UNKNOWN
|
43
|
+
assert_equal HostStatus::Global::OK, @status.to_global
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class IcingaTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
setup_default_settings
|
6
|
+
@icinga = Icinga.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test '#default_params should contain token' do
|
10
|
+
default_params = @icinga.send('default_params')
|
11
|
+
assert_kind_of Hash, default_params
|
12
|
+
assert_equal '123456', default_params['token']
|
13
|
+
end
|
14
|
+
|
15
|
+
test '#icinga_url_for should return valid urls' do
|
16
|
+
assert_equal 'http://example.com/test/bla',
|
17
|
+
@icinga.send('icinga_url_for', 'test/bla')
|
18
|
+
assert_equal 'http://example.com/test/blubb?param=1',
|
19
|
+
@icinga.send('icinga_url_for', 'test/blubb', 'param' => '1')
|
20
|
+
end
|
21
|
+
|
22
|
+
def fake_response(data)
|
23
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
24
|
+
RestClient::Response.create(data, net_http_resp, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'should correctly parse response' do
|
28
|
+
@icinga.expects(:post)
|
29
|
+
.with('http://example.com/health?host=example.com&json=true&token=123456', '')
|
30
|
+
.returns(fake_response(JSON('healthy' => 'true')))
|
31
|
+
response = @icinga.call('health', '', 'host' => 'example.com')
|
32
|
+
assert_kind_of Hash, response
|
33
|
+
assert response['healthy']
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'should return error message when result is empty' do
|
37
|
+
@icinga.expects(:post)
|
38
|
+
.with('http://example.com/health?host=example.com&json=true&token=123456', '')
|
39
|
+
.returns(fake_response(''))
|
40
|
+
response = @icinga.call('health', '', 'host' => 'example.com')
|
41
|
+
assert_kind_of Hash, response
|
42
|
+
assert_equal 'error', response['status']
|
43
|
+
assert_equal 'received empty result', response['message']
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,67 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_icinga
|
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: 2015-12-
|
12
|
-
dependencies:
|
11
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: rubocop
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
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'
|
13
55
|
description: Set a downtime for hosts after they are deleted in Foreman.
|
14
|
-
email:
|
56
|
+
email:
|
57
|
+
- timo.goebel@dm.de
|
15
58
|
executables: []
|
16
59
|
extensions: []
|
17
60
|
extra_rdoc_files: []
|
18
61
|
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
19
65
|
- app/helpers/concerns/foreman_icinga/hosts_helper_ext.rb
|
20
66
|
- app/models/concerns/foreman_icinga/host_extensions.rb
|
21
67
|
- app/models/host_status/icinga_status.rb
|
@@ -23,9 +69,18 @@ files:
|
|
23
69
|
- app/services/icinga.rb
|
24
70
|
- lib/foreman_icinga.rb
|
25
71
|
- lib/foreman_icinga/engine.rb
|
72
|
+
- lib/foreman_icinga/version.rb
|
73
|
+
- lib/tasks/foreman_icinga_tasks.rake
|
74
|
+
- locale/Makefile
|
75
|
+
- locale/en/foreman_icinga.po
|
76
|
+
- locale/foreman_icinga.pot
|
77
|
+
- locale/gemspec.rb
|
78
|
+
- test/test_plugin_helper.rb
|
79
|
+
- test/unit/concerns/host_extensions_test.rb
|
80
|
+
- test/unit/host_status/icinga_status_test.rb
|
81
|
+
- test/unit/icinga_test.rb
|
26
82
|
homepage: http://www.github.com/FILIADATAGmbH/foreman_icinga
|
27
|
-
licenses:
|
28
|
-
- GPL-3.0
|
83
|
+
licenses: []
|
29
84
|
metadata: {}
|
30
85
|
post_install_message:
|
31
86
|
rdoc_options: []
|
@@ -47,5 +102,9 @@ rubygems_version: 2.4.5
|
|
47
102
|
signing_key:
|
48
103
|
specification_version: 4
|
49
104
|
summary: This is a foreman plugin to interact with icingaweb2 deployment module.
|
50
|
-
test_files:
|
105
|
+
test_files:
|
106
|
+
- test/test_plugin_helper.rb
|
107
|
+
- test/unit/concerns/host_extensions_test.rb
|
108
|
+
- test/unit/host_status/icinga_status_test.rb
|
109
|
+
- test/unit/icinga_test.rb
|
51
110
|
has_rdoc:
|