logstash-input-tcp 4.0.3 → 4.1.0
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 -0
- data/lib/logstash/inputs/tcp.rb +30 -1
- data/logstash-input-tcp.gemspec +1 -1
- data/spec/inputs/tcp_spec.rb +36 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e9170fef8955f298473d6ab8d0fb0a5301f915c
|
4
|
+
data.tar.gz: e82dbe475f4d1c4928da2fd73a5e1e82009a038c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 202ff3f0feeb6017794bcfd1f9cdc6775066560fffc658fc3429b6064bf2ee5d1cd02f60087d4ce46149e2e52642e7cfe20439a5d1a905a2f09dab1f4e4387c3
|
7
|
+
data.tar.gz: 7491b4f37c8b2b2ff90e8d11922143ae75da7c4cb35d78e487f906219829f941bee949f7b3fc666c1cd06cfd80c88a4eb88bda167df9534e3f3b67635860b389
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/inputs/tcp.rb
CHANGED
@@ -30,6 +30,10 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
30
30
|
# `client` connects to a server.
|
31
31
|
config :mode, :validate => ["server", "client"], :default => "server"
|
32
32
|
|
33
|
+
# Proxy protocol support, only v1 is supported at this time
|
34
|
+
# http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt
|
35
|
+
config :proxy_protocol, :validate => :boolean, :default => false
|
36
|
+
|
33
37
|
# Enable SSL (must be set for other `ssl_` options to take effect).
|
34
38
|
config :ssl_enable, :validate => :boolean, :default => false
|
35
39
|
|
@@ -55,6 +59,8 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
55
59
|
|
56
60
|
HOST_FIELD = "host".freeze
|
57
61
|
PORT_FIELD = "port".freeze
|
62
|
+
PROXY_HOST_FIELD = "proxy_host".freeze
|
63
|
+
PROXY_PORT_FIELD = "proxy_port".freeze
|
58
64
|
SSLSUBJECT_FIELD = "sslsubject".freeze
|
59
65
|
|
60
66
|
def initialize(*args)
|
@@ -153,8 +159,31 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|
153
159
|
|
154
160
|
def handle_socket(socket, client_address, client_port, output_queue, codec)
|
155
161
|
peer = "#{client_address}:#{client_port}"
|
162
|
+
first_read = true
|
156
163
|
while !stop?
|
157
|
-
|
164
|
+
tbuf = read(socket)
|
165
|
+
if @proxy_protocol && first_read
|
166
|
+
first_read = false
|
167
|
+
orig_buf = tbuf
|
168
|
+
pp_hdr, tbuf = tbuf.split("\r\n", 2)
|
169
|
+
|
170
|
+
pp_info = pp_hdr.split(/\s/)
|
171
|
+
# PROXY proto clientip proxyip clientport proxyport
|
172
|
+
if pp_info[0] != "PROXY"
|
173
|
+
@logger.error("invalid proxy protocol header label", :hdr => pp_hdr)
|
174
|
+
raise IOError
|
175
|
+
else
|
176
|
+
proxy_address = pp_info[3]
|
177
|
+
proxy_port = pp_info[5]
|
178
|
+
client_address = pp_info[2]
|
179
|
+
client_port = pp_info[4]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
codec.decode(tbuf) do |event|
|
183
|
+
if @proxy_protocol
|
184
|
+
event.set(PROXY_HOST_FIELD, proxy_address) unless event.get(PROXY_HOST_FIELD)
|
185
|
+
event.set(PROXY_PORT_FIELD, proxy_port) unless event.get(PROXY_PORT_FIELD)
|
186
|
+
end
|
158
187
|
event.set(HOST_FIELD, client_address) unless event.get(HOST_FIELD)
|
159
188
|
event.set(PORT_FIELD, client_port) unless event.get(PORT_FIELD)
|
160
189
|
event.set(SSLSUBJECT_FIELD, socket.peer_cert.subject.to_s) if @ssl_enable && @ssl_verify && event.get(SSLSUBJECT_FIELD).nil?
|
data/logstash-input-tcp.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-tcp'
|
3
|
-
s.version = '4.0
|
3
|
+
s.version = '4.1.0'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "Read events over a TCP socket."
|
6
6
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
data/spec/inputs/tcp_spec.rb
CHANGED
@@ -63,6 +63,42 @@ describe LogStash::Inputs::Tcp do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
it "should handle PROXY protocol v1 connections" do
|
67
|
+
event_count = 10
|
68
|
+
port = rand(1024..65535)
|
69
|
+
conf = <<-CONFIG
|
70
|
+
input {
|
71
|
+
tcp {
|
72
|
+
port => #{port}
|
73
|
+
proxy_protocol => true
|
74
|
+
}
|
75
|
+
}
|
76
|
+
CONFIG
|
77
|
+
|
78
|
+
events = input(conf) do |pipeline, queue|
|
79
|
+
socket = Stud::try(5.times) { TCPSocket.new("127.0.0.1", port) }
|
80
|
+
socket.puts("PROXY TCP4 1.2.3.4 5.6.7.8 1234 5678\r");
|
81
|
+
socket.flush
|
82
|
+
event_count.times do |i|
|
83
|
+
# unicode smiley for testing unicode support!
|
84
|
+
socket.puts("#{i} ☹")
|
85
|
+
socket.flush
|
86
|
+
end
|
87
|
+
socket.close
|
88
|
+
|
89
|
+
event_count.times.collect {queue.pop}
|
90
|
+
end
|
91
|
+
|
92
|
+
insist { events.length } == event_count
|
93
|
+
event_count.times do |i|
|
94
|
+
insist { events[i].get("message") } == "#{i} ☹"
|
95
|
+
insist { events[i].get("host") } == "1.2.3.4"
|
96
|
+
insist { events[i].get("port") } == "1234"
|
97
|
+
insist { events[i].get("proxy_host") } == "5.6.7.8"
|
98
|
+
insist { events[i].get("proxy_port") } == "5678"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
66
102
|
it "should read events with plain codec and ISO-8859-1 charset" do
|
67
103
|
port = rand(1024..65535)
|
68
104
|
charset = "ISO-8859-1"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-tcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
168
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.4.8
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: Read events over a TCP socket.
|