logstash-filter-de_dot 0.1.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: 40cd7fa6cd2b0e8d4bdc3c40dfda787d1f2cdf9e
4
+ data.tar.gz: 267194e821436b230dbb9d9e15be5aabd7a9e4bd
5
+ SHA512:
6
+ metadata.gz: 750bf7f0bd52fcf52652afb34603115906b2a5ec7f333991400fe7b8145014f18e5073ce092a10c0442076818db3cecc2dcababf109529419dd1ae95b9b026da
7
+ data.tar.gz: ab574e0eafe500541678d6e5d4c2f9e7286c741193b8742e748d6d84e9e4bd2402f5a3db6255a07462a2172815fb96a81e4b44a170fad1cc3c60a5ecc6eded4c
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Initial release
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
+ * Aaron Mildenstein (untergeek)
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/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-filter-de_dot
2
+ If any developer-centric advice will appear here, as needed.
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–2015 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,89 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-example-unit/)
5
+
6
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
+
8
+ 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.
9
+
10
+ ## Documentation
11
+
12
+ 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/).
13
+
14
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
15
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
16
+
17
+ ## Need Help?
18
+
19
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
20
+
21
+ ## Developing
22
+
23
+ ### 1. Plugin Developement and Testing
24
+
25
+ #### Code
26
+ - To get started, you'll need JRuby with the Bundler gem installed.
27
+
28
+ - 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).
29
+
30
+ - Install dependencies
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ #### Test
36
+
37
+ - Update your dependencies
38
+
39
+ ```sh
40
+ bundle install
41
+ ```
42
+
43
+ - Run tests
44
+
45
+ ```sh
46
+ bundle exec rspec
47
+ ```
48
+
49
+ ### 2. Running your unpublished Plugin in Logstash
50
+
51
+ #### 2.1 Run in a local Logstash clone
52
+
53
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
54
+ ```ruby
55
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
+ ```
57
+ - Install plugin
58
+ ```sh
59
+ bin/plugin install --no-verify
60
+ ```
61
+ - Run Logstash with your plugin
62
+ ```sh
63
+ bin/logstash -e 'filter {awesome {}}'
64
+ ```
65
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
66
+
67
+ #### 2.2 Run in an installed Logstash
68
+
69
+ 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:
70
+
71
+ - Build your plugin gem
72
+ ```sh
73
+ gem build logstash-filter-awesome.gemspec
74
+ ```
75
+ - Install the plugin from the Logstash home
76
+ ```sh
77
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
78
+ ```
79
+ - Start Logstash and proceed to test the plugin
80
+
81
+ ## Contributing
82
+
83
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
84
+
85
+ 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.
86
+
87
+ It is more important to the community that you are able to contribute.
88
+
89
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ # This filter _appears_ to rename fields by replacing `.` characters with a different
6
+ # separator. In reality, it's a somewhat expensive filter that has to copy the
7
+ # source field contents to a new destination field (whose name no longer contains
8
+ # dots), and then remove the corresponding source field.
9
+ #
10
+ # It should only be used if no other options are available.
11
+ class LogStash::Filters::De_dot < LogStash::Filters::Base
12
+
13
+ config_name "de_dot"
14
+
15
+ # Replace dots with this value.
16
+ config :separator, :validate => :string, :default => "_"
17
+
18
+ # If `nested` is _true_, then create sub-fields instead of replacing dots with
19
+ # a different separator.
20
+ config :nested, :validate => :boolean, :default => false
21
+
22
+ # The `fields` array should contain a list of known fields to act on.
23
+ # If undefined, all top-level fields will be checked. Sub-fields must be
24
+ # manually specified in the array. For example: `["field.suffix","[foo][bar.suffix]"]`
25
+ # will result in "field_suffix" and nested or sub field ["foo"]["bar_suffix"]
26
+ #
27
+ # WARNING: This is an expensive operation.
28
+ #
29
+ config :fields, :validate => :array
30
+
31
+
32
+ public
33
+ def register
34
+ raise ArgumentError, "de_dot: separator cannot be or contain '.'" unless (@separator =~ /\./).nil?
35
+ # Add instance variables here, if any
36
+ end # def register
37
+
38
+ private
39
+ def rename_field(event, fieldref)
40
+ @logger.debug? && @logger.debug("de_dot: preprocess", :event => event.to_hash.to_s)
41
+ if @separator == ']['
42
+ @logger.debug? && @logger.debug("de_dot: fieldref pre-process", :fieldref => fieldref)
43
+ fieldref = '[' + fieldref if fieldref[0] != '['
44
+ fieldref = fieldref + ']' if fieldref[-1] != ']'
45
+ @logger.debug? && @logger.debug("de_dot: fieldref bounding square brackets should exist now", :fieldref => fieldref)
46
+ end
47
+ @logger.debug? && @logger.debug("de_dot: source field reference", :fieldref => fieldref)
48
+ newref = fieldref.gsub('.', @separator)
49
+ @logger.debug? && @logger.debug("de_dot: replacement field reference", :newref => newref)
50
+ event[newref] = event[fieldref]
51
+ @logger.debug? && @logger.debug("de_dot: event with both new and old field references", :event => event.to_hash.to_s)
52
+ event.remove(fieldref)
53
+ @logger.debug? && @logger.debug("de_dot: postprocess", :event => event.to_hash.to_s)
54
+ end
55
+
56
+ public
57
+ def filter(event)
58
+ @separator = '][' if @nested
59
+ @logger.debug? && @logger.debug("de_dot: Replace dots with separator", :separator => @separator)
60
+ @fields = event.to_hash.keys if @fields.nil?
61
+ @logger.debug? && @logger.debug("de_dot: Act on these fields", :fields => @fields)
62
+ @fields.each { |ref| rename_field(event, ref) if !(ref =~ /\./).nil? }
63
+ filter_matched(event)
64
+ end # def filter
65
+ end # class LogStash::Filters::De_dot
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-de_dot'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter removes dots from field names and replaces them with a different separator."
6
+ 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"
7
+ s.authors = ["Elastic"]
8
+ s.email = 'info@elastic.co'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
22
+ s.add_development_dependency 'logstash-devutils'
23
+ end
@@ -0,0 +1,189 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require "logstash/filters/de_dot"
4
+
5
+ describe LogStash::Filters::De_dot do
6
+ let(:config) { { } }
7
+ subject { LogStash::Filters::De_dot.new(config) }
8
+
9
+ let(:attrs) { { } }
10
+ let(:event) { LogStash::Event.new(attrs) }
11
+
12
+ before(:each) do
13
+ subject.register
14
+ end
15
+
16
+ describe "Incorrect separator" do
17
+ let(:special) { LogStash::Filters::De_dot.new({ "separator" => "." }) }
18
+ it "should raise an exception if separator has a '.' in it" do
19
+ expect { special.register }.to raise_error(ArgumentError)
20
+ end
21
+ end
22
+
23
+ describe "Single field" do
24
+ let(:attrs) { { "foo.bar" => "pass" } }
25
+
26
+ it "should replace a dot with an underscore" do
27
+ subject.filter(event)
28
+ expect(event.to_hash.keys).not_to include('foo.bar')
29
+ expect(event['foo_bar']).to eq('pass')
30
+ end
31
+ end
32
+
33
+ describe "Single field with alternate separator" do
34
+ let(:config) { { "separator" => "___" } }
35
+ let(:attrs) { { "foo.bar" => "pass" } }
36
+
37
+ it "should replace a dot with an underscore" do
38
+ subject.filter(event)
39
+ expect(event.to_hash.keys).not_to include('foo.bar')
40
+ expect(event['foo___bar']).to eq('pass')
41
+ end
42
+ end
43
+
44
+ describe "Multiple fields" do
45
+ let(:attrs) { { "acme.roller.skates" => "coyote", "nodot" => "nochange" } }
46
+
47
+ it "should replace all dots with underscores" do
48
+ subject.filter(event)
49
+ expect(event.to_hash.keys).not_to include('acme.roller.skates')
50
+ expect(event['acme_roller_skates']).to eq('coyote')
51
+ end
52
+
53
+ it "should not change a field without dots" do
54
+ subject.filter(event)
55
+ expect(event.to_hash.keys).to include('nodot')
56
+ expect(event['nodot']).to eq('nochange')
57
+ end
58
+ end
59
+
60
+ describe "Multiple fields with underscores already" do
61
+ let(:attrs) { { "acme_roller.skates" => "coyote", "no_dot" => "nochange" } }
62
+
63
+ it "should replace all dots with underscores" do
64
+ subject.filter(event)
65
+ expect(event.to_hash.keys).not_to include('acme_roller.skates')
66
+ expect(event['acme_roller_skates']).to eq('coyote')
67
+ end
68
+
69
+ it "should not change a field without dots" do
70
+ subject.filter(event)
71
+ expect(event.to_hash.keys).to include('no_dot')
72
+ expect(event['no_dot']).to eq('nochange')
73
+ end
74
+ end
75
+
76
+ describe "Nested fields" do
77
+ let(:config) { { "nested" => true } }
78
+ let(:attrs) { { "acme.roller.skates" => "coyote", "nodot" => "nochange" } }
79
+
80
+ it "should convert dotted fields to sub-fields" do
81
+ subject.filter(event)
82
+ expect(event.to_hash.keys).not_to include('acme.roller.skates')
83
+ expect(event['[acme][roller][skates]']).to eq('coyote')
84
+ end
85
+
86
+ it "should not change a field without dots" do
87
+ subject.filter(event)
88
+ expect(event.to_hash.keys).to include('nodot')
89
+ expect(event['nodot']).to eq('nochange')
90
+ end
91
+ end
92
+
93
+ describe "Specific nested field" do
94
+ let(:config) { { "fields" => [ "[acme][roller.skates]" ] } }
95
+ let(:attrs) { { "acme" => { "roller.skates" => "coyote" }, "foo.bar" => "nochange" } }
96
+
97
+ it "should replace all dots with underscores within specified fields" do
98
+ subject.filter(event)
99
+ expect(event['acme']).not_to include('roller.skates')
100
+ expect(event['[acme][roller_skates]']).to eq('coyote')
101
+ end
102
+
103
+ it "should not change a field not listed, even with dots" do
104
+ subject.filter(event)
105
+ expect(event.to_hash.keys).to include('foo.bar')
106
+ expect(event['foo.bar']).to eq('nochange')
107
+ end
108
+ end
109
+
110
+ describe "Multiple specific nested fields" do
111
+ let(:config) {
112
+ {
113
+ "nested" => true,
114
+ "fields" => [ "[acme][roller.skates]", "foo.bar", "[a.b][c.d][e.f]" ]
115
+ }
116
+ }
117
+ let(:attrs) {
118
+ {
119
+ "acme" => { "roller.skates" => "coyote" },
120
+ "foo.bar" => "nochange",
121
+ "a.b" => { "c.d" => { "e.f" => "finally"} }
122
+ }
123
+ }
124
+
125
+ it "should replace all dots with underscores within specified fields" do
126
+ subject.filter(event)
127
+ expect(event['acme']).not_to include('roller.skates')
128
+ expect(event['[acme][roller][skates]']).to eq('coyote')
129
+ expect(event.to_hash.keys).not_to include('foo.bar')
130
+ expect(event['[foo][bar]']).to eq('nochange')
131
+ expect(event.to_hash.keys).not_to include('a.a')
132
+ expect(event['[a][b][c][d][e][f]']).to eq('finally')
133
+ end
134
+ end
135
+
136
+ describe "Specific nested fields with underscores already" do
137
+ let(:config) {
138
+ {
139
+ "fields" => [ "[acme][super.roller_skates]", "[field_with][no_dot]" ]
140
+ }
141
+ }
142
+ let(:attrs) {
143
+ {
144
+ "acme" => { "super.roller_skates" => "coyote" },
145
+ "field_with" => { "no_dot" => "nochange" }
146
+ }
147
+ }
148
+
149
+ it "should replace all dots with underscores" do
150
+ subject.filter(event)
151
+ expect(event["acme"]).not_to include('super.roller_skates')
152
+ expect(event['[acme][super_roller_skates']).to eq('coyote')
153
+ end
154
+
155
+ it "should not change a field without dots" do
156
+ subject.filter(event)
157
+ expect(event.to_hash.keys).to include('field_with')
158
+ expect(event['[field_with][no_dot]']).to eq('nochange')
159
+ end
160
+ end
161
+
162
+ describe "Further nesting specific nested fields with underscores already" do
163
+ let(:config) {
164
+ {
165
+ "nested" => true,
166
+ "fields" => [ "[acme][super.roller_skates]", "[field_with][no_dot]" ]
167
+ }
168
+ }
169
+ let(:attrs) {
170
+ {
171
+ "acme" => { "super.roller_skates" => "coyote" },
172
+ "field_with" => { "no_dot" => "nochange" }
173
+ }
174
+ }
175
+
176
+ it "should replace all dots with underscores" do
177
+ subject.filter(event)
178
+ expect(event["acme"]).not_to include('super.roller_skates')
179
+ expect(event['[acme][super][roller_skates']).to eq('coyote')
180
+ end
181
+
182
+ it "should not change a field without dots" do
183
+ subject.filter(event)
184
+ expect(event.to_hash.keys).to include('field_with')
185
+ expect(event['[field_with][no_dot]']).to eq('nochange')
186
+ end
187
+ end
188
+
189
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-de_dot
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: 2015-11-09 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: 2.0.0
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-devutils
40
+ prerelease: false
41
+ type: :development
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 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
+ - DEVELOPER.md
56
+ - Gemfile
57
+ - LICENSE
58
+ - NOTICE.TXT
59
+ - README.md
60
+ - lib/logstash/filters/de_dot.rb
61
+ - logstash-filter-de_dot.gemspec
62
+ - spec/filters/de_dot_spec.rb
63
+ - spec/spec_helper.rb
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.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: This filter removes dots from field names and replaces them with a different separator.
90
+ test_files:
91
+ - spec/filters/de_dot_spec.rb
92
+ - spec/spec_helper.rb