logstash-input-fifo 0.9.0 → 0.9.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 +1 -1
- data/logstash-input-fifo.gemspec +6 -2
- data/vendor/bundle/jruby/1.9/cache/logstash-codec-json-3.0.2.gem +0 -0
- data/vendor/bundle/jruby/1.9/cache/logstash-codec-json_lines-3.0.2.gem +0 -0
- data/vendor/bundle/jruby/1.9/cache/logstash-codec-line-3.0.2.gem +0 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/CHANGELOG.md +37 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/CONTRIBUTORS +17 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/Gemfile +4 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/LICENSE +13 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/NOTICE.TXT +5 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/README.md +98 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/lib/logstash/codecs/json.rb +85 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/logstash-codec-json.gemspec +26 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json-3.0.2/spec/codecs/json_spec.rb +191 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/CHANGELOG.md +31 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/CONTRIBUTORS +19 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/Gemfile +4 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/LICENSE +13 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/NOTICE.TXT +5 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/README.md +98 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/lib/logstash/codecs/json_lines.rb +74 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/logstash-codec-json_lines.gemspec +29 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-json_lines-3.0.2/spec/codecs/json_lines_spec.rb +218 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/CHANGELOG.md +19 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/CONTRIBUTORS +15 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/Gemfile +4 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/LICENSE +13 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/NOTICE.TXT +5 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/README.md +98 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/lib/logstash/codecs/line.rb +60 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/logstash-codec-line.gemspec +27 -0
- data/vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/spec/codecs/line_spec.rb +106 -0
- data/vendor/bundle/jruby/1.9/specifications/logstash-codec-json-3.0.2.gemspec +36 -0
- data/vendor/bundle/jruby/1.9/specifications/logstash-codec-json_lines-3.0.2.gemspec +39 -0
- data/vendor/bundle/jruby/1.9/specifications/logstash-codec-line-3.0.2.gemspec +36 -0
- metadata +77 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adc22dd6b9efeb553652a01a49dea78f5f9093c3
|
4
|
+
data.tar.gz: ccc46684a8892f680de02c8e65ea9f2cb60ababd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 253983e008785b0acbb7d90fae3077b6c7eb9467cb1ad7103a879c0cc5405b6b7d478971c21718258b12bc627c15a416952e27e41a1e3b4d93f40ec597f42320
|
7
|
+
data.tar.gz: 1dd302dabb2a2fe7b8be7cae0e2b064f06e14f8f2c1805b9b1aefbdbc697145a59fcd48ed9772f6f781b12d222d066e19440b46ed4314be9cd1ba408e3c20f0b
|
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
## 0.9.
|
1
|
+
## 0.9.1
|
2
2
|
- Initial version of logstash-input-fifo
|
data/logstash-input-fifo.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-fifo'
|
3
|
-
s.version = '0.9.
|
3
|
+
s.version = '0.9.1'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = 'Read events out of a static file or from a named pipe'
|
6
6
|
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'
|
@@ -19,7 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
# Gem dependencies
|
21
21
|
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
22
|
-
s.add_runtime_dependency 'logstash-codec-
|
22
|
+
s.add_runtime_dependency 'logstash-codec-line'
|
23
23
|
s.add_runtime_dependency 'stud', '>= 0.0.22'
|
24
|
+
|
24
25
|
s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
|
26
|
+
s.add_development_dependency "logstash-codec-plain"
|
27
|
+
s.add_development_dependency "logstash-codec-json"
|
28
|
+
s.add_development_dependency "logstash-codec-json_lines"
|
25
29
|
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
## 3.0.2
|
2
|
+
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
|
3
|
+
|
4
|
+
## 3.0.1
|
5
|
+
- Republish all the gems under jruby.
|
6
|
+
## 3.0.0
|
7
|
+
- Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141
|
8
|
+
# 2.1.4
|
9
|
+
- Made 'Falling back to plain-text' log message an 'info' level log. This was
|
10
|
+
'error' for versions v2.1.0 through v2.1.3 (and was 'info' before that).
|
11
|
+
|
12
|
+
# 2.1.3
|
13
|
+
- Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
|
14
|
+
# 2.1.2
|
15
|
+
- New dependency requirements for logstash-core for the 5.0 release
|
16
|
+
## 2.1.1
|
17
|
+
- Properly require 'logstash/event' for use in unit tests
|
18
|
+
|
19
|
+
## 2.1.0
|
20
|
+
- Backward compatible support for `Event#from_json` method https://github.com/logstash-plugins/logstash-codec-json/pull/21
|
21
|
+
|
22
|
+
## 2.0.4
|
23
|
+
- Reduce the size of the gem by removing the vendor files
|
24
|
+
|
25
|
+
## 2.0.3
|
26
|
+
- fixed a spec, no change in functionality
|
27
|
+
|
28
|
+
## 2.0.0
|
29
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
30
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
31
|
+
- Dependency on logstash-core update to 2.0
|
32
|
+
|
33
|
+
## 1.1.0
|
34
|
+
- Handle scalar types (string/number) and be more defensive about crashable errors
|
35
|
+
|
36
|
+
## 1.0.1
|
37
|
+
- Handle JSON arrays at source root by emitting multiple events
|
@@ -0,0 +1,17 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Colin Surprenant (colinsurprenant)
|
6
|
+
* Jordan Sissel (jordansissel)
|
7
|
+
* João Duarte (jsvd)
|
8
|
+
* Kurt Hurtado (kurtado)
|
9
|
+
* Nick Ethier (nickethier)
|
10
|
+
* Pier-Hugues Pellerin (ph)
|
11
|
+
* Richard Pijnenburg (electrical)
|
12
|
+
* Tal Levy (talevy)
|
13
|
+
|
14
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
15
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
16
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
17
|
+
open source awesome.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-codec-json.svg)](https://travis-ci.org/logstash-plugins/logstash-codec-json)
|
4
|
+
|
5
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
|
+
|
7
|
+
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.
|
8
|
+
|
9
|
+
## Documentation
|
10
|
+
|
11
|
+
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/).
|
12
|
+
|
13
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
14
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
15
|
+
|
16
|
+
## Need Help?
|
17
|
+
|
18
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
19
|
+
|
20
|
+
## Developing
|
21
|
+
|
22
|
+
### 1. Plugin Developement and Testing
|
23
|
+
|
24
|
+
#### Code
|
25
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
26
|
+
|
27
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
28
|
+
|
29
|
+
- Install dependencies
|
30
|
+
```sh
|
31
|
+
bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Test
|
35
|
+
|
36
|
+
- Update your dependencies
|
37
|
+
|
38
|
+
```sh
|
39
|
+
bundle install
|
40
|
+
```
|
41
|
+
|
42
|
+
- Run tests
|
43
|
+
|
44
|
+
```sh
|
45
|
+
bundle exec rspec
|
46
|
+
```
|
47
|
+
|
48
|
+
### 2. Running your unpublished Plugin in Logstash
|
49
|
+
|
50
|
+
#### 2.1 Run in a local Logstash clone
|
51
|
+
|
52
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
53
|
+
```ruby
|
54
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
55
|
+
```
|
56
|
+
- Install plugin
|
57
|
+
```sh
|
58
|
+
# Logstash 2.3 and higher
|
59
|
+
bin/logstash-plugin install --no-verify
|
60
|
+
|
61
|
+
# Prior to Logstash 2.3
|
62
|
+
bin/plugin install --no-verify
|
63
|
+
|
64
|
+
```
|
65
|
+
- Run Logstash with your plugin
|
66
|
+
```sh
|
67
|
+
bin/logstash -e 'filter {awesome {}}'
|
68
|
+
```
|
69
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
70
|
+
|
71
|
+
#### 2.2 Run in an installed Logstash
|
72
|
+
|
73
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
74
|
+
|
75
|
+
- Build your plugin gem
|
76
|
+
```sh
|
77
|
+
gem build logstash-filter-awesome.gemspec
|
78
|
+
```
|
79
|
+
- Install the plugin from the Logstash home
|
80
|
+
```sh
|
81
|
+
# Logstash 2.3 and higher
|
82
|
+
bin/logstash-plugin install --no-verify
|
83
|
+
|
84
|
+
# Prior to Logstash 2.3
|
85
|
+
bin/plugin install --no-verify
|
86
|
+
|
87
|
+
```
|
88
|
+
- Start Logstash and proceed to test the plugin
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
93
|
+
|
94
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
95
|
+
|
96
|
+
It is more important to the community that you are able to contribute.
|
97
|
+
|
98
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/codecs/base"
|
3
|
+
require "logstash/util/charset"
|
4
|
+
require "logstash/json"
|
5
|
+
require "logstash/event"
|
6
|
+
|
7
|
+
# This codec may be used to decode (via inputs) and encode (via outputs)
|
8
|
+
# full JSON messages. If the data being sent is a JSON array at its root multiple events will be created (one per element).
|
9
|
+
#
|
10
|
+
# If you are streaming JSON messages delimited
|
11
|
+
# by '\n' then see the `json_lines` codec.
|
12
|
+
#
|
13
|
+
# Encoding will result in a compact JSON representation (no line terminators or indentation)
|
14
|
+
#
|
15
|
+
# If this codec recieves a payload from an input that is not valid JSON, then
|
16
|
+
# it will fall back to plain text and add a tag `_jsonparsefailure`. Upon a JSON
|
17
|
+
# failure, the payload will be stored in the `message` field.
|
18
|
+
class LogStash::Codecs::JSON < LogStash::Codecs::Base
|
19
|
+
config_name "json"
|
20
|
+
|
21
|
+
# The character encoding used in this codec. Examples include "UTF-8" and
|
22
|
+
# "CP1252".
|
23
|
+
#
|
24
|
+
# JSON requires valid UTF-8 strings, but in some cases, software that
|
25
|
+
# emits JSON does so in another encoding (nxlog, for example). In
|
26
|
+
# weird cases like this, you can set the `charset` setting to the
|
27
|
+
# actual encoding of the text and Logstash will convert it for you.
|
28
|
+
#
|
29
|
+
# For nxlog users, you may to set this to "CP1252".
|
30
|
+
config :charset, :validate => ::Encoding.name_list, :default => "UTF-8"
|
31
|
+
|
32
|
+
def register
|
33
|
+
@converter = LogStash::Util::Charset.new(@charset)
|
34
|
+
@converter.logger = @logger
|
35
|
+
end
|
36
|
+
|
37
|
+
def decode(data, &block)
|
38
|
+
parse(@converter.convert(data), &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def encode(event)
|
42
|
+
@on_event.call(event, event.to_json)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def from_json_parse(json, &block)
|
48
|
+
LogStash::Event.from_json(json).each { |event| yield event }
|
49
|
+
rescue LogStash::Json::ParserError => e
|
50
|
+
@logger.error("JSON parse error, original data now in message field", :error => e, :data => json)
|
51
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
52
|
+
end
|
53
|
+
|
54
|
+
def legacy_parse(json, &block)
|
55
|
+
decoded = LogStash::Json.load(json)
|
56
|
+
|
57
|
+
case decoded
|
58
|
+
when Array
|
59
|
+
decoded.each {|item| yield(LogStash::Event.new(item)) }
|
60
|
+
when Hash
|
61
|
+
yield LogStash::Event.new(decoded)
|
62
|
+
else
|
63
|
+
@logger.error("JSON codec is expecting array or object/map", :data => json)
|
64
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
65
|
+
end
|
66
|
+
rescue LogStash::Json::ParserError => e
|
67
|
+
@logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => json)
|
68
|
+
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
|
69
|
+
rescue StandardError => e
|
70
|
+
# This should NEVER happen. But hubris has been the cause of many pipeline breaking things
|
71
|
+
# If something bad should happen we just don't want to crash logstash here.
|
72
|
+
@logger.warn(
|
73
|
+
"An unexpected error occurred parsing JSON data",
|
74
|
+
:data => json,
|
75
|
+
:message => e.message,
|
76
|
+
:class => e.class.name,
|
77
|
+
:backtrace => e.backtrace
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
# keep compatibility with all v2.x distributions. only in 2.3 will the Event#from_json method be introduced
|
82
|
+
# and we need to keep compatibility for all v2 releases.
|
83
|
+
alias_method :parse, LogStash::Event.respond_to?(:from_json) ? :from_json_parse : :legacy_parse
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-codec-json'
|
4
|
+
s.version = '3.0.2'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "This codec may be used to decode (via inputs) and encode (via outputs) full JSON messages"
|
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"
|
8
|
+
s.authors = ["Elastic"]
|
9
|
+
s.email = 'info@elastic.co'
|
10
|
+
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
15
|
+
|
16
|
+
# Tests
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
# Special flag to let us know this is actually a logstash plugin
|
20
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
|
21
|
+
|
22
|
+
# Gem dependencies
|
23
|
+
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
|
+
|
25
|
+
s.add_development_dependency 'logstash-devutils'
|
26
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/codecs/json"
|
3
|
+
require "logstash/event"
|
4
|
+
require "logstash/json"
|
5
|
+
require "insist"
|
6
|
+
|
7
|
+
describe LogStash::Codecs::JSON do
|
8
|
+
subject do
|
9
|
+
LogStash::Codecs::JSON.new
|
10
|
+
end
|
11
|
+
|
12
|
+
shared_examples :codec do
|
13
|
+
|
14
|
+
context "#decode" do
|
15
|
+
it "should return an event from json data" do
|
16
|
+
data = {"foo" => "bar", "baz" => {"bah" => ["a","b","c"]}}
|
17
|
+
subject.decode(LogStash::Json.dump(data)) do |event|
|
18
|
+
insist { event.is_a? LogStash::Event }
|
19
|
+
insist { event.get("foo") } == data["foo"]
|
20
|
+
insist { event.get("baz") } == data["baz"]
|
21
|
+
insist { event.get("bah") } == data["bah"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be fast", :performance => true do
|
26
|
+
json = '{"message":"Hello world!","@timestamp":"2013-12-21T07:01:25.616Z","@version":"1","host":"Macintosh.local","sequence":1572456}'
|
27
|
+
iterations = 500000
|
28
|
+
count = 0
|
29
|
+
|
30
|
+
# Warmup
|
31
|
+
10000.times { subject.decode(json) { } }
|
32
|
+
|
33
|
+
start = Time.now
|
34
|
+
iterations.times do
|
35
|
+
subject.decode(json) do |event|
|
36
|
+
count += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
duration = Time.now - start
|
40
|
+
insist { count } == iterations
|
41
|
+
puts "codecs/json rate: #{"%02.0f/sec" % (iterations / duration)}, elapsed: #{duration}s"
|
42
|
+
end
|
43
|
+
|
44
|
+
context "processing plain text" do
|
45
|
+
it "falls back to plain text" do
|
46
|
+
decoded = false
|
47
|
+
subject.decode("something that isn't json") do |event|
|
48
|
+
decoded = true
|
49
|
+
insist { event.is_a?(LogStash::Event) }
|
50
|
+
insist { event.get("message") } == "something that isn't json"
|
51
|
+
insist { event.get("tags") }.include?("_jsonparsefailure")
|
52
|
+
end
|
53
|
+
insist { decoded } == true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "scalar values" do
|
58
|
+
shared_examples "given a value" do |value_arg|
|
59
|
+
context "where value is #{value_arg}" do
|
60
|
+
let(:value) { value_arg }
|
61
|
+
let(:event) { LogStash::Event.new(value) }
|
62
|
+
let(:value_json) { LogStash::Json.dump(value)}
|
63
|
+
let(:event) do
|
64
|
+
e = nil
|
65
|
+
subject.decode(value_json) do |decoded|
|
66
|
+
e = decoded
|
67
|
+
end
|
68
|
+
e
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should store the value in 'message'" do
|
72
|
+
expect(event.get("message")).to eql(value_json)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have the json parse failure tag" do
|
76
|
+
expect(event.get("tags")).to include("_jsonparsefailure")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
include_examples "given a value", 123
|
82
|
+
include_examples "given a value", "hello"
|
83
|
+
include_examples "given a value", "-1"
|
84
|
+
include_examples "given a value", " "
|
85
|
+
end
|
86
|
+
|
87
|
+
context "processing JSON with an array root" do
|
88
|
+
let(:data) {
|
89
|
+
[
|
90
|
+
{"foo" => "bar"},
|
91
|
+
{"foo" => "baz"}
|
92
|
+
]
|
93
|
+
}
|
94
|
+
let(:data_json) {
|
95
|
+
LogStash::Json.dump(data)
|
96
|
+
}
|
97
|
+
|
98
|
+
it "should yield multiple events" do
|
99
|
+
count = 0
|
100
|
+
subject.decode(data_json) do |event|
|
101
|
+
count += 1
|
102
|
+
end
|
103
|
+
expect(count).to eql(data.count)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should yield the correct objects" do
|
107
|
+
index = 0
|
108
|
+
subject.decode(data_json) do |event|
|
109
|
+
expect(event.to_hash).to include(data[index])
|
110
|
+
index += 1
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "processing weird binary blobs" do
|
116
|
+
it "falls back to plain text and doesn't crash (LOGSTASH-1595)" do
|
117
|
+
decoded = false
|
118
|
+
blob = (128..255).to_a.pack("C*").force_encoding("ASCII-8BIT")
|
119
|
+
subject.decode(blob) do |event|
|
120
|
+
decoded = true
|
121
|
+
insist { event.is_a?(LogStash::Event) }
|
122
|
+
insist { event.get("message").encoding.to_s } == "UTF-8"
|
123
|
+
end
|
124
|
+
insist { decoded } == true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when json could not be parsed" do
|
129
|
+
|
130
|
+
let(:message) { "random_message" }
|
131
|
+
|
132
|
+
it "add the failure tag" do
|
133
|
+
subject.decode(message) do |event|
|
134
|
+
expect(event).to include "tags"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "uses an array to store the tags" do
|
139
|
+
subject.decode(message) do |event|
|
140
|
+
expect(event.get('tags')).to be_a Array
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "add a json parser failure tag" do
|
145
|
+
subject.decode(message) do |event|
|
146
|
+
expect(event.get('tags')).to include "_jsonparsefailure"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "#encode" do
|
153
|
+
it "should return json data" do
|
154
|
+
data = {"foo" => "bar", "baz" => {"bah" => ["a","b","c"]}}
|
155
|
+
event = LogStash::Event.new(data)
|
156
|
+
got_event = false
|
157
|
+
subject.on_event do |e, d|
|
158
|
+
insist { d.chomp } == event.to_json
|
159
|
+
insist { LogStash::Json.load(d)["foo"] } == data["foo"]
|
160
|
+
insist { LogStash::Json.load(d)["baz"] } == data["baz"]
|
161
|
+
insist { LogStash::Json.load(d)["bah"] } == data["bah"]
|
162
|
+
got_event = true
|
163
|
+
end
|
164
|
+
subject.encode(event)
|
165
|
+
insist { got_event }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "forcing legacy parsing" do
|
171
|
+
it_behaves_like :codec do
|
172
|
+
before(:each) do
|
173
|
+
# stub codec parse method to force use of the legacy parser.
|
174
|
+
# this is very implementation specific but I am not sure how
|
175
|
+
# this can be tested otherwise.
|
176
|
+
allow(subject).to receive(:parse) do |data, &block|
|
177
|
+
subject.send(:legacy_parse, data, &block)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "default parser choice" do
|
184
|
+
# here we cannot force the use of the Event#from_json since if this test is run in the
|
185
|
+
# legacy context (no Java Event) it will fail but if in the new context, it will be picked up.
|
186
|
+
it_behaves_like :codec do
|
187
|
+
# do nothing
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|