logstash-filter-list2fields 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +0 -0
- data/CONTRIBUTORS +10 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +37 -0
- data/lib/logstash/filters/list2fields.rb +48 -0
- data/logstash-filter-list2fields.gemspec +27 -0
- data/spec/filters/list2filters_spec.rb +67 -0
- data/vendor/GeoIPASNum-2014-02-12.dat +0 -0
- data/vendor/GeoLiteCity-2013-01-18.dat +0 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9832818142f818906d8759e43dbc910d12f5e37f
|
4
|
+
data.tar.gz: 63aa2f896df825be60ffe05a4e2a6ed04c95c66d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d4417e96eec33160430d59e4eb4b54dc7b9aaa3cef9ef6aa59983410538ba59814ca54760c9a26d144898753fc1ceb7b9f29c4d61c34519fe408a4b66eee4ce
|
7
|
+
data.tar.gz: 17171e3a3477456cde677cc483979983b074ebfd8bdeab622d7889f310b0b7e175a8c131e9f0f34842dc521e59265054a78b45b3caed0ef2740ed8c85d863442
|
data/CHANGELOG.md
ADDED
File without changes
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,10 @@
|
|
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
|
+
* Inga Feick (ingafeick)
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 trivago <http://www.trivago.com>
|
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,37 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
|
4
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
5
|
+
|
6
|
+
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.
|
7
|
+
|
8
|
+
## Documentation
|
9
|
+
|
10
|
+
This filter rearranges key-value-pairs from the following structure
|
11
|
+
|
12
|
+
"awesome_list" => [ { "key" => "animal", "value" => "horse"} , {"key" => "food", "value" => "bacon"} ]
|
13
|
+
|
14
|
+
into separate logstash event fields:
|
15
|
+
|
16
|
+
"animal" => "horse"
|
17
|
+
"food" => "bacon"
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
* source : name of the field which contains the list of key value pairs (required). In the example above, this would be "awesome_list".
|
22
|
+
* key : name of the key for the key field in the list of key value pairs. Headache? Example: If this is your incoming data:
|
23
|
+
"awesome_list" => [ { "name" => "animal", "content" => "horse"} , {"name" => "food", "content" => "bacon"} ]
|
24
|
+
then the key would be "name". Optional, defaults to "key".
|
25
|
+
* value : name of the key for the value field in the list of key value pairs. In the above example, this would be "content". Optional, defaults to "value".
|
26
|
+
* prefix : string to prepend to the new fields that will be added to the logstash event. Optional, defaults to empty.
|
27
|
+
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
32
|
+
|
33
|
+
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.
|
34
|
+
|
35
|
+
It is more important to the community that you are able to contribute.
|
36
|
+
|
37
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
# TODO docu
|
6
|
+
class LogStash::Filters::List2fields < LogStash::Filters::Base
|
7
|
+
|
8
|
+
config_name "list2fields"
|
9
|
+
|
10
|
+
# The name of the field which contains the list of key value pairs
|
11
|
+
config :source, :validate => :string
|
12
|
+
|
13
|
+
# The name of the field which contains the key inside a list element
|
14
|
+
config :key, :validate => :string, :default => "key"
|
15
|
+
|
16
|
+
# The name of the field which contains the value inside a list element
|
17
|
+
config :value, :validate => :string, :default => "value"
|
18
|
+
|
19
|
+
# Prefix for the elements that will be added.
|
20
|
+
config :prefix, :validate => :string, :default => ""
|
21
|
+
|
22
|
+
public
|
23
|
+
def register
|
24
|
+
|
25
|
+
end # def register
|
26
|
+
|
27
|
+
public
|
28
|
+
def filter(event)
|
29
|
+
input = event[@source]
|
30
|
+
if !input.nil? && (input.is_a? Enumerable)
|
31
|
+
input.each do |entry|
|
32
|
+
begin
|
33
|
+
if entry.is_a?(::Hash)
|
34
|
+
new_key = @prefix.to_s + entry[@key].to_s
|
35
|
+
event[new_key] = entry[@value]
|
36
|
+
else
|
37
|
+
new_key = @prefix.to_s + entry.instance_variable_get("@" + @key)
|
38
|
+
event[new_key] = entry.instance_variable_get("@" + @value)
|
39
|
+
end # if is hash
|
40
|
+
rescue
|
41
|
+
@logger.debug("Could not find key " + @key + " in incoming data, please check your config. ")
|
42
|
+
end
|
43
|
+
end # do
|
44
|
+
end # if input.nil?
|
45
|
+
end # def filter
|
46
|
+
end # class LogStash::Filters::List2fields
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-filter-list2fields'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "$summary"
|
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"
|
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/**/*','vendor/**/*','*.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" => "filter" }
|
21
|
+
|
22
|
+
# Gem dependencies
|
23
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
|
24
|
+
|
25
|
+
s.add_development_dependency 'logstash-devutils'
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/filters/list2fields"
|
4
|
+
|
5
|
+
describe LogStash::Filters::List2fields do
|
6
|
+
|
7
|
+
let(:plugin) { LogStash::Filters::List2fields.new("source" => "message") }
|
8
|
+
|
9
|
+
before do
|
10
|
+
plugin.register
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when a prefix is set" do
|
14
|
+
|
15
|
+
let(:plugin_prefix) { LogStash::Filters::List2fields.new("source" => "message", "prefix" => "l2f_") } # TODO there's got to be a more beautiful way to do this
|
16
|
+
let(:event) { LogStash::Event.new("cheese" => "chili", "message" => [{"key"=>"foo","value"=>"bar"},{"key"=>"cheese","value"=>"bacon"}]) }
|
17
|
+
before do
|
18
|
+
plugin_prefix.filter(event)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have new fields with the prefix in the key" do
|
22
|
+
expect(event["l2f_foo"]).to eq("bar")
|
23
|
+
expect(event["l2f_cheese"]).to eq("bacon")
|
24
|
+
end # it
|
25
|
+
|
26
|
+
it "should not overwrite existing fields" do
|
27
|
+
expect(event["cheese"]).to eq("chili")
|
28
|
+
end # it
|
29
|
+
end # context
|
30
|
+
|
31
|
+
|
32
|
+
context "when the source field is empty" do
|
33
|
+
|
34
|
+
let(:event) { LogStash::Event.new() }
|
35
|
+
it "should not throw an exception" do
|
36
|
+
expect {
|
37
|
+
plugin.filter(event)
|
38
|
+
}.not_to raise_error
|
39
|
+
end # it
|
40
|
+
end # context
|
41
|
+
|
42
|
+
context "when the source field is not iterable" do
|
43
|
+
|
44
|
+
let(:event) { LogStash::Event.new("message" => "i_am_not_iterable" ) }
|
45
|
+
it "should not throw an exception" do
|
46
|
+
expect {
|
47
|
+
plugin.filter(event)
|
48
|
+
}.not_to raise_error
|
49
|
+
end # it
|
50
|
+
end # context
|
51
|
+
|
52
|
+
|
53
|
+
context "when there is a nested list" do
|
54
|
+
|
55
|
+
let(:event) { LogStash::Event.new("message" => [{"key"=>"foo","value"=>"bar"},{"key"=>"cheese","value"=>"bacon"}]) }
|
56
|
+
before do
|
57
|
+
plugin.filter(event)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have new fields" do
|
61
|
+
expect(event["foo"]).to eq("bar")
|
62
|
+
expect(event["cheese"]).to eq("bacon")
|
63
|
+
end # it
|
64
|
+
|
65
|
+
end # context
|
66
|
+
end # describe
|
67
|
+
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-list2fields
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elastic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0.beta2
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.0.0.beta2
|
28
|
+
- - <
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-devutils
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
|
+
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
|
48
|
+
email: info@elastic.co
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- CHANGELOG.md
|
54
|
+
- CONTRIBUTORS
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- NOTICE.TXT
|
58
|
+
- README.md
|
59
|
+
- lib/logstash/filters/list2fields.rb
|
60
|
+
- logstash-filter-list2fields.gemspec
|
61
|
+
- spec/filters/list2filters_spec.rb
|
62
|
+
- vendor/GeoIPASNum-2014-02-12.dat
|
63
|
+
- vendor/GeoLiteCity-2013-01-18.dat
|
64
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
65
|
+
licenses:
|
66
|
+
- Apache License (2.0)
|
67
|
+
metadata:
|
68
|
+
logstash_plugin: 'true'
|
69
|
+
logstash_group: filter
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.4.5
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: $summary
|
90
|
+
test_files:
|
91
|
+
- spec/filters/list2filters_spec.rb
|