logstash-filter-json 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fae32f551c32adc1e999196a442b5b617024b3ea
4
- data.tar.gz: 205a5c85baa987762364f8951dd2f4e1bffa350b
3
+ metadata.gz: 27170e93f03822ec0da6420f92abea14b28301d4
4
+ data.tar.gz: 4486725015297d1aef4f49a1237a93e9754f9498
5
5
  SHA512:
6
- metadata.gz: 4db90f0a968c8651a712bc53c9f1c096095ab7581948c5f4e45b74e8655bf757dcf601154179d74a4c2791d5e20b16530c4e3feff2c1b5db85be7e5b882d43bd
7
- data.tar.gz: 6de51f87957d8e83659f4f885f421da77a63c3d6e4f00de92e87335059c0db969f50b45f7bf3e5459740ae01ca6c82579de1a21be8a4a2b8020e24a48e95406d
6
+ metadata.gz: 6def29af5bc608eff94091b35d28b6bd5070d9cec25a71aad9968b0ae3c4c62c65c639e538572dfa6b8e6aea2664ba0c00f10894acd34b8a7e97ef2b03ef380d
7
+ data.tar.gz: 35044d9e29c8136bdd73cb8a3d8edf5b1a6d91f3ef3041967b2abf0e367fa6364eb1c87630b0a2488bbf6624a4d1ea5ead03f4a54c82ed27ca40a946f49dc71a
@@ -62,24 +62,18 @@ class LogStash::Filters::Json < LogStash::Filters::Base
62
62
  # TODO(colin) this field merging stuff below should be handled in Event.
63
63
 
64
64
  source = event[@source]
65
- if @target.nil?
66
- # Default is to write to the root of the event.
67
- dest = event.to_hash
68
- else
69
- if @target == @source
70
- # Overwrite source
71
- dest = event[@target] = {}
72
- else
73
- dest = event[@target] ||= {}
74
- end
75
- end
76
65
 
77
66
  begin
78
- # TODO(sissel): Note, this will not successfully handle json lists
79
- # like your text is '[ 1,2,3 ]' json parser gives you an array (correctly)
80
- # which won't merge into a hash. If someone needs this, we can fix it
81
- # later.
82
- dest.merge!(LogStash::Json.load(source))
67
+ parsed = LogStash::Json.load(source)
68
+ # If your parsed JSON is an array, we can't merge, so you must specify a
69
+ # destination to store the JSON, so you will get an exception about
70
+ if parsed.kind_of?(Array) && @target.nil?
71
+ raise('Parsed JSON arrays must have a destination in the configuration')
72
+ elsif @target.nil?
73
+ event.to_hash.merge! parsed
74
+ else
75
+ event[@target] = parsed
76
+ end
83
77
 
84
78
  # If no target, we target the root of the event object. This can allow
85
79
  # you to overwrite @timestamp and this will typically happen for json
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-json'
4
- s.version = '1.0.0'
4
+ s.version = '1.0.1'
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/plugin install gemname. This gem is not a stand-alone program"
@@ -86,6 +86,23 @@ describe LogStash::Filters::Json do
86
86
  end
87
87
  end
88
88
 
89
+ describe "parse JSON array into target field" do
90
+ config <<-CONFIG
91
+ filter {
92
+ json {
93
+ # Parse message as JSON, store the results in the 'data' field'
94
+ source => "message"
95
+ target => "data"
96
+ }
97
+ }
98
+ CONFIG
99
+
100
+ sample '[ { "k": "v" }, { "l": [1, 2, 3] } ]' do
101
+ insist { subject["data"][0]["k"] } == "v"
102
+ insist { subject["data"][1]["l"].to_a } == [1,2,3] # to_a for JRuby + JrJacksom which creates Java ArrayList
103
+ end
104
+ end
105
+
89
106
  context "when json could not be parsed" do
90
107
 
91
108
  subject(:filter) { LogStash::Filters::Json.new(config) }
@@ -124,6 +141,14 @@ describe LogStash::Filters::Json do
124
141
  end
125
142
  end
126
143
 
127
- end
144
+ context "the JSON is an ArrayList" do
145
+
146
+ let(:message) { "[1, 2, 3]" }
128
147
 
148
+ it "adds the failure tag" do
149
+ expect(event['tags']).to include "_jsonparsefailure"
150
+ end
151
+ end
152
+
153
+ end
129
154
  end
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  requirements: []
85
85
  rubyforge_project:
86
- rubygems_version: 2.2.2
86
+ rubygems_version: 2.1.9
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  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.