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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ddf0449d8e4b3c20ad42da931a88623695222c346815463d100f184deb39a41
4
- data.tar.gz: bd1c0786156077172f52eb2998b86030ec8524ed341a8b17544942f5b662f69e
3
+ metadata.gz: f084e6137c8f48a2f6a912ccf2b114d1b6fcf2ef3acef94f32f2b16311846728
4
+ data.tar.gz: 80aaab59b6691d0150a01681e5a00abde796284a5f4c8866f11349c6925c9adb
5
5
  SHA512:
6
- metadata.gz: 191f3b6b17ae2d93c10d763fbe765bead21e1e6932986dd188a493d5e616245f2d9e6ec1956b3fbe29edfa9e3aa98a828d803b51fd12a18bd6fa860f26813700
7
- data.tar.gz: 0a7189b4d3249b2a249b263c5fdfe0180b164f633fa2d90a1ec9d979cbdd0e9b18a02ff3fd92e9addc351699188074e93bea1ef43630ac42e4b6d5aa8c6b597c
6
+ metadata.gz: 9b4a20d9872d279858c788e42bf147ce9f8cc85ac88950d409b72a5f38e321f522bf7651682f8c6d5453a50aad4237e3a6e2f983c031e3ab4b24f64142d8538a
7
+ data.tar.gz: d5db418ac041b5169c3173b1f92070955ace448791a4c6b03168a4123478d89d387a7a0c14a54ab9e288a57be0683080794571a149dcd7b9e21982980e4ef14a
@@ -1,3 +1,6 @@
1
+ ## 3.1.0
2
+ - Added better error handling, preventing some classes of malformed inputs from crashing the pipeline.
3
+
1
4
  ## 3.0.6
2
5
  - Updated documentation with some clarifications and fixes
3
6
 
@@ -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
- @tag_on_failure.each{|tag| event.tag(tag)}
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
- @tag_on_failure.each{|tag| event.tag(tag)}
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.6'
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"
@@ -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.6
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-02-04 00:00:00.000000000 Z
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