riemann-client 0.2.5 → 1.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/.github/workflows/ci.yml +58 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +84 -0
- data/Gemfile +7 -0
- data/README.markdown +21 -12
- data/Rakefile +15 -0
- data/lib/riemann/attribute.rb +2 -0
- data/lib/riemann/auto_state.rb +9 -3
- data/lib/riemann/client/ssl_socket.rb +92 -0
- data/lib/riemann/client/tcp.rb +46 -39
- data/lib/riemann/client/tcp_socket.rb +76 -58
- data/lib/riemann/client/udp.rb +8 -4
- data/lib/riemann/client.rb +84 -78
- data/lib/riemann/event.rb +60 -61
- data/lib/riemann/message.rb +2 -0
- data/lib/riemann/metric_thread.rb +59 -54
- data/lib/riemann/query.rb +4 -2
- data/lib/riemann/state.rb +8 -8
- data/lib/riemann/version.rb +3 -1
- data/lib/riemann.rb +2 -3
- data/riemann-client.gemspec +34 -0
- data/spec/client.rb +384 -0
- data/spec/riemann.config +30 -0
- metadata +84 -38
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 395c52ac148f9988953268a74e1e747c415e3b80c75e7e0cfef536d7f44a2d36
|
4
|
+
data.tar.gz: 81051904aef015898e9abde73a6bdf2cde446cec0ed8712b0a2cd569d1a62f50
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d016e54a3881d70914163c88506da3936f47c6c3390f092eb1a2a179c1cd1034984337d81ecbbefdcef01019efa168f8d93662918c67125f31245cffa471b1f5
|
7
|
+
data.tar.gz: 330ea26290403c97dd44ac1b0d04b72ea9bebd27a147f00c0135ce9d46a09c01c4f8271daaa3c118a2feeebb84603d6dde77066ee5a994e6c7c32e8e2eb1c89a
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
name: CI
|
3
|
+
|
4
|
+
on:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- main
|
8
|
+
pull_request:
|
9
|
+
branches:
|
10
|
+
- main
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
lint:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Setup ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: '2.7'
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Run rubocop
|
23
|
+
run: bundle exec rubocop
|
24
|
+
test:
|
25
|
+
needs: lint
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
strategy:
|
28
|
+
matrix:
|
29
|
+
ruby-version:
|
30
|
+
- 2.6
|
31
|
+
- 2.7
|
32
|
+
- 3.0
|
33
|
+
- 3.1
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v2
|
36
|
+
- name: Setup Ruby
|
37
|
+
uses: ruby/setup-ruby@v1
|
38
|
+
with:
|
39
|
+
ruby-version: ${{ matrix.ruby-version }}
|
40
|
+
bundler-cache: true
|
41
|
+
- name: Install riemann
|
42
|
+
run: |
|
43
|
+
wget --quiet https://github.com/riemann/riemann/releases/download/0.3.8/riemann_0.3.8_all.deb
|
44
|
+
sudo dpkg -i riemann_0.3.8_all.deb
|
45
|
+
|
46
|
+
sudo systemctl stop riemann
|
47
|
+
|
48
|
+
sudo openssl genrsa -out /etc/riemann/riemann_server.key 4096
|
49
|
+
sudo openssl pkcs8 -topk8 -nocrypt -in /etc/riemann/riemann_server.key -out /etc/riemann/riemann_server.pkcs8
|
50
|
+
sudo openssl req -x509 -new -nodes -key /etc/riemann/riemann_server.key -days 7 -out /etc/riemann/riemann_server.crt -subj '/CN=localhost'
|
51
|
+
sudo chmod +r /etc/riemann/riemann_server.pkcs8
|
52
|
+
sudo cp -v spec/riemann.config /etc/riemann/
|
53
|
+
|
54
|
+
sudo systemctl start riemann
|
55
|
+
|
56
|
+
while ! nc -z localhost 5555; do sleep 1; done
|
57
|
+
- name: Run the test suite
|
58
|
+
run: bundle exec bacon spec/*.rb
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
Metrics/AbcSize:
|
3
|
+
Enabled: false
|
4
|
+
Metrics/BlockLength:
|
5
|
+
Enabled: false
|
6
|
+
Metrics/ClassLength:
|
7
|
+
Enabled: false
|
8
|
+
Metrics/CyclomaticComplexity:
|
9
|
+
Enabled: false
|
10
|
+
Metrics/MethodLength:
|
11
|
+
Enabled: false
|
12
|
+
Metrics/PerceivedComplexity:
|
13
|
+
Enabled: false
|
14
|
+
Naming/VariableNumber:
|
15
|
+
AllowedIdentifiers:
|
16
|
+
- TLSv1_2
|
17
|
+
Style/Documentation:
|
18
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [1.0.1](https://github.com/riemann/riemann-ruby-client/tree/1.0.1) (2022-06-25)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/v1.0.0...1.0.1)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Setup Rubocop and lower required Ruby version [\#37](https://github.com/riemann/riemann-ruby-client/pull/37) ([smortex](https://github.com/smortex))
|
10
|
+
|
11
|
+
## [v1.0.0](https://github.com/riemann/riemann-ruby-client/tree/v1.0.0) (2022-06-16)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.6...v1.0.0)
|
14
|
+
|
15
|
+
**Implemented enhancements:**
|
16
|
+
|
17
|
+
- Add support for micro-seconds resolution [\#34](https://github.com/riemann/riemann-ruby-client/pull/34) ([smortex](https://github.com/smortex))
|
18
|
+
- Add support for TLS [\#33](https://github.com/riemann/riemann-ruby-client/pull/33) ([smortex](https://github.com/smortex))
|
19
|
+
- Add support for IPv6 addresses [\#30](https://github.com/riemann/riemann-ruby-client/pull/30) ([dch](https://github.com/dch))
|
20
|
+
|
21
|
+
**Merged pull requests:**
|
22
|
+
|
23
|
+
- Fix race conditions in CI [\#35](https://github.com/riemann/riemann-ruby-client/pull/35) ([smortex](https://github.com/smortex))
|
24
|
+
- Modernize and setup CI [\#32](https://github.com/riemann/riemann-ruby-client/pull/32) ([smortex](https://github.com/smortex))
|
25
|
+
- Bump beefcake dependency [\#29](https://github.com/riemann/riemann-ruby-client/pull/29) ([dch](https://github.com/dch))
|
26
|
+
|
27
|
+
## [0.2.6](https://github.com/riemann/riemann-ruby-client/tree/0.2.6) (2015-11-18)
|
28
|
+
|
29
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.5...0.2.6)
|
30
|
+
|
31
|
+
**Merged pull requests:**
|
32
|
+
|
33
|
+
- Client should yield self [\#22](https://github.com/riemann/riemann-ruby-client/pull/22) ([agile](https://github.com/agile))
|
34
|
+
- Allow TCP sockets to work on Windows [\#21](https://github.com/riemann/riemann-ruby-client/pull/21) ([sgran](https://github.com/sgran))
|
35
|
+
- README hash syntax fix [\#20](https://github.com/riemann/riemann-ruby-client/pull/20) ([squarism](https://github.com/squarism))
|
36
|
+
|
37
|
+
## [0.2.5](https://github.com/riemann/riemann-ruby-client/tree/0.2.5) (2015-02-05)
|
38
|
+
|
39
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.4...0.2.5)
|
40
|
+
|
41
|
+
## [0.2.4](https://github.com/riemann/riemann-ruby-client/tree/0.2.4) (2015-02-03)
|
42
|
+
|
43
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.2...0.2.4)
|
44
|
+
|
45
|
+
**Merged pull requests:**
|
46
|
+
|
47
|
+
- Tightening beefcake requirement [\#19](https://github.com/riemann/riemann-ruby-client/pull/19) ([aphyr](https://github.com/aphyr))
|
48
|
+
- Fix for \#17, plus test and connection refactor [\#18](https://github.com/riemann/riemann-ruby-client/pull/18) ([RKelln](https://github.com/RKelln))
|
49
|
+
- Ensure that we close the connection if we got an error back [\#16](https://github.com/riemann/riemann-ruby-client/pull/16) ([eric](https://github.com/eric))
|
50
|
+
- String\#clear doesn't exist in 1.8 [\#15](https://github.com/riemann/riemann-ruby-client/pull/15) ([eric](https://github.com/eric))
|
51
|
+
- Tcp client with timeouts [\#14](https://github.com/riemann/riemann-ruby-client/pull/14) ([eric](https://github.com/eric))
|
52
|
+
|
53
|
+
## [0.2.2](https://github.com/riemann/riemann-ruby-client/tree/0.2.2) (2013-05-28)
|
54
|
+
|
55
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.0...0.2.2)
|
56
|
+
|
57
|
+
**Merged pull requests:**
|
58
|
+
|
59
|
+
- Update README with timeout information [\#11](https://github.com/riemann/riemann-ruby-client/pull/11) ([gsandie](https://github.com/gsandie))
|
60
|
+
- Add tcp socket timeouts [\#10](https://github.com/riemann/riemann-ruby-client/pull/10) ([gsandie](https://github.com/gsandie))
|
61
|
+
- Socket can not be opened in method connected? [\#9](https://github.com/riemann/riemann-ruby-client/pull/9) ([vadv](https://github.com/vadv))
|
62
|
+
|
63
|
+
## [0.2.0](https://github.com/riemann/riemann-ruby-client/tree/0.2.0) (2013-04-02)
|
64
|
+
|
65
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/version-0.0.7...0.2.0)
|
66
|
+
|
67
|
+
**Merged pull requests:**
|
68
|
+
|
69
|
+
- Get and set attributes using hash-style accessors [\#8](https://github.com/riemann/riemann-ruby-client/pull/8) ([jegt](https://github.com/jegt))
|
70
|
+
- Add extra attributes added to the Event constructor to the event as Attribute instances [\#7](https://github.com/riemann/riemann-ruby-client/pull/7) ([jegt](https://github.com/jegt))
|
71
|
+
- Change attribute name to attribute key [\#6](https://github.com/riemann/riemann-ruby-client/pull/6) ([b](https://github.com/b))
|
72
|
+
- Arbitrary attributes on events [\#5](https://github.com/riemann/riemann-ruby-client/pull/5) ([b](https://github.com/b))
|
73
|
+
|
74
|
+
## [version-0.0.7](https://github.com/riemann/riemann-ruby-client/tree/version-0.0.7) (2012-04-16)
|
75
|
+
|
76
|
+
[Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/fe25a3b01681612defc39250006748069e06a172...version-0.0.7)
|
77
|
+
|
78
|
+
**Merged pull requests:**
|
79
|
+
|
80
|
+
- Add support for ruby 1.8 [\#1](https://github.com/riemann/riemann-ruby-client/pull/1) ([eric](https://github.com/eric))
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/Gemfile
ADDED
data/README.markdown
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
|
2
|
-
==========
|
1
|
+
# Riemann Ruby Client
|
3
2
|
|
4
|
-
|
3
|
+
[](https://github.com/riemann/riemann-ruby-client/actions/workflows/ci.yml)
|
5
4
|
|
6
|
-
|
7
|
-
===
|
5
|
+
## Installing
|
8
6
|
|
9
|
-
```
|
7
|
+
```shell
|
8
|
+
gem install riemann-client
|
9
|
+
```
|
10
|
+
|
11
|
+
## Use
|
12
|
+
|
13
|
+
```ruby
|
10
14
|
require 'riemann/client'
|
11
15
|
|
12
16
|
# Create a client. Host, port and timeout are optional.
|
@@ -38,8 +42,8 @@ c['host =~ "%.dc1" and (state = "critical" or state = "warning")']
|
|
38
42
|
|
39
43
|
```
|
40
44
|
|
41
|
-
Transports
|
42
|
-
|
45
|
+
## Transports
|
46
|
+
|
43
47
|
|
44
48
|
Riemann::Client sends small events over UDP by default, and uses TCP for
|
45
49
|
queries and large events. UDP sends are essentially "shouting into the void".
|
@@ -48,14 +52,13 @@ faster than TCP, but you will not know if the server is down or encountered an
|
|
48
52
|
error. You can specify what transport to use by selecting a subclient:
|
49
53
|
|
50
54
|
``` ruby
|
51
|
-
c.udp << { :state "ok" } # => nil
|
52
|
-
c.tcp << { :state "ok" } # => #<Message ...>
|
55
|
+
c.udp << { :state => "ok" } # => nil
|
56
|
+
c.tcp << { :state => "ok" } # => #<Message ...>
|
53
57
|
c.tcp["true"] # => [#<Event ... >, ...]
|
54
58
|
c.udp["true"] # => raise Riemann::Client::Unsupported
|
55
59
|
```
|
56
60
|
|
57
|
-
Client state management
|
58
|
-
=======================
|
61
|
+
## Client state management
|
59
62
|
|
60
63
|
Riemann::Client provides some classes to make managing state updates easier.
|
61
64
|
|
@@ -64,3 +67,9 @@ be used to flush an accumulated value to ustate at regular intervals.
|
|
64
67
|
|
65
68
|
Riemann::AutoState bundles a state and a client together. Any changes to the
|
66
69
|
AutoState automatically send the new state to the client.
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The MIT License
|
74
|
+
|
75
|
+
Copyright (c) 2011-2022 Kyle Kingsbury
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann'
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
7
|
+
require 'github_changelog_generator/task'
|
8
|
+
|
9
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
10
|
+
config.user = 'riemann'
|
11
|
+
config.project = 'riemann-ruby-client'
|
12
|
+
config.exclude_labels = ['skip-changelog']
|
13
|
+
config.future_release = Riemann::VERSION
|
14
|
+
config.add_issues_wo_labels = false
|
15
|
+
end
|
data/lib/riemann/attribute.rb
CHANGED
data/lib/riemann/auto_state.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Riemann
|
2
4
|
class AutoState
|
3
5
|
# Binds together a state hash and a Client. Any change made here
|
@@ -40,7 +42,7 @@ module Riemann
|
|
40
42
|
# @state.state = 'heavy lifting b'
|
41
43
|
# ...
|
42
44
|
# end
|
43
|
-
|
45
|
+
|
44
46
|
def initialize(client = Client.new, state = {})
|
45
47
|
@client = client
|
46
48
|
@state = state
|
@@ -95,7 +97,11 @@ module Riemann
|
|
95
97
|
def once(opts)
|
96
98
|
o = @state.merge opts
|
97
99
|
o[:time] = Time.now.to_i
|
98
|
-
o[:tags] =
|
100
|
+
o[:tags] = begin
|
101
|
+
(o[:tags] | ['once'])
|
102
|
+
rescue StandardError
|
103
|
+
['once']
|
104
|
+
end
|
99
105
|
@client << o
|
100
106
|
end
|
101
107
|
|
@@ -111,7 +117,7 @@ module Riemann
|
|
111
117
|
def service=(service)
|
112
118
|
@state[:service] = service
|
113
119
|
flush
|
114
|
-
end
|
120
|
+
end
|
115
121
|
|
116
122
|
def service
|
117
123
|
@state[:service]
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require_relative 'tcp_socket'
|
5
|
+
|
6
|
+
module Riemann
|
7
|
+
class Client
|
8
|
+
# Socket: A specialized socket that has been configure
|
9
|
+
class SSLSocket < TcpSocket
|
10
|
+
def initialize(options = {})
|
11
|
+
super(options)
|
12
|
+
@key_file = options[:key_file]
|
13
|
+
@cert_file = options[:cert_file]
|
14
|
+
@ca_file = options[:ca_file]
|
15
|
+
@ssl_verify = options[:ssl_verify]
|
16
|
+
end
|
17
|
+
|
18
|
+
def ssl_context
|
19
|
+
@ssl_context ||= OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
20
|
+
ctx.key = OpenSSL::PKey::RSA.new(File.read(@key_file))
|
21
|
+
ctx.cert = OpenSSL::X509::Certificate.new(File.read(@cert_file))
|
22
|
+
ctx.ca_file = @ca_file if @ca_file
|
23
|
+
ctx.ssl_version = :TLSv1_2
|
24
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER if @ssl_verify
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Internal: Connect to the give address within the timeout.
|
29
|
+
#
|
30
|
+
# Make an attempt to connect to a single address within the given timeout.
|
31
|
+
#
|
32
|
+
# Return the ::Socket when it is connected, or raise an Error if no
|
33
|
+
# connection was possible.
|
34
|
+
def connect_nonblock(addr, timeout)
|
35
|
+
sock = super(addr, timeout)
|
36
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
|
37
|
+
ssl_socket.sync = true
|
38
|
+
|
39
|
+
begin
|
40
|
+
ssl_socket.connect_nonblock
|
41
|
+
rescue IO::WaitReadable
|
42
|
+
unless IO.select([ssl_socket], nil, nil, timeout)
|
43
|
+
raise Timeout, "Could not read from #{host}:#{port} in #{timeout} seconds"
|
44
|
+
end
|
45
|
+
|
46
|
+
retry
|
47
|
+
rescue IO::WaitWritable
|
48
|
+
unless IO.select(nil, [ssl_socket], nil, timeout)
|
49
|
+
raise Timeout, "Could not write to #{host}:#{port} in #{timeout} seconds"
|
50
|
+
end
|
51
|
+
|
52
|
+
retry
|
53
|
+
end
|
54
|
+
ssl_socket
|
55
|
+
end
|
56
|
+
|
57
|
+
# Internal: Read up to a maxlen of data from the socket and store it in outbuf
|
58
|
+
#
|
59
|
+
# maxlen - the maximum number of bytes to read from the socket
|
60
|
+
# outbuf - the buffer in which to store the bytes.
|
61
|
+
#
|
62
|
+
# Returns the bytes read
|
63
|
+
def readpartial(maxlen, outbuf = nil)
|
64
|
+
super(maxlen, outbuf)
|
65
|
+
rescue OpenSSL::SSL::SSLErrorWaitReadable
|
66
|
+
unless wait_readable(read_timeout)
|
67
|
+
raise Timeout, "Could not read from #{host}:#{port} in #{read_timeout} seconds"
|
68
|
+
end
|
69
|
+
|
70
|
+
retry
|
71
|
+
end
|
72
|
+
|
73
|
+
# Internal: Write the given data to the socket
|
74
|
+
#
|
75
|
+
# buf - the data to write to the socket.
|
76
|
+
#
|
77
|
+
# Raises an error if it is unable to write the data to the socket within the
|
78
|
+
# write_timeout.
|
79
|
+
#
|
80
|
+
# returns nothing
|
81
|
+
def write(buf)
|
82
|
+
super(buf)
|
83
|
+
rescue OpenSSL::SSL::SSLErrorWaitWritable
|
84
|
+
unless wait_writable(write_timeout)
|
85
|
+
raise Timeout, "Could not write to #{host}:#{port} in #{write_timeout} seconds"
|
86
|
+
end
|
87
|
+
|
88
|
+
retry
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/riemann/client/tcp.rb
CHANGED
@@ -1,32 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'monitor'
|
2
4
|
require 'riemann/client/tcp_socket'
|
5
|
+
require 'riemann/client/ssl_socket'
|
3
6
|
|
4
7
|
module Riemann
|
5
8
|
class Client
|
6
9
|
class TCP < Client
|
7
|
-
attr_accessor :host, :port
|
10
|
+
attr_accessor :host, :port
|
8
11
|
|
9
12
|
# Public: Set a socket factory -- an object responding
|
10
13
|
# to #call(options) that returns a Socket object
|
11
|
-
|
12
|
-
|
14
|
+
class << self
|
15
|
+
attr_writer :socket_factory
|
13
16
|
end
|
14
17
|
|
15
18
|
# Public: Return a socket factory
|
16
19
|
def self.socket_factory
|
17
|
-
@socket_factory || proc { |options|
|
20
|
+
@socket_factory || proc { |options|
|
21
|
+
if options[:ssl]
|
22
|
+
SSLSocket.connect(options)
|
23
|
+
else
|
24
|
+
TcpSocket.connect(options)
|
25
|
+
end
|
26
|
+
}
|
18
27
|
end
|
19
28
|
|
20
|
-
def initialize(options = {})
|
29
|
+
def initialize(options = {}) # rubocop:disable Lint/MissingSuper
|
21
30
|
@options = options
|
22
31
|
@locket = Monitor.new
|
23
32
|
end
|
24
33
|
|
25
34
|
def socket
|
26
35
|
@locket.synchronize do
|
27
|
-
if @pid && @pid != Process.pid
|
28
|
-
close
|
29
|
-
end
|
36
|
+
close if @pid && @pid != Process.pid
|
30
37
|
|
31
38
|
return @socket if connected?
|
32
39
|
|
@@ -51,32 +58,32 @@ module Riemann
|
|
51
58
|
end
|
52
59
|
|
53
60
|
# Read a message from a stream
|
54
|
-
def read_message(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
str = s.read length
|
59
|
-
message = Riemann::Message.decode str
|
60
|
-
rescue => e
|
61
|
-
puts "Message was #{str.inspect}"
|
62
|
-
raise
|
63
|
-
end
|
61
|
+
def read_message(socket)
|
62
|
+
unless (buffer = socket.read(4)) && (buffer.size == 4)
|
63
|
+
raise InvalidResponse, 'unexpected EOF'
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
length = buffer.unpack1('N')
|
67
|
+
begin
|
68
|
+
str = socket.read length
|
69
|
+
message = Riemann::Message.decode str
|
70
|
+
rescue StandardError
|
71
|
+
puts "Message was #{str.inspect}"
|
72
|
+
raise
|
73
|
+
end
|
69
74
|
|
70
|
-
|
71
|
-
|
72
|
-
raise
|
75
|
+
unless message.ok
|
76
|
+
puts 'Failed'
|
77
|
+
raise ServerError, message.error
|
73
78
|
end
|
79
|
+
|
80
|
+
message
|
74
81
|
end
|
75
82
|
|
76
83
|
def send_recv(message)
|
77
|
-
with_connection do |
|
78
|
-
|
79
|
-
read_message(
|
84
|
+
with_connection do |socket|
|
85
|
+
socket.write(message.encode_with_length)
|
86
|
+
read_message(socket)
|
80
87
|
end
|
81
88
|
end
|
82
89
|
|
@@ -87,17 +94,17 @@ module Riemann
|
|
87
94
|
tries = 0
|
88
95
|
|
89
96
|
@locket.synchronize do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
tries += 1
|
98
|
+
yield(socket)
|
99
|
+
rescue IOError, Errno::EPIPE, Errno::ECONNREFUSED, InvalidResponse, Timeout::Error,
|
100
|
+
Riemann::Client::TcpSocket::Error
|
101
|
+
close
|
102
|
+
raise if tries > 3
|
103
|
+
|
104
|
+
retry
|
105
|
+
rescue StandardError
|
106
|
+
close
|
107
|
+
raise
|
101
108
|
end
|
102
109
|
end
|
103
110
|
end
|