logstash-codec-json 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/lib/logstash/codecs/json.rb +10 -2
- data/logstash-codec-json.gemspec +1 -1
- data/spec/codecs/json_spec.rb +28 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9295eea7f1cd9ae7339dbc10ef81cf23b6ce1d36
|
4
|
+
data.tar.gz: bcd279ad1a9df82528d42ba132dd15bc4b824996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de6306fad4704d91654c976b9cbde23b4028c72d9053b581fbe75f194f1c9e357ac12b50bf39e07956894e72cc7d33cffe58c102906bbb4ab88b5dc449e630b
|
7
|
+
data.tar.gz: c4bc2c043c6df6643835cfffcb952165218ada149fc5ed9dbd37333ef9aa185a5ea610d41dad0eb854d722cdcbeee720f6fc78a861131889ac70390df87bda14
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/codecs/json.rb
CHANGED
@@ -4,7 +4,9 @@ require "logstash/util/charset"
|
|
4
4
|
require "logstash/json"
|
5
5
|
|
6
6
|
# This codec may be used to decode (via inputs) and encode (via outputs)
|
7
|
-
# full JSON messages.
|
7
|
+
# full JSON messages. If the data being sent is a JSON array at its root multiple events will be created (one per element).
|
8
|
+
#
|
9
|
+
# If you are streaming JSON messages delimited
|
8
10
|
# by '\n' then see the `json_lines` codec.
|
9
11
|
#
|
10
12
|
# Encoding will result in a compact JSON representation (no line terminators or indentation)
|
@@ -37,7 +39,13 @@ class LogStash::Codecs::JSON < LogStash::Codecs::Base
|
|
37
39
|
def decode(data)
|
38
40
|
data = @converter.convert(data)
|
39
41
|
begin
|
40
|
-
|
42
|
+
decoded = LogStash::Json.load(data)
|
43
|
+
if decoded.is_a?(Array)
|
44
|
+
decoded.each {|item| yield(LogStash::Event.new(item)) }
|
45
|
+
else
|
46
|
+
yield LogStash::Event.new(decoded)
|
47
|
+
end
|
48
|
+
|
41
49
|
rescue LogStash::Json::ParserError => e
|
42
50
|
@logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => data)
|
43
51
|
yield LogStash::Event.new("message" => data, "tags" => ["_jsonparsefailure"])
|
data/logstash-codec-json.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-codec-json'
|
4
|
-
s.version = '1.0.
|
4
|
+
s.version = '1.0.1'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This codec may be used to decode (via inputs) and encode (via outputs) full JSON messages"
|
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"
|
data/spec/codecs/json_spec.rb
CHANGED
@@ -52,6 +52,34 @@ describe LogStash::Codecs::JSON do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
context "processing JSON with an array root" do
|
56
|
+
let(:data) {
|
57
|
+
[
|
58
|
+
{"foo" => "bar"},
|
59
|
+
{"foo" => "baz"}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
let(:data_json) {
|
63
|
+
LogStash::Json.dump(data)
|
64
|
+
}
|
65
|
+
|
66
|
+
it "should yield multiple events" do
|
67
|
+
count = 0
|
68
|
+
subject.decode(data_json) do |event|
|
69
|
+
count += 1
|
70
|
+
end
|
71
|
+
expect(count).to eql(data.count)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should yield the correct objects" do
|
75
|
+
index = 0
|
76
|
+
subject.decode(data_json) do |event|
|
77
|
+
expect(event.to_hash).to include(data[index])
|
78
|
+
index += 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
55
83
|
context "processing weird binary blobs" do
|
56
84
|
it "falls back to plain text and doesn't crash (LOGSTASH-1595)" do
|
57
85
|
decoded = false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-codec-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.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-
|
11
|
+
date: 2015-07-14 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.
|
86
|
+
rubygems_version: 2.1.9
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: This codec may be used to decode (via inputs) and encode (via outputs) full JSON messages
|