xymonclient 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -8
- data/lib/xymonclient/exception.rb +6 -0
- data/lib/xymonclient/version.rb +1 -1
- data/lib/xymonclient.rb +27 -4
- data/spec/xymonclient_spec.rb +31 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2178d1cc649bd47137710b76bfd567e3648ec39
|
4
|
+
data.tar.gz: deb2925a13f311a4a598fe524a17c41bf413248f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d978c6d7d89dce1e6a1a30ba0cef55d86b03fb38c18ee3b27a3360051705ef4aec2483df5cd2e9283e790ccddae88ba019d73449a5b90a45b6cec752b6ff3d5
|
7
|
+
data.tar.gz: 9b272aece7341bd23418aa2f4b3649d12fdd6016fec6def9560bad69843caee763e05a13dc68a7db993587562b59e6a4bb5a91458f4a25d8f9c894ac80f84055
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xymonclient (0.
|
4
|
+
xymonclient (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.3.0)
|
10
|
-
codeclimate-test-reporter (1.0.
|
11
|
-
simplecov
|
10
|
+
codeclimate-test-reporter (1.0.8)
|
11
|
+
simplecov (<= 0.13)
|
12
12
|
diff-lcs (1.3)
|
13
13
|
docile (1.1.5)
|
14
|
-
json (2.0
|
15
|
-
parser (2.
|
14
|
+
json (2.1.0-java)
|
15
|
+
parser (2.4.0.0)
|
16
16
|
ast (~> 2.2)
|
17
17
|
powerpack (0.1.1)
|
18
|
-
rainbow (2.2.
|
18
|
+
rainbow (2.2.2)
|
19
|
+
rake
|
19
20
|
rake (10.5.0)
|
20
21
|
rspec (3.5.0)
|
21
22
|
rspec-core (~> 3.5.0)
|
@@ -42,7 +43,7 @@ GEM
|
|
42
43
|
json (>= 1.8, < 3)
|
43
44
|
simplecov-html (~> 0.10.0)
|
44
45
|
simplecov-html (0.10.0)
|
45
|
-
unicode-display_width (1.1
|
46
|
+
unicode-display_width (1.2.1)
|
46
47
|
|
47
48
|
PLATFORMS
|
48
49
|
java
|
@@ -56,4 +57,4 @@ DEPENDENCIES
|
|
56
57
|
xymonclient!
|
57
58
|
|
58
59
|
BUNDLED WITH
|
59
|
-
1.14.
|
60
|
+
1.14.5
|
data/lib/xymonclient/version.rb
CHANGED
data/lib/xymonclient.rb
CHANGED
@@ -12,14 +12,18 @@ module XymonClient
|
|
12
12
|
# (port default to 1984)
|
13
13
|
class Client
|
14
14
|
attr_reader :servers
|
15
|
+
attr_accessor :retry_count
|
16
|
+
attr_accessor :retry_interval
|
15
17
|
|
16
|
-
def initialize(servers = [])
|
18
|
+
def initialize(servers = [], retry_count = 3, retry_interval = 5)
|
17
19
|
@servers = \
|
18
20
|
if servers.empty?
|
19
21
|
XymonClient::ServerDiscovery.find_from_file
|
20
22
|
else
|
21
23
|
_parse_servers(servers)
|
22
24
|
end
|
25
|
+
@retry_count = retry_count
|
26
|
+
@retry_interval = retry_interval
|
23
27
|
end
|
24
28
|
|
25
29
|
def status(host, service, status, message, lifetime = '30m')
|
@@ -65,21 +69,40 @@ module XymonClient
|
|
65
69
|
unless XymonClient.valid_duration?(duration)
|
66
70
|
cookies = board(host, service, ['cookie'])
|
67
71
|
@servers.each do |server|
|
72
|
+
next if cookies[server].to_i == -1
|
68
73
|
_send(
|
69
74
|
server,
|
70
75
|
"xymondack #{cookies[server].to_i} #{duration} #{message}"
|
71
|
-
)
|
76
|
+
)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
75
80
|
private
|
76
81
|
|
77
82
|
def _send_to_all(message)
|
78
|
-
|
83
|
+
fail_srv = []
|
84
|
+
send_result = true
|
85
|
+
@servers.each do |server|
|
86
|
+
retry_count = 0
|
87
|
+
begin
|
88
|
+
_send(server, message)
|
89
|
+
rescue
|
90
|
+
if retry_count < @retry_count || @retry_count == -1
|
91
|
+
sleep @retry_interval
|
92
|
+
retry_count += 1
|
93
|
+
retry
|
94
|
+
else
|
95
|
+
send_result = false
|
96
|
+
fail_srv << server
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
raise XymonClient::SendFailure if fail_srv.count == @servers.count
|
101
|
+
raise XymonClient::PartialSendFailure, fail_srv \
|
102
|
+
if (1..@servers.count - 1).cover?(fail_srv.count)
|
79
103
|
end
|
80
104
|
|
81
105
|
def _send(server, message)
|
82
|
-
# TODO: validate response from all servers ( and retry ?)
|
83
106
|
socket = TCPSocket.open(server[:host], server[:port])
|
84
107
|
socket.puts message
|
85
108
|
socket.close_write
|
data/spec/xymonclient_spec.rb
CHANGED
@@ -13,5 +13,36 @@ describe XymonClient do
|
|
13
13
|
)
|
14
14
|
client.status('my.host', 'myservice', 'green', 'all is good')
|
15
15
|
end
|
16
|
+
|
17
|
+
it 'could not send a status to some servers' do
|
18
|
+
client.retry_count = 0
|
19
|
+
times_called = 0
|
20
|
+
allow(client).to receive(:_send) do
|
21
|
+
times_called += 1
|
22
|
+
raise Errno::ECONNREFUSED if times_called == 2
|
23
|
+
end
|
24
|
+
expect do
|
25
|
+
client.status('my.host', 'myservice', 'green', 'all is good')
|
26
|
+
end.to raise_error(XymonClient::PartialSendFailure)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'could not send a status to all servers' do
|
30
|
+
allow(client).to receive(:_send).and_raise Errno::ECONNREFUSED
|
31
|
+
expect do
|
32
|
+
client.status('my.host', 'myservice', 'green', 'all is good')
|
33
|
+
end.to raise_error(XymonClient::SendFailure)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'retry sending a status to some servers' do
|
37
|
+
client.retry_count = 2
|
38
|
+
times_called = 0
|
39
|
+
allow(client).to receive(:_send) do
|
40
|
+
times_called += 1
|
41
|
+
raise Errno::ECONNREFUSED if times_called == 1
|
42
|
+
end
|
43
|
+
expect do
|
44
|
+
client.status('my.host', 'myservice', 'green', 'all is good')
|
45
|
+
end.not_to raise_error
|
46
|
+
end
|
16
47
|
end
|
17
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xymonclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chauviere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02
|
11
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|