File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -59,8 +59,8 @@ 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 quietly fall-back to plain-text (aka skip the filter without warnings and tags )
63
- config :fallback_mode , :validate => :boolean , :default => false
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
64
65
65
def register
66
66
# Nothing to do here
@@ -75,7 +75,7 @@ def filter(event)
75
75
begin
76
76
parsed = LogStash ::Json . load ( source )
77
77
rescue => e
78
- unless @fallback_mode
78
+ unless @skip_on_invalid_json
79
79
@tag_on_failure . each { |tag | event . tag ( tag ) }
80
80
@logger . warn ( "Error parsing json" , :source => @source , :raw => source , :exception => e )
81
81
end
Original file line number Diff line number Diff line change 176
176
end
177
177
end
178
178
179
- describe "parse mixture of json an non-json content (fallback mode )" do
179
+ describe "parse mixture of json an non-json content (skip_on_invalid_json )" do
180
180
subject ( :filter ) { LogStash ::Filters ::Json . new ( config ) }
181
181
182
- let ( :config ) { { "source" => "message" , "remove_field" => [ "message" ] , "fallback_mode " => fallback_mode } }
182
+ let ( :config ) { { "source" => "message" , "remove_field" => [ "message" ] , "skip_on_invalid_json " => skip_on_invalid_json } }
183
183
let ( :event ) { LogStash ::Event . new ( "message" => message ) }
184
184
185
185
before ( :each ) do
190
190
191
191
let ( :message ) { "this is not a json message" }
192
192
193
- context "with fallback_mode off " do
194
- let ( :fallback_mode ) { false }
193
+ context "with `skip_on_invalid_json` set to false " do
194
+ let ( :skip_on_invalid_json ) { false }
195
195
196
196
it "sends a warning to the logger" do
197
197
expect ( filter . logger ) . to have_received ( :warn ) . with ( "Error parsing json" , anything ( ) )
206
206
end
207
207
end
208
208
209
- context "with fallback_mode on " do
210
- let ( :fallback_mode ) { true }
209
+ context "with `skip_on_invalid_json` set to true " do
210
+ let ( :skip_on_invalid_json ) { true }
211
211
212
212
it "sends no warning" do
213
213
expect ( filter . logger ) . to_not have_received ( :warn )
You can’t perform that action at this time.
0 commit comments