logstash-filter-json 3.0.6 → 3.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/filters/json.rb +11 -2
- data/logstash-filter-json.gemspec +1 -1
- data/spec/filters/json_spec.rb +47 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f084e6137c8f48a2f6a912ccf2b114d1b6fcf2ef3acef94f32f2b16311846728
|
4
|
+
data.tar.gz: 80aaab59b6691d0150a01681e5a00abde796284a5f4c8866f11349c6925c9adb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4a20d9872d279858c788e42bf147ce9f8cc85ac88950d409b72a5f38e321f522bf7651682f8c6d5453a50aad4237e3a6e2f983c031e3ab4b24f64142d8538a
|
7
|
+
data.tar.gz: d5db418ac041b5169c3173b1f92070955ace448791a4c6b03168a4123478d89d387a7a0c14a54ab9e288a57be0683080794571a149dcd7b9e21982980e4ef14a
|
data/CHANGELOG.md
CHANGED
@@ -76,7 +76,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
76
76
|
parsed = LogStash::Json.load(source)
|
77
77
|
rescue => e
|
78
78
|
unless @skip_on_invalid_json
|
79
|
-
|
79
|
+
_do_tag_on_failure(event)
|
80
80
|
@logger.warn("Error parsing json", :source => @source, :raw => source, :exception => e)
|
81
81
|
end
|
82
82
|
return
|
@@ -86,7 +86,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
86
86
|
event.set(@target, parsed)
|
87
87
|
else
|
88
88
|
unless parsed.is_a?(Hash)
|
89
|
-
|
89
|
+
_do_tag_on_failure(event)
|
90
90
|
@logger.warn("Parsed JSON object/hash requires a target configuration option", :source => @source, :raw => source)
|
91
91
|
return
|
92
92
|
end
|
@@ -121,5 +121,14 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
121
121
|
filter_matched(event)
|
122
122
|
|
123
123
|
@logger.debug? && @logger.debug("Event after json filter", :event => event)
|
124
|
+
rescue => ex
|
125
|
+
meta = { :exception => ex.message, :source => @source, :raw => source}
|
126
|
+
meta[:backtrace] = ex.backtrace if logger.debug?
|
127
|
+
logger.warn('Exception caught in json filter', meta)
|
128
|
+
_do_tag_on_failure(event)
|
129
|
+
end
|
130
|
+
|
131
|
+
def _do_tag_on_failure(event)
|
132
|
+
@tag_on_failure.each { |tag| event.tag(tag) }
|
124
133
|
end
|
125
134
|
end
|
@@ -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.1.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Parses JSON events"
|
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"
|
data/spec/filters/json_spec.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "logstash/devutils/rspec/spec_helper"
|
4
4
|
require "logstash/filters/json"
|
5
5
|
require "logstash/timestamp"
|
6
|
+
require 'rubygems'
|
6
7
|
|
7
8
|
describe LogStash::Filters::Json do
|
8
9
|
|
@@ -59,6 +60,52 @@ describe LogStash::Filters::Json do
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
63
|
+
logstash_version = Gem::Version.create(LOGSTASH_CORE_VERSION)
|
64
|
+
|
65
|
+
if (Gem::Requirement.create('>= 7.0').satisfied_by?(logstash_version) ||
|
66
|
+
(Gem::Requirement.create('~> 6.4').satisfied_by?(logstash_version) && LogStash::SETTINGS.get('config.field_reference.parser') == 'STRICT'))
|
67
|
+
describe "unsupported field name using `target`" do
|
68
|
+
config <<-CONFIG
|
69
|
+
filter {
|
70
|
+
json {
|
71
|
+
# Parse message as JSON, store the results in the 'data' field'
|
72
|
+
source => "message"
|
73
|
+
target => "data"
|
74
|
+
tag_on_failure => ["_jsonparsefailure","_custom_failure_tag"]
|
75
|
+
}
|
76
|
+
}
|
77
|
+
CONFIG
|
78
|
+
|
79
|
+
sample '{"okay":true, "un[sup]]ported": "foo", "another": "okay"}' do
|
80
|
+
insist { subject.get("tags") }.include?("_jsonparsefailure")
|
81
|
+
insist { subject.get("tags") }.include?("_custom_failure_tag")
|
82
|
+
|
83
|
+
# it does not partially apply
|
84
|
+
insist { subject.include?('[data][okay]') } == false
|
85
|
+
insist { subject.include?('[data][another]') } == false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "unsupported field name without target" do
|
90
|
+
config <<-CONFIG
|
91
|
+
filter {
|
92
|
+
json {
|
93
|
+
# Parse message as JSON, store the results in the 'data' field'
|
94
|
+
source => "message"
|
95
|
+
tag_on_failure => ["_jsonparsefailure","_custom_failure_tag"]
|
96
|
+
}
|
97
|
+
}
|
98
|
+
CONFIG
|
99
|
+
|
100
|
+
sample '{"okay":true, "un[sup]]ported": "foo", "another": "okay"}' do
|
101
|
+
insist { subject.get("tags") }.include?("_jsonparsefailure")
|
102
|
+
insist { subject.get("tags") }.include?("_custom_failure_tag")
|
103
|
+
|
104
|
+
# we can make no guarantees about partial application in this case.
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
62
109
|
describe "fixing @timestamp (#pull 733)" do
|
63
110
|
config <<-CONFIG
|
64
111
|
filter {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.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: 2019-
|
11
|
+
date: 2019-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|