logstash-input-tcp 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -2
- data/lib/logstash/inputs/tcp.rb +81 -60
- data/logstash-input-tcp.gemspec +1 -1
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 736fd1ded495c11b6aa4f70150cd2779ea23617d
|
4
|
+
data.tar.gz: b609a4785013e0f39af136f1fb42b905003d4dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52e09a292d90e8fec2dba13ea2076fb69940398a6571a28004d5d6219ec0efeef0687e4cc570a8b23f528975b037cb98250a9620ead9c4a0addb52dd059b7ff6
|
7
|
+
data.tar.gz: f700ffc6f7c5290c4bbc48a0409d13703c7cc2570b9105474395ead15a9d4b35e44e0fc6e05487a9419f6dd53ddbd53f5cb2da1279e1197e61bf6373237d2ed8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
## 2.0.0
|
2
|
-
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
2
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
3
3
|
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
4
4
|
- Dependency on logstash-core update to 2.0
|
5
|
-
|
5
|
+
## 2.0.2
|
6
|
+
- refactored & cleaned up plugin structure, see https://github.com/logstash-plugins/logstash-input-tcp/pull/18
|
data/lib/logstash/inputs/tcp.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
require "logstash/inputs/base"
|
3
3
|
require "logstash/util/socket_peer"
|
4
4
|
|
5
|
+
require "socket"
|
6
|
+
require "openssl"
|
7
|
+
|
5
8
|
# Read events over a TCP socket.
|
6
9
|
#
|
7
10
|
# Like stdin and file inputs, each event is assumed to be one line of text.
|
@@ -49,57 +52,27 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
49
52
|
def initialize(*args)
|
50
53
|
super(*args)
|
51
54
|
|
55
|
+
# monkey patch TCPSocket and SSLSocket to include socket peer
|
56
|
+
TCPSocket.module_eval{include ::LogStash::Util::SocketPeer}
|
57
|
+
OpenSSL::SSL::SSLSocket.module_eval{include ::LogStash::Util::SocketPeer}
|
58
|
+
|
52
59
|
# threadsafe socket bookkeeping
|
53
60
|
@server_socket = nil
|
54
61
|
@client_socket = nil
|
55
62
|
@connection_sockets = {}
|
56
63
|
@socket_mutex = Mutex.new
|
64
|
+
|
65
|
+
@ssl_context = nil
|
57
66
|
end
|
58
67
|
|
59
68
|
def register
|
60
|
-
require "socket"
|
61
|
-
require "timeout"
|
62
|
-
require "openssl"
|
63
|
-
|
64
|
-
# monkey patch TCPSocket and SSLSocket to include socket peer
|
65
|
-
TCPSocket.module_eval{include ::LogStash::Util::SocketPeer}
|
66
|
-
OpenSSL::SSL::SSLSocket.module_eval{include ::LogStash::Util::SocketPeer}
|
67
|
-
|
68
69
|
fix_streaming_codecs
|
69
70
|
|
70
|
-
if @ssl_enable
|
71
|
-
@ssl_context = OpenSSL::SSL::SSLContext.new
|
72
|
-
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
|
73
|
-
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
|
74
|
-
if @ssl_verify
|
75
|
-
@cert_store = OpenSSL::X509::Store.new
|
76
|
-
# Load the system default certificate path to the store
|
77
|
-
@cert_store.set_default_paths
|
78
|
-
if File.directory?(@ssl_cacert)
|
79
|
-
@cert_store.add_path(@ssl_cacert)
|
80
|
-
else
|
81
|
-
@cert_store.add_file(@ssl_cacert)
|
82
|
-
end
|
83
|
-
@ssl_context.cert_store = @cert_store
|
84
|
-
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
71
|
# note that since we are opening a socket in register, we must also make sure we close it
|
89
72
|
# in the close method even if we also close it in the stop method since we could have
|
90
73
|
# a situation where register is called but not run & stop.
|
91
74
|
|
92
|
-
if server?
|
93
|
-
@logger.info("Starting tcp input listener", :address => "#{@host}:#{@port}")
|
94
|
-
begin
|
95
|
-
set_server_socket(TCPServer.new(@host, @port))
|
96
|
-
rescue Errno::EADDRINUSE
|
97
|
-
@logger.error("Could not start TCP server: Address in use", :host => @host, :port => @port)
|
98
|
-
raise
|
99
|
-
end
|
100
|
-
|
101
|
-
set_server_socket(OpenSSL::SSL::SSLServer.new(server_socket, @ssl_context)) if @ssl_enable
|
102
|
-
end
|
75
|
+
self.server_socket = new_server_socket if server?
|
103
76
|
end
|
104
77
|
|
105
78
|
def run(output_queue)
|
@@ -136,11 +109,13 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
136
109
|
# start a new thread for each connection.
|
137
110
|
server_connection_thread(output_queue, socket)
|
138
111
|
rescue OpenSSL::SSL::SSLError => e
|
112
|
+
# log error, close socket, accept next connection
|
139
113
|
@logger.error("SSL Error", :exception => e, :backtrace => e.backtrace)
|
140
|
-
|
114
|
+
socket.close rescue nil
|
115
|
+
rescue => e
|
141
116
|
# if this exception occured while the plugin is stopping
|
142
117
|
# just ignore and exit
|
143
|
-
raise unless stop?
|
118
|
+
raise e unless stop?
|
144
119
|
end
|
145
120
|
end
|
146
121
|
ensure
|
@@ -150,24 +125,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
150
125
|
|
151
126
|
def run_client(output_queue)
|
152
127
|
while !stop?
|
153
|
-
|
154
|
-
|
155
|
-
if @ssl_enable
|
156
|
-
set_client_socket(OpenSSL::SSL::SSLSocket.new(client_socket, @ssl_context))
|
157
|
-
begin
|
158
|
-
client_socket.connect
|
159
|
-
rescue OpenSSL::SSL::SSLError => e
|
160
|
-
@logger.error("SSL Error", :exception => e, :backtrace => e.backtrace)
|
161
|
-
sleep(1) # prevent hammering peer
|
162
|
-
next
|
163
|
-
rescue
|
164
|
-
# if this exception occured while the plugin is stopping
|
165
|
-
# just ignore and exit
|
166
|
-
raise unless stop?
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
@logger.debug? && @logger.debug("Opened connection", :client => "#{client_socket.peer}")
|
128
|
+
self.client_socket = new_client_socket
|
171
129
|
handle_socket(client_socket, client_socket.peeraddr[3], output_queue, @codec.clone)
|
172
130
|
end
|
173
131
|
ensure
|
@@ -201,7 +159,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
201
159
|
@logger.debug? && @logger.debug("Connection reset by peer", :client => socket.peer)
|
202
160
|
rescue => e
|
203
161
|
# if plugin is stopping, don't bother logging it as an error
|
204
|
-
@logger.error("An error occurred. Closing connection", :client => socket.peer, :exception => e, :backtrace => e.backtrace)
|
162
|
+
!stop? && @logger.error("An error occurred. Closing connection", :client => socket.peer, :exception => e, :backtrace => e.backtrace)
|
205
163
|
ensure
|
206
164
|
# catch all rescue nil on close to discard any close errors or invalid socket
|
207
165
|
socket.close rescue nil
|
@@ -222,9 +180,72 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
222
180
|
socket.sysread(16384)
|
223
181
|
end
|
224
182
|
|
183
|
+
def ssl_context
|
184
|
+
return @ssl_context if @ssl_context
|
185
|
+
|
186
|
+
begin
|
187
|
+
@ssl_context = OpenSSL::SSL::SSLContext.new
|
188
|
+
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
|
189
|
+
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
|
190
|
+
if @ssl_verify
|
191
|
+
@cert_store = OpenSSL::X509::Store.new
|
192
|
+
# Load the system default certificate path to the store
|
193
|
+
@cert_store.set_default_paths
|
194
|
+
if File.directory?(@ssl_cacert)
|
195
|
+
@cert_store.add_path(@ssl_cacert)
|
196
|
+
else
|
197
|
+
@cert_store.add_file(@ssl_cacert)
|
198
|
+
end
|
199
|
+
@ssl_context.cert_store = @cert_store
|
200
|
+
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
201
|
+
end
|
202
|
+
rescue => e
|
203
|
+
@logger.error("Could not inititalize SSL context", :exception => e, :backtrace => e.backtrace)
|
204
|
+
raise e
|
205
|
+
end
|
206
|
+
|
207
|
+
@ssl_context
|
208
|
+
end
|
209
|
+
|
210
|
+
def new_server_socket
|
211
|
+
@logger.info("Starting tcp input listener", :address => "#{@host}:#{@port}")
|
212
|
+
|
213
|
+
begin
|
214
|
+
socket = TCPServer.new(@host, @port)
|
215
|
+
rescue Errno::EADDRINUSE
|
216
|
+
@logger.error("Could not start TCP server: Address in use", :host => @host, :port => @port)
|
217
|
+
raise
|
218
|
+
end
|
219
|
+
|
220
|
+
@ssl_enable ? OpenSSL::SSL::SSLServer.new(socket, ssl_context) : socket
|
221
|
+
end
|
222
|
+
|
223
|
+
def new_client_socket
|
224
|
+
socket = TCPSocket.new(@host, @port)
|
225
|
+
|
226
|
+
if @ssl_enable
|
227
|
+
socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
|
228
|
+
socket.connect
|
229
|
+
end
|
230
|
+
|
231
|
+
@logger.debug? && @logger.debug("Opened connection", :client => "#{socket.peer}")
|
232
|
+
|
233
|
+
socket
|
234
|
+
rescue OpenSSL::SSL::SSLError => e
|
235
|
+
@logger.error("SSL Error", :exception => e, :backtrace => e.backtrace)
|
236
|
+
# catch all rescue nil on close to discard any close errors or invalid socket
|
237
|
+
socket.close rescue nil
|
238
|
+
sleep(1) # prevent hammering peer
|
239
|
+
retry
|
240
|
+
rescue
|
241
|
+
# if this exception occured while the plugin is stopping
|
242
|
+
# just ignore and exit
|
243
|
+
raise unless stop?
|
244
|
+
end
|
245
|
+
|
225
246
|
# threadsafe sockets bookkeeping
|
226
247
|
|
227
|
-
def
|
248
|
+
def client_socket=(socket)
|
228
249
|
@socket_mutex.synchronize{@client_socket = socket}
|
229
250
|
end
|
230
251
|
|
@@ -232,7 +253,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
232
253
|
@socket_mutex.synchronize{@client_socket}
|
233
254
|
end
|
234
255
|
|
235
|
-
def
|
256
|
+
def server_socket=(socket)
|
236
257
|
@socket_mutex.synchronize{@server_socket = socket}
|
237
258
|
end
|
238
259
|
|
data/logstash-input-tcp.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-tcp'
|
4
|
-
s.version = '2.0.
|
4
|
+
s.version = '2.0.2'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Read events over a TCP socket."
|
7
7
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-tcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
@@ -11,7 +11,8 @@ cert_chain: []
|
|
11
11
|
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - '>='
|
17
18
|
- !ruby/object:Gem::Version
|
@@ -19,10 +20,7 @@ dependencies:
|
|
19
20
|
- - <
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 3.0.0
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
type: :runtime
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - '>='
|
28
26
|
- !ruby/object:Gem::Version
|
@@ -30,92 +28,94 @@ dependencies:
|
|
30
28
|
- - <
|
31
29
|
- !ruby/object:Gem::Version
|
32
30
|
version: 3.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-codec-plain
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
34
40
|
requirement: !ruby/object:Gem::Requirement
|
35
41
|
requirements:
|
36
42
|
- - '>='
|
37
43
|
- !ruby/object:Gem::Version
|
38
44
|
version: '0'
|
39
|
-
name: logstash-codec-plain
|
40
45
|
prerelease: false
|
41
46
|
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: logstash-codec-line
|
42
49
|
version_requirements: !ruby/object:Gem::Requirement
|
43
50
|
requirements:
|
44
51
|
- - '>='
|
45
52
|
- !ruby/object:Gem::Version
|
46
53
|
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
49
55
|
requirements:
|
50
56
|
- - '>='
|
51
57
|
- !ruby/object:Gem::Version
|
52
58
|
version: '0'
|
53
|
-
name: logstash-codec-line
|
54
59
|
prerelease: false
|
55
60
|
type: :runtime
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: logstash-codec-json
|
56
63
|
version_requirements: !ruby/object:Gem::Requirement
|
57
64
|
requirements:
|
58
65
|
- - '>='
|
59
66
|
- !ruby/object:Gem::Version
|
60
67
|
version: '0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
68
|
requirement: !ruby/object:Gem::Requirement
|
63
69
|
requirements:
|
64
70
|
- - '>='
|
65
71
|
- !ruby/object:Gem::Version
|
66
72
|
version: '0'
|
67
|
-
name: logstash-codec-json
|
68
73
|
prerelease: false
|
69
74
|
type: :runtime
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: logstash-codec-json_lines
|
70
77
|
version_requirements: !ruby/object:Gem::Requirement
|
71
78
|
requirements:
|
72
79
|
- - '>='
|
73
80
|
- !ruby/object:Gem::Version
|
74
81
|
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
82
|
requirement: !ruby/object:Gem::Requirement
|
77
83
|
requirements:
|
78
84
|
- - '>='
|
79
85
|
- !ruby/object:Gem::Version
|
80
86
|
version: '0'
|
81
|
-
name: logstash-codec-json_lines
|
82
87
|
prerelease: false
|
83
88
|
type: :runtime
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: logstash-devutils
|
84
91
|
version_requirements: !ruby/object:Gem::Requirement
|
85
92
|
requirements:
|
86
93
|
- - '>='
|
87
94
|
- !ruby/object:Gem::Version
|
88
95
|
version: '0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
96
|
requirement: !ruby/object:Gem::Requirement
|
91
97
|
requirements:
|
92
98
|
- - '>='
|
93
99
|
- !ruby/object:Gem::Version
|
94
100
|
version: '0'
|
95
|
-
name: logstash-devutils
|
96
101
|
prerelease: false
|
97
102
|
type: :development
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - '>='
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0'
|
103
103
|
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
104
104
|
email: info@elastic.co
|
105
105
|
executables: []
|
106
106
|
extensions: []
|
107
107
|
extra_rdoc_files: []
|
108
108
|
files:
|
109
|
+
- lib/logstash/inputs/tcp.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/inputs/tcp_spec.rb
|
112
|
+
- logstash-input-tcp.gemspec
|
109
113
|
- CHANGELOG.md
|
114
|
+
- README.md
|
110
115
|
- CONTRIBUTORS
|
111
116
|
- Gemfile
|
112
117
|
- LICENSE
|
113
118
|
- NOTICE.TXT
|
114
|
-
- README.md
|
115
|
-
- lib/logstash/inputs/tcp.rb
|
116
|
-
- logstash-input-tcp.gemspec
|
117
|
-
- spec/inputs/tcp_spec.rb
|
118
|
-
- spec/spec_helper.rb
|
119
119
|
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
120
120
|
licenses:
|
121
121
|
- Apache License (2.0)
|
@@ -138,10 +138,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.1.9
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Read events over a TCP socket.
|
145
145
|
test_files:
|
146
|
-
- spec/inputs/tcp_spec.rb
|
147
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/inputs/tcp_spec.rb
|