logstash-input-beats 5.0.4-java → 5.0.5-java
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/VERSION +1 -1
- data/lib/logstash-input-beats_jars.rb +1 -1
- data/lib/logstash/inputs/beats/message_listener.rb +26 -9
- data/spec/inputs/beats/message_listener_spec.rb +81 -18
- data/vendor/jar-dependencies/org/logstash/beats/logstash-input-beats/{5.0.4/logstash-input-beats-5.0.4.jar → 5.0.5/logstash-input-beats-5.0.5.jar} +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8556139762c9123ccc0204ec083924778a39f246ac992dd5d9e477e98068e72
|
4
|
+
data.tar.gz: b30065ad1d79a5020baae07c8b8a980a76a82bc84fadaccce4a54af667859d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01fcf5bae4b075a0ea5c58905a77c712f3ec317ad5d27417c75749a33f590b5572f0a9fa0fbbdd29618537f2a4a565edd51802efb4d3fe7c3b3225e3746cbbc2
|
7
|
+
data.tar.gz: 2ba8917e5b5576c0166e6a18cdc6677bd47daaa9abb282386c736fd83de0e7eef1addaa95c37da43a9891761384bd176f80a577c3bc6616aebad1e41e7c759d0
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.0.
|
1
|
+
5.0.5
|
@@ -9,4 +9,4 @@ require_jar('com.fasterxml.jackson.core', 'jackson-annotations', '2.7.5')
|
|
9
9
|
require_jar('com.fasterxml.jackson.core', 'jackson-databind', '2.7.5')
|
10
10
|
require_jar('com.fasterxml.jackson.module', 'jackson-module-afterburner', '2.7.5')
|
11
11
|
require_jar('org.apache.logging.log4j', 'log4j-api', '2.6.2')
|
12
|
-
require_jar('org.logstash.beats', 'logstash-input-beats', '5.0.
|
12
|
+
require_jar('org.logstash.beats', 'logstash-input-beats', '5.0.5')
|
@@ -10,7 +10,7 @@ module LogStash module Inputs class Beats
|
|
10
10
|
FILEBEAT_LOG_LINE_FIELD = "message".freeze
|
11
11
|
LSF_LOG_LINE_FIELD = "line".freeze
|
12
12
|
|
13
|
-
ConnectionState = Struct.new(:ctx, :codec)
|
13
|
+
ConnectionState = Struct.new(:ctx, :codec, :ip_address)
|
14
14
|
|
15
15
|
attr_reader :logger, :input, :connections_list
|
16
16
|
|
@@ -27,14 +27,10 @@ module LogStash module Inputs class Beats
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def onNewMessage(ctx, message)
|
30
|
-
hash = message.getData
|
31
|
-
|
32
|
-
begin
|
33
|
-
hash.get("@metadata").put("ip_address", ctx.channel().remoteAddress().getAddress().getHostAddress())
|
34
|
-
rescue #should never happen, but don't allow an error here to stop beats input
|
35
|
-
input.logger.warn("Could not retrieve remote IP address for beats input.")
|
36
|
-
end
|
30
|
+
hash = message.getData
|
31
|
+
ip_address = ip_address(ctx)
|
37
32
|
|
33
|
+
hash['@metadata']['ip_address'] = ip_address unless ip_address.nil? || hash['@metadata'].nil?
|
38
34
|
target_field = extract_target_field(hash)
|
39
35
|
|
40
36
|
if target_field.nil?
|
@@ -83,8 +79,29 @@ module LogStash module Inputs class Beats
|
|
83
79
|
connections_list[ctx].codec
|
84
80
|
end
|
85
81
|
|
82
|
+
def ip_address(ctx)
|
83
|
+
return if connections_list[ctx].nil?
|
84
|
+
connections_list[ctx].ip_address
|
85
|
+
end
|
86
|
+
|
86
87
|
def register_connection(ctx)
|
87
|
-
connections_list[ctx] = ConnectionState.new(ctx, input.codec.dup)
|
88
|
+
connections_list[ctx] = ConnectionState.new(ctx, input.codec.dup, ip_address_from_ctx(ctx))
|
89
|
+
end
|
90
|
+
|
91
|
+
def ip_address_from_ctx(ctx)
|
92
|
+
begin
|
93
|
+
remote_address = ctx.channel.remoteAddress
|
94
|
+
# Netty allows remoteAddress to be nil, which can cause a lot of log entries - see
|
95
|
+
# https://github.com/logstash-plugins/logstash-input-beats/issues/269
|
96
|
+
if remote_address.nil?
|
97
|
+
input.logger.debug("Cannot retrieve remote IP address for beats input - remoteAddress is nil")
|
98
|
+
return nil
|
99
|
+
end
|
100
|
+
remote_address.getAddress.getHostAddress
|
101
|
+
rescue => e # This should not happen, but should not block the beats input
|
102
|
+
input.logger.warn("Could not retrieve remote IP address for beats input.", :error => e)
|
103
|
+
nil
|
104
|
+
end
|
88
105
|
end
|
89
106
|
|
90
107
|
def unregister_connection(ctx)
|
@@ -56,7 +56,11 @@ describe LogStash::Inputs::Beats::MessageListener do
|
|
56
56
|
let(:queue) { Queue.new }
|
57
57
|
let(:codec) { DummyCodec.new }
|
58
58
|
let(:input) { LogStash::Inputs::Beats.new({ "port" => 5555, "codec" => codec }) }
|
59
|
-
|
59
|
+
|
60
|
+
let(:ip_address) { "10.0.0.1" }
|
61
|
+
let(:remote_address) { OngoingMethodMock.new("getHostAddress", ip_address) }
|
62
|
+
let(:ctx) {OngoingMethodMock.new("remoteAddress", remote_address)}
|
63
|
+
|
60
64
|
let(:message) { MockMessage.new("abc", { "message" => "hello world"}) }
|
61
65
|
|
62
66
|
subject { described_class.new(queue, input) }
|
@@ -66,28 +70,54 @@ describe LogStash::Inputs::Beats::MessageListener do
|
|
66
70
|
end
|
67
71
|
|
68
72
|
context "onNewConnection" do
|
69
|
-
|
70
|
-
|
73
|
+
let(:second_ip_address) { "10.0.0.2" }
|
74
|
+
let(:second_ctx) {OngoingMethodMock.new("getHostAddress", second_ip_address)}
|
75
|
+
|
76
|
+
shared_examples 'a valid new connection' do
|
77
|
+
it "register the connection to the connection list" do
|
78
|
+
expect { subject.onNewConnection(second_ctx) }.to change { subject.connections_list.count }.by(1)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it_behaves_like 'a valid new connection'
|
83
|
+
|
84
|
+
context 'with a nil remote address' do
|
85
|
+
let(:second_ip_address) { nil}
|
86
|
+
|
87
|
+
it_behaves_like 'a valid new connection'
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when the channel throws retrieving remote address' do
|
91
|
+
before do
|
92
|
+
allow(second_ctx).to receive(:channel).and_raise('nope')
|
93
|
+
end
|
94
|
+
|
95
|
+
it_behaves_like 'a valid new connection'
|
71
96
|
end
|
72
97
|
|
73
98
|
describe "metrics" do
|
74
99
|
it "new connection should increment connection count" do
|
75
100
|
expect(subject).to receive(:increment_connection_count).once
|
76
|
-
subject.onNewConnection(
|
101
|
+
subject.onNewConnection(second_ctx)
|
77
102
|
end
|
78
103
|
|
79
104
|
describe "peak connections" do
|
105
|
+
let (:ctxes) { [1, 2, 3, 4].inject([]) do |result, element|
|
106
|
+
result << OngoingMethodMock.new("getHostAddress", "10.0.0.#{element}")
|
107
|
+
result
|
108
|
+
end
|
109
|
+
}
|
80
110
|
it "closing and open connections should keep highest count" do
|
81
111
|
expect(subject.instance_eval("@peak_connection_count").value).to eq(1)
|
82
|
-
subject.onNewConnection(
|
112
|
+
subject.onNewConnection(ctxes[0])
|
83
113
|
expect(subject.instance_eval("@peak_connection_count").value).to eq(2)
|
84
|
-
subject.onNewConnection(
|
114
|
+
subject.onNewConnection(ctxes[1])
|
85
115
|
expect(subject.instance_eval("@peak_connection_count").value).to eq(3)
|
86
|
-
subject.onConnectionClose(
|
116
|
+
subject.onConnectionClose(ctxes[1])
|
87
117
|
expect(subject.instance_eval("@peak_connection_count").value).to eq(3)
|
88
|
-
subject.onNewConnection(
|
118
|
+
subject.onNewConnection(ctxes[2])
|
89
119
|
expect(subject.instance_eval("@peak_connection_count").value).to eq(3)
|
90
|
-
subject.onNewConnection(
|
120
|
+
subject.onNewConnection(ctxes[3])
|
91
121
|
expect(subject.instance_eval("@peak_connection_count").value).to eq(4)
|
92
122
|
end
|
93
123
|
end
|
@@ -97,7 +127,7 @@ describe LogStash::Inputs::Beats::MessageListener do
|
|
97
127
|
|
98
128
|
context "onNewMessage" do
|
99
129
|
context "when the message is from filebeat" do
|
100
|
-
let(:message) { MockMessage.new("abc", { "message" => "hello world" } )}
|
130
|
+
let(:message) { MockMessage.new("abc", { "message" => "hello world", "@metadata" => {} } )}
|
101
131
|
|
102
132
|
it "extract the event" do
|
103
133
|
subject.onNewMessage(ctx, message)
|
@@ -107,7 +137,7 @@ describe LogStash::Inputs::Beats::MessageListener do
|
|
107
137
|
end
|
108
138
|
|
109
139
|
context "when the message is from LSF" do
|
110
|
-
let(:message) { MockMessage.new("abc", { "line" => "hello world" } )}
|
140
|
+
let(:message) { MockMessage.new("abc", { "line" => "hello world", '@metadata' => {} } )}
|
111
141
|
|
112
142
|
it "extract the event" do
|
113
143
|
subject.onNewMessage(ctx, message)
|
@@ -118,13 +148,15 @@ describe LogStash::Inputs::Beats::MessageListener do
|
|
118
148
|
|
119
149
|
context "when the message is from any libbeat" do
|
120
150
|
#Requires data modeled as Java, not Ruby since the actual code pulls from Java backed (Netty) object
|
121
|
-
data
|
122
|
-
|
123
|
-
|
124
|
-
|
151
|
+
let(:data) do
|
152
|
+
d = HashMap.new
|
153
|
+
d.put('@metadata', HashMap.new)
|
154
|
+
d.put('metric', 1)
|
155
|
+
d.put('name', "super-stats")
|
156
|
+
d
|
157
|
+
end
|
125
158
|
|
126
159
|
let(:message) { MockMessage.new("abc", data)}
|
127
|
-
let(:ctx) {OngoingMethodMock.new("getHostAddress", "10.0.0.1")}
|
128
160
|
|
129
161
|
it "extract the event" do
|
130
162
|
subject.onNewMessage(ctx, message)
|
@@ -132,10 +164,41 @@ describe LogStash::Inputs::Beats::MessageListener do
|
|
132
164
|
expect(event.get("message")).to be_nil
|
133
165
|
expect(event.get("metric")).to eq(1)
|
134
166
|
expect(event.get("name")).to eq("super-stats")
|
135
|
-
expect(event.get("[@metadata][ip_address]")).to eq(
|
167
|
+
expect(event.get("[@metadata][ip_address]")).to eq(ip_address)
|
136
168
|
end
|
137
|
-
end
|
138
169
|
|
170
|
+
context 'when the remote address is nil' do
|
171
|
+
let(:ctx) { OngoingMethodMock.new("remoteAddress", nil)}
|
172
|
+
|
173
|
+
it 'extracts the event' do
|
174
|
+
subject.onNewMessage(ctx, message)
|
175
|
+
event = queue.pop
|
176
|
+
expect(event.get("message")).to be_nil
|
177
|
+
expect(event.get("metric")).to eq(1)
|
178
|
+
expect(event.get("name")).to eq("super-stats")
|
179
|
+
expect(event.get("[@metadata][ip_address]")).to eq(nil)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when getting the remote address raises' do
|
184
|
+
let(:raising_ctx) { double("context")}
|
185
|
+
|
186
|
+
before do
|
187
|
+
allow(raising_ctx).to receive(:channel).and_raise("nope")
|
188
|
+
subject.onNewConnection(raising_ctx)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'extracts the event' do
|
192
|
+
subject.onNewMessage(raising_ctx, message)
|
193
|
+
event = queue.pop
|
194
|
+
expect(event.get("message")).to be_nil
|
195
|
+
expect(event.get("metric")).to eq(1)
|
196
|
+
expect(event.get("name")).to eq("super-stats")
|
197
|
+
expect(event.get("[@metadata][ip_address]")).to eq(nil)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
139
202
|
end
|
140
203
|
|
141
204
|
context "onException" do
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-beats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.5
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -266,7 +266,7 @@ files:
|
|
266
266
|
- vendor/jar-dependencies/io/netty/netty-tcnative-boringssl-static/1.1.33.Fork23/netty-tcnative-boringssl-static-1.1.33.Fork23.jar
|
267
267
|
- vendor/jar-dependencies/org/apache/logging/log4j/log4j-api/2.6.2/log4j-api-2.6.2.jar
|
268
268
|
- vendor/jar-dependencies/org/javassist/javassist/3.20.0-GA/javassist-3.20.0-GA.jar
|
269
|
-
- vendor/jar-dependencies/org/logstash/beats/logstash-input-beats/5.0.
|
269
|
+
- vendor/jar-dependencies/org/logstash/beats/logstash-input-beats/5.0.5/logstash-input-beats-5.0.5.jar
|
270
270
|
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
271
271
|
licenses:
|
272
272
|
- Apache License (2.0)
|