logstash-filter-json 3.0.1 → 3.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 -0
- data/lib/logstash/filters/json.rb +7 -2
- data/logstash-filter-json.gemspec +2 -2
- data/spec/filters/json_spec.rb +47 -0
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b6415ca4f107d636b1305a1cfa50f5fe6116a5
|
4
|
+
data.tar.gz: 4b1adb7d1a1b8c24fc464dfcdd055b4d0372115c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c4057279fe3c6911553fc383883bc41deaccaee6f3cad0f56298d451d2bcb870176aa9ea0cf24c81c98acf1b4b11b675803444d9a419e41fe80baa907472fae
|
7
|
+
data.tar.gz: aa96a6fd9b490b9967f62ef022ae380af6edd232a850f164496d81c41067623a5508c5b6fe6c3b00f3c35985c07aedc8c88d3e86e58896cbff54fc4e271c1a49
|
data/CHANGELOG.md
CHANGED
@@ -59,6 +59,9 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
59
59
|
# successful match
|
60
60
|
config :tag_on_failure, :validate => :array, :default => ["_jsonparsefailure"]
|
61
61
|
|
62
|
+
# Allow to skip filter on invalid json (allows to handle json and non-json data without warnings)
|
63
|
+
config :skip_on_invalid_json, :validate => :boolean, :default => false
|
64
|
+
|
62
65
|
def register
|
63
66
|
# Nothing to do here
|
64
67
|
end
|
@@ -72,8 +75,10 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
72
75
|
begin
|
73
76
|
parsed = LogStash::Json.load(source)
|
74
77
|
rescue => e
|
75
|
-
@
|
76
|
-
|
78
|
+
unless @skip_on_invalid_json
|
79
|
+
@tag_on_failure.each{|tag| event.tag(tag)}
|
80
|
+
@logger.warn("Error parsing json", :source => @source, :raw => source, :exception => e)
|
81
|
+
end
|
77
82
|
return
|
78
83
|
end
|
79
84
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-json'
|
4
|
-
s.version = '3.0.
|
4
|
+
s.version = '3.0.2'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This is a JSON parsing filter. It takes an existing field which contains JSON and expands it into an actual data structure within the Logstash event."
|
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"
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
|
-
s.add_runtime_dependency "logstash-core-plugin-api", "
|
23
|
+
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
24
|
|
25
25
|
s.add_development_dependency 'logstash-devutils'
|
26
26
|
end
|
data/spec/filters/json_spec.rb
CHANGED
@@ -175,4 +175,51 @@ describe LogStash::Filters::Json do
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
end
|
178
|
+
|
179
|
+
describe "parse mixture of json an non-json content (skip_on_invalid_json)" do
|
180
|
+
subject(:filter) { LogStash::Filters::Json.new(config) }
|
181
|
+
|
182
|
+
let(:config) { {"source" => "message", "remove_field" => ["message"], "skip_on_invalid_json" => skip_on_invalid_json} }
|
183
|
+
let(:event) { LogStash::Event.new("message" => message) }
|
184
|
+
|
185
|
+
before(:each) do
|
186
|
+
allow(filter.logger).to receive(:warn)
|
187
|
+
filter.register
|
188
|
+
filter.filter(event)
|
189
|
+
end
|
190
|
+
|
191
|
+
let(:message) { "this is not a json message" }
|
192
|
+
|
193
|
+
context "with `skip_on_invalid_json` set to false" do
|
194
|
+
let(:skip_on_invalid_json) { false }
|
195
|
+
|
196
|
+
it "sends a warning to the logger" do
|
197
|
+
expect(filter.logger).to have_received(:warn).with("Error parsing json", anything())
|
198
|
+
end
|
199
|
+
|
200
|
+
it "keeps the source field" do
|
201
|
+
expect(event.get("message")).to eq message
|
202
|
+
end
|
203
|
+
|
204
|
+
it "adds a parse-error tag" do
|
205
|
+
expect(event.get("tags")).to eq ["_jsonparsefailure"]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "with `skip_on_invalid_json` set to true" do
|
210
|
+
let(:skip_on_invalid_json) { true }
|
211
|
+
|
212
|
+
it "sends no warning" do
|
213
|
+
expect(filter.logger).to_not have_received(:warn)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "keeps the source field" do
|
217
|
+
expect(event.get("message")).to eq message
|
218
|
+
end
|
219
|
+
|
220
|
+
it "does not add a parse-error tag" do
|
221
|
+
expect(event.get("tags")).to be_nil
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
178
225
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
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-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
|
-
- - "
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.60'
|
19
|
+
- - "<="
|
17
20
|
- !ruby/object:Gem::Version
|
18
|
-
version: '2.
|
21
|
+
version: '2.99'
|
19
22
|
name: logstash-core-plugin-api
|
20
23
|
prerelease: false
|
21
24
|
type: :runtime
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.60'
|
30
|
+
- - "<="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
32
|
+
version: '2.99'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
29
35
|
requirements:
|
@@ -75,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
81
|
version: '0'
|
76
82
|
requirements: []
|
77
83
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.6.3
|
79
85
|
signing_key:
|
80
86
|
specification_version: 4
|
81
87
|
summary: This is a JSON parsing filter. It takes an existing field which contains JSON and expands it into an actual data structure within the Logstash event.
|