logstash-filter-merge 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ac277dd1fae14429ee2078017721842640e059e
4
+ data.tar.gz: a2f5515f7e6110b8136a12a4b7a7838c2656296c
5
+ SHA512:
6
+ metadata.gz: 49a58e441548318e47b60a836bdcdb421b68d12ffdbe202d8db7b047d46dbe7e36cd27e9bc4b8a01094f2745fb69ba4a1ff7bb96ce2014d85fb3e4eab4ec9f29
7
+ data.tar.gz: 6c24a8cfc3b373491a13c0f7776eb35f664ccd72511dc930b19d304a53404eeeeb76c44180194ab378b15e118e81f4304d1ac41217060a7f74adf8d046ab9726
data/BUILD.md ADDED
@@ -0,0 +1,96 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
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
+
7
+ ## Documentation
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.elastic.co/guide/en/logstash/current/).
10
+
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/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - 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).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ # Logstash 2.3 and higher
57
+ bin/logstash-plugin install --no-verify
58
+
59
+ # Prior to Logstash 2.3
60
+ bin/plugin install --no-verify
61
+
62
+ ```
63
+ - Run Logstash with your plugin
64
+ ```sh
65
+ bin/logstash -e 'filter {awesome {}}'
66
+ ```
67
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
68
+
69
+ #### 2.2 Run in an installed Logstash
70
+
71
+ 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:
72
+
73
+ - Build your plugin gem
74
+ ```sh
75
+ gem build logstash-filter-awesome.gemspec
76
+ ```
77
+ - Install the plugin from the Logstash home
78
+ ```sh
79
+ # Logstash 2.3 and higher
80
+ bin/logstash-plugin install --no-verify
81
+
82
+ # Prior to Logstash 2.3
83
+ bin/plugin install --no-verify
84
+
85
+ ```
86
+ - Start Logstash and proceed to test the plugin
87
+
88
+ ## Contributing
89
+
90
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
91
+
92
+ 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.
93
+
94
+ It is more important to the community that you are able to contribute.
95
+
96
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 1.0.0
2
+ - First release
3
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,12 @@
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
+ * Aaron Mildenstein (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+ * William Tisäter (tiwilliam)
8
+
9
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
10
+ Logstash, and you aren't on the list above and want to be, please let us know
11
+ and we'll make sure you're here. Contributions from folks like you are what make
12
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
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
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Logstash Merge Filter Documentation
2
+
3
+ [![Travis Build Status](https://travis-ci.org/tiwilliam/logstash-filter-merge.svg)](https://travis-ci.org/tiwilliam/logstash-filter-merge)
4
+ [![Gem Version](https://badge.fury.io/rb/logstash-filter-merge.svg)](https://badge.fury.io/rb/logstash-filter-merge)
5
+
6
+ This filter helps you to merge your fields.
7
+
8
+ ## Merge with root
9
+
10
+ ```
11
+ merge {
12
+ field => "something"
13
+ }
14
+ ```
15
+
16
+ ## Only merge new fields to root
17
+
18
+ ```
19
+ merge {
20
+ field => "something"
21
+ overwrite => false
22
+ }
23
+ ```
24
+
25
+ ## Merge with custom target
26
+
27
+ ```
28
+ merge {
29
+ field => "something"
30
+ target => "something_else"
31
+ }
32
+ ```
33
+
34
+ ## Merge only whitelisted keys
35
+
36
+ ```
37
+ merge {
38
+ field => "something"
39
+ whitelist => ["user_agent", "browser_family"]
40
+ }
41
+ ```
42
+
43
+ ## Filter options
44
+
45
+ * **field**
46
+
47
+ The source field to read data from.
48
+
49
+ * **target**
50
+
51
+ The field to merge source field with. Defaults to event root.
52
+
53
+ * **overwrite**
54
+
55
+ Overwrite target fields with source field. Defaults to `true`.
56
+
57
+ * **whitelist**
58
+
59
+ If source is a hash, only merge keys listed in this array. Disabled by default.
60
+
61
+ ## Changelog
62
+
63
+ You can read about all changes in [CHANGELOG.md](CHANGELOG.md).
64
+
65
+ ## Need help?
66
+
67
+ Need help? Try #logstash on freenode IRC or the [Logstash discussion forum](https://discuss.elastic.co/c/logstash).
68
+
69
+ ## Want to contribute?
70
+
71
+ Get started by reading [BUILD.md](BUILD.md).
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ class LogStash::Filters::Merge < LogStash::Filters::Base
6
+
7
+ config_name "merge"
8
+
9
+ # Field to read from.
10
+ config :field, :validate => :string, :required => true
11
+
12
+ # Field to merge with.
13
+ config :target, :validate => :string
14
+
15
+ # Overwrite target fields with source field.
16
+ config :overwrite, :validate => :boolean, :default => true
17
+
18
+ # Allows you to select which keys to merge from a hash.
19
+ config :whitelist, :validate => :array, :default => []
20
+
21
+ private
22
+ def hash_merge(target, source)
23
+ if source.is_a? Hash
24
+ if not target.is_a? Hash and @overwrite
25
+ target = {}
26
+ end
27
+
28
+ source.each do |source_key, source_value|
29
+ next if @whitelist.length > 0 and not @whitelist.include? source_key
30
+ next if target.include? source_key and not @overwrite
31
+
32
+ target[source_key] = source_value
33
+ end
34
+ else
35
+ if target.nil? or @overwrite
36
+ target = source
37
+ end
38
+ end
39
+
40
+ return target
41
+ end
42
+
43
+ public
44
+ def register
45
+ end
46
+
47
+ public
48
+ def filter(event)
49
+ value = event.get(@field)
50
+
51
+ if @target.nil?
52
+ hash_merge(event.to_hash, value)
53
+ else
54
+ event.set(@target, hash_merge(event.get(@target), value))
55
+ end
56
+
57
+ filter_matched(event)
58
+ end
59
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-merge'
3
+ s.version = '1.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter helps you merge fields."
6
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using `logstash-plugin install logstash-filter-base64`. This gem is not a stand-alone program"
7
+ s.authors = ["William Tisäter"]
8
+ s.email = 'william@defunct.cc'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
12
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
14
+
15
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
16
+
17
+ s.add_development_dependency 'logstash-devutils'
18
+ end
@@ -0,0 +1,126 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require "logstash/filters/merge"
4
+
5
+ describe LogStash::Filters::Merge do
6
+ describe "minimal config with hash" do
7
+ let(:config) { '''
8
+ filter {
9
+ merge {
10
+ field => "data"
11
+ }
12
+ }
13
+ ''' }
14
+
15
+ sample("data" => {"one" => 1, "two" => 2}, "three" => 3) do
16
+ expect(subject.get("one")).to eq(1)
17
+ expect(subject.get("two")).to eq(2)
18
+ expect(subject.get("three")).to eq(3)
19
+ end
20
+
21
+ sample("data" => {"one" => 1}, "one" => 0) do
22
+ expect(subject.get("one")).to eq(1)
23
+ end
24
+ end
25
+
26
+ describe "minimal config with whitelist" do
27
+ let(:config) { '''
28
+ filter {
29
+ merge {
30
+ field => "data"
31
+ whitelist => ["one"]
32
+ }
33
+ }
34
+ ''' }
35
+
36
+ sample("data" => {"one" => 1, "two" => 2}, "three" => 3) do
37
+ expect(subject.get("one")).to eq(1)
38
+ expect(subject.get("two")).to eq(nil)
39
+ expect(subject.get("three")).to eq(3)
40
+ end
41
+ end
42
+
43
+ describe "overwrite set to false with hash" do
44
+ let(:config) { '''
45
+ filter {
46
+ merge {
47
+ field => "data"
48
+ overwrite => false
49
+ }
50
+ }
51
+ ''' }
52
+
53
+ sample("data" => {"one" => 1, "two" => 2}, "three" => 3) do
54
+ expect(subject.get("one")).to eq(1)
55
+ expect(subject.get("two")).to eq(2)
56
+ expect(subject.get("three")).to eq(3)
57
+ end
58
+
59
+ sample("data" => {"one" => 1, "two" => 2}, "one" => 0) do
60
+ expect(subject.get("one")).to eq(0)
61
+ expect(subject.get("two")).to eq(2)
62
+ end
63
+ end
64
+
65
+ describe "target set to field with hash" do
66
+ let(:config) { '''
67
+ filter {
68
+ merge {
69
+ field => "data"
70
+ target => "target"
71
+ }
72
+ }
73
+ ''' }
74
+
75
+ sample("data" => {"one" => 1, "two" => 2}, "target" => 3) do
76
+ expect(subject.get("target")).to eq({"one" => 1, "two" => 2})
77
+ end
78
+
79
+ sample("data" => {"one" => 1, "two" => 2}, "target" => "testing") do
80
+ expect(subject.get("target")).to eq({"one" => 1, "two" => 2})
81
+ end
82
+
83
+ sample("data" => {"one" => 1, "two" => 2}, "target" => {"one" => 0, "three" => 3}) do
84
+ expect(subject.get("target")).to eq({"one" => 1, "two" => 2, "three" => 3})
85
+ end
86
+ end
87
+
88
+ describe "minimal config with integer" do
89
+ let(:config) { '''
90
+ filter {
91
+ merge {
92
+ field => "data"
93
+ target => "output"
94
+ }
95
+ }
96
+ ''' }
97
+
98
+ sample("data" => 1) do
99
+ expect(subject.get("output")).to eq(1)
100
+ end
101
+
102
+ sample("data" => 1, "output" => 0) do
103
+ expect(subject.get("output")).to eq(1)
104
+ end
105
+ end
106
+
107
+ describe "overwrite set to false with integer" do
108
+ let(:config) { '''
109
+ filter {
110
+ merge {
111
+ field => "data"
112
+ target => "output"
113
+ overwrite => false
114
+ }
115
+ }
116
+ ''' }
117
+
118
+ sample("data" => 1) do
119
+ expect(subject.get("output")).to eq(1)
120
+ end
121
+
122
+ sample("data" => 1, "output" => 0) do
123
+ expect(subject.get("output")).to eq(0)
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-merge
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - William Tisäter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-devutils
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using `logstash-plugin install logstash-filter-base64`. This gem is not a stand-alone program
42
+ email: william@defunct.cc
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - BUILD.md
48
+ - CHANGELOG.md
49
+ - CONTRIBUTORS
50
+ - Gemfile
51
+ - LICENSE
52
+ - NOTICE.TXT
53
+ - README.md
54
+ - lib/logstash/filters/merge.rb
55
+ - logstash-filter-merge.gemspec
56
+ - spec/filters/merge_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
59
+ licenses:
60
+ - Apache License (2.0)
61
+ metadata:
62
+ logstash_plugin: 'true'
63
+ logstash_group: filter
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: This filter helps you merge fields.
84
+ test_files:
85
+ - spec/filters/merge_spec.rb
86
+ - spec/spec_helper.rb