logstash-codec-json 1.0.1 → 1.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
  SHA1:
3
- metadata.gz: 9295eea7f1cd9ae7339dbc10ef81cf23b6ce1d36
4
- data.tar.gz: bcd279ad1a9df82528d42ba132dd15bc4b824996
3
+ metadata.gz: f792b833b69b019e652f7cc595f3a8aab43e2261
4
+ data.tar.gz: f10764c4248cdfecd36ff9e54148139480f7bb29
5
5
  SHA512:
6
- metadata.gz: 6de6306fad4704d91654c976b9cbde23b4028c72d9053b581fbe75f194f1c9e357ac12b50bf39e07956894e72cc7d33cffe58c102906bbb4ab88b5dc449e630b
7
- data.tar.gz: c4bc2c043c6df6643835cfffcb952165218ada149fc5ed9dbd37333ef9aa185a5ea610d41dad0eb854d722cdcbeee720f6fc78a861131889ac70390df87bda14
6
+ metadata.gz: c28a3d92840520105f63da899c12bb4d4433ea9178d10e3a2d40d14842a40182cacb5d41c957a1982e8ef01b542ad775b7b531e59cd1f572d5fa59f60be349b7
7
+ data.tar.gz: 3305bb9be36a093ff7baeeae903fb39a8ddb29d94c665c763dfe245a74fe8e833c32e7ab42431bcf1faa6c26d4cba1d2fec978e8e90ea181b331bae4df39a215
data/CHANGELOG.md CHANGED
@@ -1,2 +1,4 @@
1
+ * 1.1.0
2
+ - Handle scalar types (string/number) and be more defensive about crashable errors
1
3
  * 1.0.1
2
4
  - Handle JSON arrays at source root by emitting multiple events
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -42,13 +42,24 @@ class LogStash::Codecs::JSON < LogStash::Codecs::Base
42
42
  decoded = LogStash::Json.load(data)
43
43
  if decoded.is_a?(Array)
44
44
  decoded.each {|item| yield(LogStash::Event.new(item)) }
45
- else
45
+ elsif decoded.is_a?(Hash)
46
46
  yield LogStash::Event.new(decoded)
47
+ else
48
+ @logger.info? && @logger.info("JSON codec received a scalar instead of an Arary or Object!", :data => data)
49
+ yield LogStash::Event.new("message" => data, "tags" => ["_jsonparsefailure"])
47
50
  end
48
51
 
49
52
  rescue LogStash::Json::ParserError => e
50
53
  @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => data)
51
54
  yield LogStash::Event.new("message" => data, "tags" => ["_jsonparsefailure"])
55
+ rescue StandardError => e
56
+ # This should NEVER happen. But hubris has been the cause of many pipeline breaking things
57
+ # If something bad should happen we just don't want to crash logstash here.
58
+ @logger.warn("An unexpected error occurred parsing input to JSON",
59
+ :input => data,
60
+ :message => e.message,
61
+ :class => e.class.name,
62
+ :backtrace => e.backtrace)
52
63
  end
53
64
  end # def decode
54
65
 
@@ -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.1'
4
+ s.version = '1.1.0'
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"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = `git ls-files`.split($\)
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -52,6 +52,36 @@ describe LogStash::Codecs::JSON do
52
52
  end
53
53
  end
54
54
 
55
+ describe "scalar values" do
56
+ shared_examples "given a value" do |value_arg|
57
+ context "where value is #{value_arg}" do
58
+ let(:value) { value_arg }
59
+ let(:event) { LogStash::Event.new(value) }
60
+ let(:value_json) { LogStash::Json.dump(value)}
61
+ let(:event) do
62
+ e = nil
63
+ subject.decode(value_json) do |decoded|
64
+ e = decoded
65
+ end
66
+ e
67
+ end
68
+
69
+ it "should store the value in 'message'" do
70
+ expect(event["message"]).to eql(value_json)
71
+ end
72
+
73
+ it "should have the json parse failure tag" do
74
+ expect(event["tags"]).to include("_jsonparsefailure")
75
+ end
76
+ end
77
+ end
78
+
79
+ include_examples "given a value", 123
80
+ include_examples "given a value", "hello"
81
+ include_examples "given a value", "-1"
82
+ include_examples "given a value", " "
83
+ end
84
+
55
85
  context "processing JSON with an array root" do
56
86
  let(:data) {
57
87
  [
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.1
4
+ version: 1.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: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -50,17 +50,15 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
- - .gitignore
53
+ - lib/logstash/codecs/json.rb
54
+ - spec/codecs/json_spec.rb
55
+ - logstash-codec-json.gemspec
56
+ - README.md
54
57
  - CHANGELOG.md
55
58
  - CONTRIBUTORS
56
59
  - Gemfile
57
60
  - LICENSE
58
61
  - NOTICE.TXT
59
- - README.md
60
- - Rakefile
61
- - lib/logstash/codecs/json.rb
62
- - logstash-codec-json.gemspec
63
- - spec/codecs/json_spec.rb
64
62
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
65
63
  licenses:
66
64
  - Apache License (2.0)
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- .bundle
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- @files=[]
2
-
3
- task :default do
4
- system("rake -T")
5
- end
6
-
7
- require "logstash/devutils/rake"