logstash-input-udp 3.1.3 → 3.2.0
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTORS +1 -0
- data/lib/logstash/inputs/udp.rb +15 -7
- data/logstash-input-udp.gemspec +2 -1
- data/spec/inputs/udp_spec.rb +28 -6
- data/spec/support/client.rb +6 -13
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0105afa2ee725c47660577dbf22c2ad2f67be803379a6fd65dd0dfae7a2cafff
|
4
|
+
data.tar.gz: 6daebc814537c9219e9b993e97f0a55f2c0bbfb9769bc4ee09930614a3ffd96b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 982fef22a015e83c177579134eecc8fb042af10fbe78652b465ad5298f04112855fce191a8818b6518c9dc0119e12bd1c468d8944dc7dcc9867f1ebc6f3943d8
|
7
|
+
data.tar.gz: c540241bc6cec7b34e0063f950967e58f9c241aebb83903aa389019497f9db40b133fa10cc2f309a449d180982bb811c073922c7e37f537e87421f53fddd4fa2
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTORS
CHANGED
@@ -11,6 +11,7 @@ Contributors:
|
|
11
11
|
* Pier-Hugues Pellerin (ph)
|
12
12
|
* Richard Pijnenburg (electrical)
|
13
13
|
* kcrayon
|
14
|
+
* Colin Surprenant (colinsurprenant)
|
14
15
|
|
15
16
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
16
17
|
Logstash, and you aren't on the list above and want to be, please let us know
|
data/lib/logstash/inputs/udp.rb
CHANGED
@@ -37,6 +37,8 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
37
37
|
# before packets will start dropping.
|
38
38
|
config :queue_size, :validate => :number, :default => 2000
|
39
39
|
|
40
|
+
HOST_FIELD = "host".freeze
|
41
|
+
|
40
42
|
public
|
41
43
|
def initialize(params)
|
42
44
|
super
|
@@ -86,7 +88,7 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
86
88
|
|
87
89
|
@input_workers = @workers.times do |i|
|
88
90
|
@logger.debug("Starting UDP worker thread", :worker => i)
|
89
|
-
Thread.new { inputworker(i) }
|
91
|
+
Thread.new(i, @codec.clone) { |i, codec| inputworker(i, codec) }
|
90
92
|
end
|
91
93
|
|
92
94
|
while !stop?
|
@@ -109,17 +111,15 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
109
111
|
end
|
110
112
|
end # def udp_listener
|
111
113
|
|
112
|
-
def inputworker(number)
|
114
|
+
def inputworker(number, codec)
|
113
115
|
LogStash::Util::set_thread_name("<udp.#{number}")
|
114
116
|
begin
|
115
117
|
while true
|
116
118
|
payload, client = @input_to_worker.pop
|
119
|
+
host = client[3]
|
117
120
|
|
118
|
-
|
119
|
-
|
120
|
-
event.set("host", client[3]) if event.get("host").nil?
|
121
|
-
@output_queue.push(event)
|
122
|
-
end
|
121
|
+
codec.decode(payload) { |event| push_decoded_event(host, event) }
|
122
|
+
codec.flush { |event| push_decoded_event(host, event) }
|
123
123
|
end
|
124
124
|
rescue => e
|
125
125
|
@logger.error("Exception in inputworker", "exception" => e, "backtrace" => e.backtrace)
|
@@ -136,4 +136,12 @@ class LogStash::Inputs::Udp < LogStash::Inputs::Base
|
|
136
136
|
@udp.close rescue nil
|
137
137
|
end
|
138
138
|
|
139
|
+
private
|
140
|
+
|
141
|
+
def push_decoded_event(host, event)
|
142
|
+
decorate(event)
|
143
|
+
event.set(HOST_FIELD, host) if event.get(HOST_FIELD).nil?
|
144
|
+
@output_queue.push(event)
|
145
|
+
end
|
146
|
+
|
139
147
|
end # class LogStash::Inputs::Udp
|
data/logstash-input-udp.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-udp'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.2.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Reads events over UDP"
|
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/logstash-plugin install gemname. This gem is not a stand-alone program"
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'logstash-codec-plain'
|
26
26
|
s.add_runtime_dependency 'stud', '~> 0.0.22'
|
27
|
+
s.add_development_dependency 'logstash-codec-line'
|
27
28
|
s.add_development_dependency 'logstash-devutils'
|
28
29
|
end
|
29
30
|
|
data/spec/inputs/udp_spec.rb
CHANGED
@@ -9,8 +9,10 @@ describe LogStash::Inputs::Udp do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
let!(:helper) { UdpHelpers.new }
|
12
|
-
let(:
|
13
|
-
|
12
|
+
let(:client) { LogStash::Inputs::Test::UDPClient.new(port) }
|
13
|
+
let(:port) { rand(1024..65535) }
|
14
|
+
let(:config) { { "port" => port } }
|
15
|
+
subject { LogStash::Plugin.lookup("input","udp").new(config) }
|
14
16
|
|
15
17
|
after :each do
|
16
18
|
subject.close rescue nil
|
@@ -23,8 +25,6 @@ describe LogStash::Inputs::Udp do
|
|
23
25
|
end
|
24
26
|
|
25
27
|
describe "receive" do
|
26
|
-
|
27
|
-
let(:client) { LogStash::Inputs::Test::UDPClient.new(port) }
|
28
28
|
let(:nevents) { 10 }
|
29
29
|
|
30
30
|
let(:events) do
|
@@ -46,10 +46,32 @@ describe LogStash::Inputs::Udp do
|
|
46
46
|
expect(message).to match(/msg \d+/)
|
47
47
|
end
|
48
48
|
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "multiple lines per datagram using line codec" do
|
52
|
+
# 3 workers for 3 datagrams send below
|
53
|
+
let(:config) { { "port" => port, "workers" => 3, "codec" => "line" } }
|
54
|
+
|
55
|
+
let(:events) do
|
56
|
+
helper.input(subject, 8) do
|
57
|
+
client.send("line1\nline2")
|
58
|
+
client.send("line3\nline4")
|
59
|
+
client.send("line5\nline6\nline7\nline8")
|
60
|
+
end
|
61
|
+
end
|
49
62
|
|
63
|
+
before(:each) do
|
64
|
+
subject.register
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should receive events been generated" do
|
68
|
+
expect(events.size).to be(8)
|
69
|
+
messages = events.map { |event| event.get("message") }.sort # important to sort here because order is unpredictable
|
70
|
+
messages.each_index {|i| expect(messages[i]).to match("line#{i + 1}")}
|
71
|
+
end
|
50
72
|
end
|
51
73
|
|
52
74
|
it_behaves_like "an interruptible input plugin" do
|
53
|
-
|
75
|
+
# see https://github.com/elastic/logstash-devutils/blob/9c4a1fbf2b0c4547e428c5a40ed84f60aad17f97/lib/logstash/devutils/rspec/shared_examples.rb
|
54
76
|
end
|
55
|
-
end
|
77
|
+
end
|
data/spec/support/client.rb
CHANGED
@@ -4,7 +4,6 @@ require "socket"
|
|
4
4
|
module LogStash::Inputs::Test
|
5
5
|
|
6
6
|
class UDPClient
|
7
|
-
|
8
7
|
attr_reader :host, :port, :socket
|
9
8
|
|
10
9
|
def initialize(port)
|
@@ -14,24 +13,18 @@ module LogStash::Inputs::Test
|
|
14
13
|
socket.connect(host, port)
|
15
14
|
end
|
16
15
|
|
17
|
-
def send(msg
|
16
|
+
def send(msg)
|
18
17
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
socket.connect(host, port) if socket.closed?
|
19
|
+
socket.send(msg, 0)
|
20
|
+
rescue => e
|
21
|
+
puts("send exception, retrying", e.inspect)
|
22
22
|
retry
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def send(msg)
|
27
|
-
socket.connect(host, port) if socket.closed?
|
28
|
-
socket.send(msg, 0)
|
29
|
-
end
|
30
|
-
|
31
26
|
def close
|
32
|
-
socket.close
|
27
|
+
socket.close unless socket.closed?
|
33
28
|
end
|
34
|
-
|
35
29
|
end
|
36
|
-
|
37
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-udp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 0.0.22
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
name: logstash-codec-line
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
requirement: !ruby/object:Gem::Requirement
|
63
77
|
requirements:
|
@@ -114,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
128
|
version: '0'
|
115
129
|
requirements: []
|
116
130
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.6.
|
131
|
+
rubygems_version: 2.6.13
|
118
132
|
signing_key:
|
119
133
|
specification_version: 4
|
120
134
|
summary: Reads events over UDP
|