fluent-plugin-wendelin 0.3 → 0.4
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.
- data/README.md +2 -2
- data/example/to_wendelin.conf +2 -0
- data/fluent-plugin-wendelin.gemspec +3 -3
- data/lib/fluent/plugin/out_wendelin.rb +14 -2
- data/lib/fluent/plugin/wendelin_client.rb +155 -72
- metadata +20 -16
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Configuration
|
|
12
12
|
|
13
13
|
A sample configuration to setup ingestion of data for a tag to Wendelin:
|
14
14
|
|
15
|
-
```
|
15
|
+
```
|
16
16
|
<match your.sensor.tag>
|
17
17
|
@type wendelin
|
18
18
|
@id wendelin_out
|
@@ -20,6 +20,7 @@ A sample configuration to setup ingestion of data for a tag to Wendelin:
|
|
20
20
|
streamtool_uri <Wendelin_URL>/erp5/portal_ingestion_policies/<YOUR_INGESTION_POLICY_ID>
|
21
21
|
user <your_wendelin_user>
|
22
22
|
password <your_wendelin_password>
|
23
|
+
use_keep_alive <true or false>
|
23
24
|
|
24
25
|
# all parameters of BufferedOutput & Output classes are supported too, e.g.
|
25
26
|
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
|
@@ -43,7 +44,6 @@ See *example/to_wendelin.conf* for fully setup example.
|
|
43
44
|
TODO
|
44
45
|
----
|
45
46
|
|
46
|
-
- make content to be posted over HTTP as raw (instead of urlencode data).
|
47
47
|
- HTTPS certificates are currently not verified.
|
48
48
|
- X.509 certificates instead of user / password.
|
49
49
|
- cleanup
|
data/example/to_wendelin.conf
CHANGED
@@ -28,6 +28,8 @@
|
|
28
28
|
user <your_wendelin_user>
|
29
29
|
password <your_wendelin_password>
|
30
30
|
|
31
|
+
use_keep_alive true
|
32
|
+
|
31
33
|
# all parameters of BufferedOutput & Output classes are supported too, e.g.
|
32
34
|
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
|
33
35
|
# their code near:
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "fluent-plugin-wendelin"
|
3
|
-
gem.version = "0.
|
4
|
-
gem.authors = ["
|
5
|
-
gem.email = ["
|
3
|
+
gem.version = "0.4"
|
4
|
+
gem.authors = ["Nexedians"]
|
5
|
+
gem.email = ["klaus@nexedi.com"]
|
6
6
|
gem.summary = %q{Fluentd output to Wendelin}
|
7
7
|
gem.description = %q{Fluentd output plugin to forward data to Wendelin system}
|
8
8
|
gem.homepage = "https://lab.nexedi.com/nexedi/fluent-plugin-wendelin"
|
@@ -38,6 +38,12 @@ module Fluent
|
|
38
38
|
config_param :user, :string, :default => nil
|
39
39
|
config_param :password, :string, :default => nil
|
40
40
|
|
41
|
+
config_param :use_keep_alive, :bool, :default => false
|
42
|
+
|
43
|
+
config_param :ssl_timeout, :integer, :default => 60
|
44
|
+
config_param :open_timeout, :integer, :default => 60
|
45
|
+
config_param :read_timeout, :integer, :default => 60
|
46
|
+
config_param :keep_alive_timeout, :integer, :default => 300
|
41
47
|
|
42
48
|
def configure(conf)
|
43
49
|
super
|
@@ -47,7 +53,9 @@ module Fluent
|
|
47
53
|
credentials['user'] = @user
|
48
54
|
credentials['password'] = @password
|
49
55
|
end
|
50
|
-
@wendelin = WendelinClient.new(@streamtool_uri, credentials, @log
|
56
|
+
@wendelin = WendelinClient.new(@streamtool_uri, credentials, @log,
|
57
|
+
@ssl_timeout, @open_timeout,
|
58
|
+
@read_timeout, @keep_alive_timeout)
|
51
59
|
end
|
52
60
|
|
53
61
|
def start
|
@@ -80,7 +88,11 @@ module Fluent
|
|
80
88
|
# further on server by Wendelin
|
81
89
|
reference = tag
|
82
90
|
|
83
|
-
@
|
91
|
+
if @use_keep_alive
|
92
|
+
@wendelin.ingest_with_keep_alive(reference, data_chunk)
|
93
|
+
else
|
94
|
+
@wendelin.ingest(reference, data_chunk)
|
95
|
+
end
|
84
96
|
end
|
85
97
|
|
86
98
|
end
|
@@ -15,91 +15,174 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
|
19
18
|
require 'net/http'
|
20
19
|
require 'openssl'
|
21
20
|
|
22
|
-
|
23
21
|
# class representing a Wendelin client
|
24
22
|
class WendelinClient
|
25
23
|
|
26
24
|
# `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint"
|
27
25
|
# `credentials` # {'user' => _, 'password' => _} TODO change to certificate
|
28
26
|
# `log` - logger to use
|
29
|
-
def initialize(streamtool_uri, credentials, log
|
30
|
-
|
31
|
-
@
|
32
|
-
@
|
27
|
+
def initialize(streamtool_uri, credentials, log,
|
28
|
+
ssl_timeout, open_timeout, read_timeout, keep_alive_timeout)
|
29
|
+
@streamtool_uri = streamtool_uri
|
30
|
+
@credentials = credentials
|
31
|
+
@log = log
|
32
|
+
@ssl_timeout = ssl_timeout
|
33
|
+
@open_timeout = open_timeout
|
34
|
+
@read_timeout = read_timeout
|
35
|
+
@keep_alive_timeout = keep_alive_timeout
|
33
36
|
end
|
34
37
|
|
35
38
|
|
39
|
+
# start request in an independent function to keep the connection open
|
40
|
+
def start_connection(uri)
|
41
|
+
|
42
|
+
@log.debug "start new connection"
|
43
|
+
|
44
|
+
@http = Net::HTTP.start(uri.hostname, uri.port,
|
45
|
+
:use_ssl => (uri.scheme == 'https'),
|
46
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
47
|
+
|
48
|
+
# Net::HTTP default open timeout is infinity, which results
|
49
|
+
# in thread hang forever if other side does not fully
|
50
|
+
# establish connection. Default read_timeout is 60 seconds.
|
51
|
+
# We go safe way and make sure all timeouts are defined.
|
52
|
+
:ssl_timeout => @ssl_timeout,
|
53
|
+
:open_timeout => @open_timeout,
|
54
|
+
:read_timeout => @read_timeout,
|
55
|
+
:keep_alive_timeout => @keep_alive_timeout,)
|
56
|
+
end
|
57
|
+
|
36
58
|
# ingest `data_chunk` to a stream referenced as `reference`
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX
|
97
|
-
#@log.info "ingested ok"
|
98
|
-
else
|
99
|
-
@log.warn "FAIL:"
|
100
|
-
res.value
|
101
|
-
end
|
102
|
-
end
|
59
|
+
def ingest_with_keep_alive(reference, data_chunk)
|
60
|
+
uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}")
|
61
|
+
# call start_connection if http is undefined
|
62
|
+
if ! defined? @http
|
63
|
+
start_connection(uri)
|
64
|
+
end
|
65
|
+
|
66
|
+
# connect again if the connection is not started
|
67
|
+
if ! @http.started?()
|
68
|
+
start_connection(uri)
|
69
|
+
end
|
70
|
+
|
71
|
+
@request = Net::HTTP::Post.new(uri)
|
72
|
+
|
73
|
+
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex
|
74
|
+
# and it is far too slow. Such POST is legit:
|
75
|
+
# https://stackoverflow.com/a/14710450
|
76
|
+
@request.body = data_chunk
|
77
|
+
@request.content_type = 'application/octet-stream'
|
78
|
+
|
79
|
+
if @credentials.has_key?('user')
|
80
|
+
@request.basic_auth @credentials['user'], @credentials['password']
|
81
|
+
end
|
82
|
+
|
83
|
+
@log.on_trace do
|
84
|
+
@log.trace '>>> REQUEST'
|
85
|
+
@log.trace "method\t=> #{@request.method}"
|
86
|
+
@log.trace "path\t=> #{@request.path}"
|
87
|
+
@log.trace "uri\t=> #{@request.uri}"
|
88
|
+
@log.trace "body\t=> #{@request.body}"
|
89
|
+
@log.trace "body_stream\t=> #{@request.body_stream}"
|
90
|
+
@request.each {|h| @log.trace "#{h}:\t#{@request[h]}"}
|
91
|
+
@log.trace
|
92
|
+
end
|
93
|
+
|
94
|
+
begin
|
95
|
+
res = @http.request(@request) # Net::HTTPResponse object
|
96
|
+
end
|
97
|
+
|
98
|
+
rescue
|
99
|
+
# some http/ssl/other connection error
|
100
|
+
@log.warn "HTTP ERROR:"
|
101
|
+
raise
|
102
|
+
else
|
103
|
+
@log.on_trace do
|
104
|
+
@log.trace '>>> RESPONSE'
|
105
|
+
res.each {|h| @log.trace "#{h}:\t#{res[h]}"}
|
106
|
+
@log.trace "code\t=> #{res.code}"
|
107
|
+
@log.trace "msg\t=> #{res.message}"
|
108
|
+
@log.trace "class\t=> #{res.class}"
|
109
|
+
@log.trace "body:", res.body
|
110
|
+
end
|
111
|
+
|
112
|
+
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX
|
113
|
+
#@log.info "ingested ok"
|
114
|
+
else
|
115
|
+
@log.warn "FAIL:"
|
116
|
+
res.value
|
117
|
+
end
|
103
118
|
end
|
104
119
|
|
120
|
+
def ingest(reference, data_chunk)
|
121
|
+
uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}")
|
122
|
+
req = Net::HTTP::Post.new(uri)
|
123
|
+
if @credentials.has_key?('user')
|
124
|
+
req.basic_auth @credentials['user'], @credentials['password']
|
125
|
+
end
|
126
|
+
|
127
|
+
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex
|
128
|
+
# and it is far too slow. Such POST is legit:
|
129
|
+
# https://stackoverflow.com/a/14710450
|
130
|
+
req.body = data_chunk
|
131
|
+
req.content_type = 'application/octet-stream'
|
132
|
+
|
133
|
+
@log.on_trace do
|
134
|
+
@log.trace '>>> REQUEST'
|
135
|
+
@log.trace "method\t=> #{req.method}"
|
136
|
+
@log.trace "path\t=> #{req.path}"
|
137
|
+
@log.trace "uri\t=> #{req.uri}"
|
138
|
+
@log.trace "body\t=> #{req.body}"
|
139
|
+
@log.trace "body_stream\t=> #{req.body_stream}"
|
140
|
+
req.each {|h| @log.trace "#{h}:\t#{req[h]}"}
|
141
|
+
@log.trace
|
142
|
+
end
|
143
|
+
|
144
|
+
begin
|
145
|
+
# TODO keep connection open (so that every new ingest does not do
|
146
|
+
# full connect again)
|
147
|
+
res = Net::HTTP.start(uri.hostname, uri.port,
|
148
|
+
:use_ssl => (uri.scheme == 'https'),
|
149
|
+
# NOTE = "do not check server cert"
|
150
|
+
# TODO move this out to conf parameters
|
151
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
152
|
+
|
153
|
+
# Net::HTTP default open timeout is infinity, which results
|
154
|
+
# in thread hang forever if other side does not fully
|
155
|
+
# establish connection. Default read_timeout is 60 seconds.
|
156
|
+
# We go safe way and make sure all timeouts are defined.
|
157
|
+
:ssl_timeout => @ssl_timeout,
|
158
|
+
:open_timeout => @open_timeout,
|
159
|
+
:read_timeout => @read_timeout,
|
160
|
+
) do |http|
|
161
|
+
http.request(req)
|
162
|
+
end
|
163
|
+
|
164
|
+
rescue
|
165
|
+
# some http/ssl/other connection error
|
166
|
+
@log.warn "HTTP ERROR:"
|
167
|
+
raise
|
168
|
+
|
169
|
+
else
|
170
|
+
@log.on_trace do
|
171
|
+
@log.trace '>>> RESPONSE'
|
172
|
+
res.each {|h| @log.trace "#{h}:\t#{res[h]}"}
|
173
|
+
@log.trace "code\t=> #{res.code}"
|
174
|
+
@log.trace "msg\t=> #{res.message}"
|
175
|
+
@log.trace "class\t=> #{res.class}"
|
176
|
+
@log.trace "body:", res.body
|
177
|
+
end
|
178
|
+
|
179
|
+
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX
|
180
|
+
#@log.info "ingested ok"
|
181
|
+
else
|
182
|
+
@log.warn "FAIL:"
|
183
|
+
res.value
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
105
188
|
end
|
metadata
CHANGED
@@ -1,37 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-wendelin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: '0.4'
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
|
-
-
|
8
|
+
- Nexedians
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
14
16
|
name: fluentd
|
15
|
-
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
16
19
|
requirements:
|
17
|
-
- -
|
20
|
+
- - ~>
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: '0'
|
20
|
-
|
21
|
-
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
23
25
|
requirements:
|
24
|
-
- -
|
26
|
+
- - ~>
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: '0'
|
29
|
+
prerelease: false
|
27
30
|
description: Fluentd output plugin to forward data to Wendelin system
|
28
31
|
email:
|
29
|
-
-
|
32
|
+
- klaus@nexedi.com
|
30
33
|
executables: []
|
31
34
|
extensions: []
|
32
35
|
extra_rdoc_files: []
|
33
36
|
files:
|
34
|
-
-
|
37
|
+
- .gitignore
|
35
38
|
- Gemfile
|
36
39
|
- LICENSE.txt
|
37
40
|
- README.md
|
@@ -45,25 +48,26 @@ files:
|
|
45
48
|
homepage: https://lab.nexedi.com/nexedi/fluent-plugin-wendelin
|
46
49
|
licenses:
|
47
50
|
- Apache-2.0
|
48
|
-
metadata: {}
|
49
51
|
post_install_message:
|
50
52
|
rdoc_options: []
|
51
53
|
require_paths:
|
52
54
|
- lib
|
53
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
54
57
|
requirements:
|
55
|
-
- -
|
58
|
+
- - ! '>='
|
56
59
|
- !ruby/object:Gem::Version
|
57
60
|
version: '0'
|
58
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
59
63
|
requirements:
|
60
|
-
- -
|
64
|
+
- - ! '>='
|
61
65
|
- !ruby/object:Gem::Version
|
62
66
|
version: '0'
|
63
67
|
requirements: []
|
64
68
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
69
|
+
rubygems_version: 1.8.23.2
|
66
70
|
signing_key:
|
67
|
-
specification_version:
|
71
|
+
specification_version: 3
|
68
72
|
summary: Fluentd output to Wendelin
|
69
73
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 16421dddd4db913fcdc9c1c50de6c83065014e9c
|
4
|
-
data.tar.gz: 7af5466ec21e0b9845ff1fef6e1e85d2b4fd5a56
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 7ecff204b3f1b6ccc090709ecf00f88fa511be03e9912e1a1aa5761ba9e0a39b871df297e50796a26c9640f266eeed198d061dc502079677053e3dac107b12e7
|
7
|
-
data.tar.gz: 98be162b72588df472140aa7c2eb033c70c3ac4d36fc9fde4c4b3d6ab85934bcb5e9c96320bf781c0f41e351494f0818cd60f0e7041950157558b67838dc30da
|