logstash-filter-split-sbt 3.1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/CONTRIBUTORS +18 -0
- data/Gemfile +11 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +98 -0
- data/docs/index.asciidoc +111 -0
- data/lib/logstash/filters/split.rb +107 -0
- data/logstash-filter-split.gemspec +27 -0
- data/spec/filters/split_spec.rb +126 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 203fffeb050a4ecd74275d9853bff83a87993eb3
|
4
|
+
data.tar.gz: a77b5f73f945b93f0c7d74aae63b38b8f04cd8bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8e0ccd02ee69c6da6a9f378eae9d27126bde2198b4ce42dd1ca9151cca5287e2616ad5594852840463845609ac2aba7e3b33ff8e86dde62248e075428c8a3b2
|
7
|
+
data.tar.gz: 5940bae42224b8d88c6c36779f1e3a1e743a8aba97e06c13e8049cf139291a10627a5de7d48ed8ac688e1d8628eb427b901f48f2a4856b3e009efd166ba8a5ae
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
## 3.1.4
|
2
|
+
- Fix some documentation issues
|
3
|
+
|
4
|
+
## 3.1.3
|
5
|
+
- Improved performance by no longer cloning the source field if it is the same as the target field
|
6
|
+
## 3.1.1
|
7
|
+
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
|
8
|
+
|
9
|
+
## 3.1.0
|
10
|
+
- Log and tag attempts to split invalid types instead of crashing logstash
|
11
|
+
## 3.0.1
|
12
|
+
- Republish all the gems under jruby.
|
13
|
+
## 3.0.0
|
14
|
+
- 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
|
15
|
+
# 2.0.4
|
16
|
+
- Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
|
17
|
+
# 2.0.3
|
18
|
+
- New dependency requirements for logstash-core for the 5.0 release
|
19
|
+
## 2.0.0
|
20
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
21
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
22
|
+
- Dependency on logstash-core update to 2.0
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
* John E. Vincent (lusis)
|
7
|
+
* Jordan Sissel (jordansissel)
|
8
|
+
* Pete Fritchman (fetep)
|
9
|
+
* Philippe Weber (wiibaa)
|
10
|
+
* Pier-Hugues Pellerin (ph)
|
11
|
+
* R. Toma (rtoma)
|
12
|
+
* Richard Pijnenburg (electrical)
|
13
|
+
* Suyog Rao (suyograo)
|
14
|
+
|
15
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
16
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
17
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
18
|
+
open source awesome.
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
|
6
|
+
use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
|
7
|
+
|
8
|
+
if Dir.exist?(logstash_path) && use_logstash_source
|
9
|
+
gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
|
10
|
+
gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
|
11
|
+
end
|
data/LICENSE
ADDED
@@ -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.
|
data/NOTICE.TXT
ADDED
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-split.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-split)
|
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.
|
data/docs/index.asciidoc
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
:plugin: split
|
2
|
+
:type: filter
|
3
|
+
|
4
|
+
///////////////////////////////////////////
|
5
|
+
START - GENERATED VARIABLES, DO NOT EDIT!
|
6
|
+
///////////////////////////////////////////
|
7
|
+
:version: %VERSION%
|
8
|
+
:release_date: %RELEASE_DATE%
|
9
|
+
:changelog_url: %CHANGELOG_URL%
|
10
|
+
:include_path: ../../../../logstash/docs/include
|
11
|
+
///////////////////////////////////////////
|
12
|
+
END - GENERATED VARIABLES, DO NOT EDIT!
|
13
|
+
///////////////////////////////////////////
|
14
|
+
|
15
|
+
[id="plugins-{type}s-{plugin}"]
|
16
|
+
|
17
|
+
=== Split filter plugin
|
18
|
+
|
19
|
+
include::{include_path}/plugin_header.asciidoc[]
|
20
|
+
|
21
|
+
==== Description
|
22
|
+
|
23
|
+
The split filter clones an event by splitting one of its fields and
|
24
|
+
placing each value resulting from the split into a clone of the original
|
25
|
+
event. The field being split can either be a string or an array.
|
26
|
+
|
27
|
+
An example use case of this filter is for taking output from the
|
28
|
+
<<plugins-inputs-exec,exec input plugin>> which emits one event for
|
29
|
+
the whole output of a command and splitting that output by newline -
|
30
|
+
making each line an event.
|
31
|
+
|
32
|
+
Split filter can also be used to split array fields in events into individual events.
|
33
|
+
A very common pattern in JSON & XML is to make use of lists to group data together.
|
34
|
+
|
35
|
+
For example, a json structure like this:
|
36
|
+
|
37
|
+
[source,js]
|
38
|
+
----------------------------------
|
39
|
+
{ field1: ...,
|
40
|
+
results: [
|
41
|
+
{ result ... },
|
42
|
+
{ result ... },
|
43
|
+
{ result ... },
|
44
|
+
...
|
45
|
+
] }
|
46
|
+
----------------------------------
|
47
|
+
|
48
|
+
The split filter can be used on the above data to create separate events for each value of `results` field
|
49
|
+
|
50
|
+
[source,js]
|
51
|
+
----------------------------------
|
52
|
+
filter {
|
53
|
+
split {
|
54
|
+
field => "results"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
----------------------------------
|
58
|
+
|
59
|
+
The end result of each split is a complete copy of the event
|
60
|
+
with only the current split section of the given field changed.
|
61
|
+
|
62
|
+
[id="plugins-{type}s-{plugin}-options"]
|
63
|
+
==== Split Filter Configuration Options
|
64
|
+
|
65
|
+
This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
|
66
|
+
|
67
|
+
[cols="<,<,<",options="header",]
|
68
|
+
|=======================================================================
|
69
|
+
|Setting |Input type|Required
|
70
|
+
| <<plugins-{type}s-{plugin}-field>> |<<string,string>>|No
|
71
|
+
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
|
72
|
+
| <<plugins-{type}s-{plugin}-terminator>> |<<string,string>>|No
|
73
|
+
|=======================================================================
|
74
|
+
|
75
|
+
Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
|
76
|
+
filter plugins.
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
[id="plugins-{type}s-{plugin}-field"]
|
81
|
+
===== `field`
|
82
|
+
|
83
|
+
* Value type is <<string,string>>
|
84
|
+
* Default value is `"message"`
|
85
|
+
|
86
|
+
The field which value is split by the terminator.
|
87
|
+
Can be a multiline message or the ID of an array.
|
88
|
+
Nested arrays are referenced like: "[object_id][array_id]"
|
89
|
+
|
90
|
+
[id="plugins-{type}s-{plugin}-target"]
|
91
|
+
===== `target`
|
92
|
+
|
93
|
+
* Value type is <<string,string>>
|
94
|
+
* There is no default value for this setting.
|
95
|
+
|
96
|
+
The field within the new event which the value is split into.
|
97
|
+
If not set, the target field defaults to split field name.
|
98
|
+
|
99
|
+
[id="plugins-{type}s-{plugin}-terminator"]
|
100
|
+
===== `terminator`
|
101
|
+
|
102
|
+
* Value type is <<string,string>>
|
103
|
+
* Default value is `"\n"`
|
104
|
+
|
105
|
+
The string to split on. This is usually a line terminator, but can be any
|
106
|
+
string. If you are splitting a JSON array into multiple events, you can ignore this field.
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
[id="plugins-{type}s-{plugin}-common-options"]
|
111
|
+
include::{include_path}/{type}.asciidoc[]
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
# The split filter clones an event by splitting one of its fields and
|
6
|
+
# placing each value resulting from the split into a clone of the original
|
7
|
+
# event. The field being split can either be a string or an array.
|
8
|
+
#
|
9
|
+
# An example use case of this filter is for taking output from the
|
10
|
+
# <<plugins-inputs-exec,exec input plugin>> which emits one event for
|
11
|
+
# the whole output of a command and splitting that output by newline -
|
12
|
+
# making each line an event.
|
13
|
+
#
|
14
|
+
# Split filter can also be used to split array fields in events into individual events.
|
15
|
+
# A very common pattern in JSON & XML is to make use of lists to group data together.
|
16
|
+
#
|
17
|
+
# For example, a json structure like this:
|
18
|
+
#
|
19
|
+
# [source,js]
|
20
|
+
# ----------------------------------
|
21
|
+
# { field1: ...,
|
22
|
+
# results: [
|
23
|
+
# { result ... },
|
24
|
+
# { result ... },
|
25
|
+
# { result ... },
|
26
|
+
# ...
|
27
|
+
# ] }
|
28
|
+
# ----------------------------------
|
29
|
+
#
|
30
|
+
# The split filter can be used on the above data to create separate events for each value of `results` field
|
31
|
+
#
|
32
|
+
# [source,js]
|
33
|
+
# ----------------------------------
|
34
|
+
# filter {
|
35
|
+
# split {
|
36
|
+
# field => "results"
|
37
|
+
# }
|
38
|
+
# }
|
39
|
+
# ----------------------------------
|
40
|
+
#
|
41
|
+
# The end result of each split is a complete copy of the event
|
42
|
+
# with only the current split section of the given field changed.
|
43
|
+
class LogStash::Filters::Split < LogStash::Filters::Base
|
44
|
+
PARSE_FAILURE_TAG = '_split_type_failure'.freeze
|
45
|
+
|
46
|
+
config_name "split"
|
47
|
+
|
48
|
+
# The string to split on. This is usually a line terminator, but can be any
|
49
|
+
# string. If you are splitting a JSON array into multiple events, you can ignore this field.
|
50
|
+
config :terminator, :validate => :string, :default => "\n"
|
51
|
+
|
52
|
+
# The field which value is split by the terminator.
|
53
|
+
# Can be a multiline message or the ID of an array.
|
54
|
+
# Nested arrays are referenced like: "[object_id][array_id]"
|
55
|
+
config :field, :validate => :string, :default => "message"
|
56
|
+
|
57
|
+
# The field within the new event which the value is split into.
|
58
|
+
# If not set, the target field defaults to split field name.
|
59
|
+
config :target, :validate => :string
|
60
|
+
|
61
|
+
public
|
62
|
+
def register
|
63
|
+
# Nothing to do
|
64
|
+
end # def register
|
65
|
+
|
66
|
+
public
|
67
|
+
def filter(event)
|
68
|
+
|
69
|
+
|
70
|
+
original_value = event.get(@field)
|
71
|
+
|
72
|
+
if original_value.is_a?(Array)
|
73
|
+
splits = target.nil? ? event.remove(@field) : original_value
|
74
|
+
elsif original_value.is_a?(String)
|
75
|
+
# Using -1 for 'limit' on String#split makes ruby not drop trailing empty
|
76
|
+
# splits.
|
77
|
+
splits = original_value.split(@terminator, -1)
|
78
|
+
else
|
79
|
+
logger.warn("Only String and Array types are splittable. field:#{@field} is of type = #{original_value.class}")
|
80
|
+
event.tag(PARSE_FAILURE_TAG)
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
84
|
+
# Skip filtering if splitting this event resulted in only one thing found.
|
85
|
+
return if splits.length == 1 && original_value.is_a?(String)
|
86
|
+
#or splits[1].empty?
|
87
|
+
|
88
|
+
splits.each do |value|
|
89
|
+
next if value.nil? || value.empty?
|
90
|
+
|
91
|
+
event_split = event.clone
|
92
|
+
@logger.debug("Split event", :value => value, :field => @field)
|
93
|
+
if @target.nil?
|
94
|
+
event_split.set(@field, value)
|
95
|
+
else
|
96
|
+
event_split.set(@target, value)
|
97
|
+
end
|
98
|
+
filter_matched(event_split)
|
99
|
+
|
100
|
+
# Push this new event onto the stack at the LogStash::FilterWorker
|
101
|
+
yield event_split
|
102
|
+
end
|
103
|
+
|
104
|
+
# Cancel this event, we'll use the newly generated ones above.
|
105
|
+
event.cancel
|
106
|
+
end # def filter
|
107
|
+
end # class LogStash::Filters::Split
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-filter-split-sbt'
|
4
|
+
s.version = '3.1.4.1'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "The split filter is for splitting multiline messages into separate events."
|
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", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
|
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" => "filter" }
|
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
|
27
|
+
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/filters/split"
|
4
|
+
require "logstash/event"
|
5
|
+
|
6
|
+
describe LogStash::Filters::Split do
|
7
|
+
|
8
|
+
describe "all defaults" do
|
9
|
+
config <<-CONFIG
|
10
|
+
filter {
|
11
|
+
split { }
|
12
|
+
}
|
13
|
+
CONFIG
|
14
|
+
|
15
|
+
sample "big\nbird\nsesame street" do
|
16
|
+
insist { subject.length } == 3
|
17
|
+
insist { subject[0].get("message") } == "big"
|
18
|
+
insist { subject[1].get("message") } == "bird"
|
19
|
+
insist { subject[2].get("message") } == "sesame street"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "custome terminator" do
|
24
|
+
config <<-CONFIG
|
25
|
+
filter {
|
26
|
+
split {
|
27
|
+
terminator => "\t"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
CONFIG
|
31
|
+
|
32
|
+
sample "big\tbird\tsesame street" do
|
33
|
+
insist { subject.length } == 3
|
34
|
+
insist { subject[0].get("message") } == "big"
|
35
|
+
insist { subject[1].get("message") } == "bird"
|
36
|
+
insist { subject[2].get("message") } == "sesame street"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "custom field" do
|
41
|
+
config <<-CONFIG
|
42
|
+
filter {
|
43
|
+
split {
|
44
|
+
field => "custom"
|
45
|
+
}
|
46
|
+
}
|
47
|
+
CONFIG
|
48
|
+
|
49
|
+
sample("custom" => "big\nbird\nsesame street", "do_not_touch" => "1\n2\n3") do
|
50
|
+
insist { subject.length } == 3
|
51
|
+
subject.each do |s|
|
52
|
+
insist { s.get("do_not_touch") } == "1\n2\n3"
|
53
|
+
end
|
54
|
+
insist { subject[0].get("custom") } == "big"
|
55
|
+
insist { subject[1].get("custom") } == "bird"
|
56
|
+
insist { subject[2].get("custom") } == "sesame street"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "split array" do
|
61
|
+
config <<-CONFIG
|
62
|
+
filter {
|
63
|
+
split {
|
64
|
+
field => "array"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
CONFIG
|
68
|
+
|
69
|
+
sample("array" => ["big", "bird", "sesame street"], "untouched" => "1\n2\n3") do
|
70
|
+
insist { subject.length } == 3
|
71
|
+
subject.each do |s|
|
72
|
+
insist { s.get("untouched") } == "1\n2\n3"
|
73
|
+
end
|
74
|
+
insist { subject[0].get("array") } == "big"
|
75
|
+
insist { subject[1].get("array") } == "bird"
|
76
|
+
insist { subject[2].get("array") } == "sesame street"
|
77
|
+
end
|
78
|
+
|
79
|
+
sample("array" => ["big"], "untouched" => "1\n2\n3") do
|
80
|
+
insist { subject.is_a?(Logstash::Event) }
|
81
|
+
insist { subject.get("array") } == "big"
|
82
|
+
end
|
83
|
+
|
84
|
+
sample("array" => ["single-element"], "untouched" => "1\n2\n3") do
|
85
|
+
insist { subject.get("array") } == "single-element"
|
86
|
+
insist { subject.get("untouched") } == "1\n2\n3"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "split array into new field" do
|
91
|
+
config <<-CONFIG
|
92
|
+
filter {
|
93
|
+
split {
|
94
|
+
field => "array"
|
95
|
+
target => "element"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
CONFIG
|
99
|
+
|
100
|
+
sample("array" => ["big", "bird", "sesame street"]) do
|
101
|
+
insist { subject.length } == 3
|
102
|
+
insist { subject[0].get("element") } == "big"
|
103
|
+
insist { subject[1].get("element") } == "bird"
|
104
|
+
insist { subject[2].get("element") } == "sesame street"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when invalid type is passed" do
|
109
|
+
let(:filter) { LogStash::Filters::Split.new({"field" => "field"}) }
|
110
|
+
let(:logger) { filter.logger }
|
111
|
+
let(:event) { event = LogStash::Event.new("field" => 10) }
|
112
|
+
|
113
|
+
before do
|
114
|
+
allow(filter.logger).to receive(:warn).with(anything)
|
115
|
+
filter.filter(event)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should log an error" do
|
119
|
+
expect(filter.logger).to have_received(:warn).with(/Only String and Array types are splittable/)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should add a '_splitparsefailure' tag" do
|
123
|
+
expect(event.get("tags")).to include(LogStash::Filters::Split::PARSE_FAILURE_TAG)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-split-sbt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.1.4.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elastic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.60'
|
20
|
+
- - <=
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.99'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.60'
|
30
|
+
- - <=
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.99'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-devutils
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: This gem is a Logstash plugin required to be installed on top of the
|
48
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
49
|
+
gem is not a stand-alone program
|
50
|
+
email: info@elastic.co
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- lib/logstash/filters/split.rb
|
56
|
+
- spec/filters/split_spec.rb
|
57
|
+
- logstash-filter-split.gemspec
|
58
|
+
- CHANGELOG.md
|
59
|
+
- README.md
|
60
|
+
- CONTRIBUTORS
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE
|
63
|
+
- NOTICE.TXT
|
64
|
+
- docs/index.asciidoc
|
65
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
66
|
+
licenses:
|
67
|
+
- Apache License (2.0)
|
68
|
+
metadata:
|
69
|
+
logstash_plugin: 'true'
|
70
|
+
logstash_group: filter
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.0.14.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: The split filter is for splitting multiline messages into separate events.
|
91
|
+
test_files:
|
92
|
+
- spec/filters/split_spec.rb
|