foreman_icinga 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a19abcebbff33e10eb8dbe58e71d5577fda543dd
|
4
|
+
data.tar.gz: a239355f620a1e1b8a540424259e4e6309a76334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ba9da13812cfb4b1c1f287502a1ac85bbd20d73f3e9758b4de405524d9350ecd578447d5803c32e612b1eb97a430cc8aa53f508d6bed1162d120d0228b5dc78
|
7
|
+
data.tar.gz: 24c126884c8c83f289300aa272f500c9f9eb528c39e7a37543ddbaa5c9904066951877cbe322895663e7c144d161cfabc88efaeee86ad00c1c37cc8c6e4ef11b
|
@@ -40,7 +40,7 @@ module ForemanIcinga
|
|
40
40
|
'comment' => 'host deleted in foreman',
|
41
41
|
'duration' => '7200'
|
42
42
|
}
|
43
|
-
response = icinga.call('deployment/downtime/schedule',
|
43
|
+
response = icinga.call('deployment/downtime/schedule', {}, params)
|
44
44
|
|
45
45
|
if response['status'] == 'error' && ! icinga_ignore_failed_action?
|
46
46
|
errors.add(:base, _("Error from Icinga server: '%s'") % response['message'])
|
data/app/services/icinga.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
|
3
3
|
class Icinga
|
4
|
+
delegate :logger, :to => :Rails
|
4
5
|
attr_reader :client, :token, :address
|
5
6
|
|
6
7
|
def initialize
|
@@ -8,19 +9,18 @@ class Icinga
|
|
8
9
|
@token = Setting[:icinga_token]
|
9
10
|
end
|
10
11
|
|
11
|
-
def call(endpoint, payload =
|
12
|
+
def call(endpoint, payload = {}, params = {}, method = :post)
|
12
13
|
uri = icinga_url_for(endpoint, params.merge(default_params))
|
13
|
-
|
14
|
+
result = nil
|
15
|
+
result = parse post(uri, payload) if method == :post
|
16
|
+
result = parse get(uri, payload) if method == :get
|
17
|
+
result
|
14
18
|
rescue OpenSSL::SSL::SSLError => e
|
15
19
|
message = "SSL Connection to Icinga failed: #{e}"
|
16
20
|
logger.warn message
|
17
21
|
error_response message
|
18
22
|
end
|
19
23
|
|
20
|
-
def logger
|
21
|
-
Rails.logger
|
22
|
-
end
|
23
|
-
|
24
24
|
protected
|
25
25
|
|
26
26
|
attr_reader :connect_params
|
@@ -30,7 +30,7 @@ class Icinga
|
|
30
30
|
:timeout => 3,
|
31
31
|
:open_timeout => 3,
|
32
32
|
:headers => {
|
33
|
-
:accept =>
|
33
|
+
:accept => '*/*',
|
34
34
|
},
|
35
35
|
:verify_ssl => verify_ssl?,
|
36
36
|
:ssl_ca_file => ssl_ca_file
|
@@ -55,10 +55,14 @@ class Icinga
|
|
55
55
|
RestClient::Resource.new(uri, connect_params)
|
56
56
|
end
|
57
57
|
|
58
|
-
def post(path, payload =
|
58
|
+
def post(path, payload = {})
|
59
59
|
client(path).post(payload)
|
60
60
|
end
|
61
61
|
|
62
|
+
def get(path, payload = {})
|
63
|
+
client(path).get(payload)
|
64
|
+
end
|
65
|
+
|
62
66
|
def parse(response)
|
63
67
|
if response && response.code >= 200 && response.code < 300
|
64
68
|
return response.body.present? ? JSON.parse(response.body) : error_response(_('received empty result'))
|
@@ -81,7 +85,7 @@ class Icinga
|
|
81
85
|
|
82
86
|
def icinga_url_for(route, params = {})
|
83
87
|
base = URI.join(address, route).to_s
|
84
|
-
return base if params.empty?
|
88
|
+
return base + "?token=" + token if params.empty?
|
85
89
|
base + '?' + params.to_query + '&token=' + token
|
86
90
|
end
|
87
91
|
end
|
data/test/unit/icinga_test.rb
CHANGED
@@ -7,7 +7,7 @@ class IcingaTest < ActiveSupport::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
test '#icinga_url_for should return valid urls' do
|
10
|
-
assert_equal 'http://example.com/test/bla
|
10
|
+
assert_equal 'http://example.com/test/bla?token=123456',
|
11
11
|
@icinga.send('icinga_url_for', 'test/bla')
|
12
12
|
assert_equal 'http://example.com/test/blubb?param=1&token=123456',
|
13
13
|
@icinga.send('icinga_url_for', 'test/blubb', 'param' => '1')
|
@@ -20,18 +20,18 @@ class IcingaTest < ActiveSupport::TestCase
|
|
20
20
|
|
21
21
|
test 'should correctly parse response' do
|
22
22
|
@icinga.expects(:post)
|
23
|
-
.with('http://example.com/health?host=example.com&json=true&token=123456',
|
23
|
+
.with('http://example.com/health?host=example.com&json=true&token=123456', {})
|
24
24
|
.returns(fake_response(JSON('healthy' => 'true')))
|
25
|
-
response = @icinga.call('health',
|
25
|
+
response = @icinga.call('health', {}, {'host' => 'example.com'})
|
26
26
|
assert_kind_of Hash, response
|
27
27
|
assert response['healthy']
|
28
28
|
end
|
29
29
|
|
30
30
|
test 'should return error message when result is empty' do
|
31
31
|
@icinga.expects(:post)
|
32
|
-
.with('http://example.com/health?host=example.com&json=true&token=123456',
|
32
|
+
.with('http://example.com/health?host=example.com&json=true&token=123456', {})
|
33
33
|
.returns(fake_response(''))
|
34
|
-
response = @icinga.call('health',
|
34
|
+
response = @icinga.call('health', {}, {'host' => 'example.com'})
|
35
35
|
assert_kind_of Hash, response
|
36
36
|
assert_equal 'error', response['status']
|
37
37
|
assert_equal 'received empty result', response['message']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_icinga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Goebel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|