logstash-filter-fieldmap 0.0.2

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: a252ea6441660da9c5c79041a1fead2ebd1e6759
4
+ data.tar.gz: de4ad626f2124376d50210aa910242d1d9eed5a5
5
+ SHA512:
6
+ metadata.gz: 472d273fb4c4a2939a897103cdb11e07f91d07b5805b81587806fb67d976dd1817198f16624422f8f79bde302615832921bd75fb0407bcc1a58cd501550d7155
7
+ data.tar.gz: b8dd07aa4910e4d9bfab2c5c0a60db7f506b86f0153660fc3940be42c968bd3eeacb8418d8d7dda1eeb10b68562308241c4170508e1d57a4a61a56da817da2c1
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## 0.0.2
2
+ - rescue if the field val has a { but isn't json. its kind of a crappy test
3
+
4
+ ## 0.0.1
5
+ - initial create
6
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped this logstash plugin along its way.
3
+
4
+ Contributors:
5
+ * Patrick Christopher (coffeepac)
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ this Logstash plugin, and you aren't on the list above and want to be, please let
9
+ us know and we'll make sure you're here. Contributions from folks like you are
10
+ what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,4 @@
1
+ # logstash-filter-fieldmap
2
+ Takes a constant list of fields and a target field in the event. Splits
3
+ the event by a specified sperator and then creates a dictionary field
4
+ where the constant list are the keys and the split string is the values.
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,86 @@
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
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ # This filter will split the src_field on delimiter and then
6
+ # create a map in the dst_field by pairing the elements of
7
+ # the keys config item with the values from the split src
8
+ # field.
9
+ #
10
+ # If the number of elements in the split src_field and the
11
+ # supplied keys is not the same the event will receive a tag
12
+ # and be sent along
13
+ #
14
+ class LogStash::Filters::FieldMap < LogStash::Filters::Base
15
+
16
+ # Setting the config_name here is required. This is how you
17
+ # configure this filter from your Logstash config.
18
+ #
19
+ # filter {
20
+ # fieldmap {
21
+ # src_field => 'message'
22
+ # dst_field => 'mapped_message'
23
+ # delimiter => ' '
24
+ # keys => ['KeyA', 'KeyB']
25
+ # }
26
+ # }
27
+ #
28
+ config_name "fieldmap"
29
+
30
+ # Field to use as source for map values
31
+ config :src_field, :validate => :string, :default => "message"
32
+
33
+ # Field to store processed values into.
34
+ # this filter will overwrite any data already in dst_field
35
+ config :dst_field, :validate => :string, :default => "mapped_message"
36
+
37
+ # Regex to split src_field by
38
+ config :regex, :validate => :string, :default => '[[:space:]]'
39
+
40
+ # List of keys to use in the dst map
41
+ config :keys, :validate => :array, :required => true
42
+
43
+ # Append value to the tag field when the mapping failed
44
+ config :map_failure, :validate => :string, :default => "_fieldmapfailed"
45
+ public
46
+ def register
47
+ # Add instance variables
48
+ end # def register
49
+
50
+ public
51
+ def filter(event)
52
+ @logger.debug? and @logger.debug("Running fieldmap filter", :event => event)
53
+
54
+ if event[@src_field]
55
+ # split the src field on delimiter then check if that length matches
56
+ # the key lenght, if not, explode
57
+ split_src = event[@src_field].split(/#{@regex}/)
58
+ @logger.debug? and @logger.debug("split_src is: ", :split_src => split_src)
59
+ if split_src.length == @keys.length
60
+ event[@dst_field] = {} # don't need to save off the source data, already split into split_src
61
+ idx = 0
62
+ split_src.map do |val|
63
+ val = val.strip
64
+ if val.include?('{')
65
+ begin
66
+ val = LogStash::Json.load(val.gsub("\\", ""))
67
+ rescue LogStash::Json::ParserError # if its not valid json leave it alone
68
+ end
69
+ end
70
+ event[@dst_field][@keys[idx]] = val
71
+ idx=idx+1
72
+ end
73
+ filter_matched(event)
74
+ else
75
+ event["tags"] ||= []
76
+ event["tags"] << @map_failure unless event["tags"].include?(@map_failure)
77
+ @logger.info? and @logger.info("Event failed field map")
78
+ end
79
+ end
80
+
81
+ @logger.debug? and @logger.debug("Event now: ", :event => event)
82
+
83
+ end # def filter
84
+ end # class LogStash::Filters::Example
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-fieldmap'
3
+ s.version = '0.0.2'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter will split the src_field on delimiter and then create a map in the dst_field by pairing the elements of the keys config item with the values from the split src field"
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 = ["Patrick Christopher"]
8
+ s.email = 'coffeepac@gmail.com'
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,46 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require "logstash/filters/fieldmap"
4
+
5
+ describe LogStash::Filters::FieldMap do
6
+ describe "Hello World Demo" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ fieldmap {
10
+ src_field => 'message'
11
+ dst_field => 'mapped_message'
12
+ regex => '[[:blank:]]'
13
+ keys => ['Greeting', 'Target']
14
+ }
15
+ }
16
+ CONFIG
17
+ end
18
+
19
+ sample("message" => "Hello World") do
20
+ expect(subject).to include("message")
21
+ expect(subject['mapped_message']).to eq({'Greeting' => 'Hello', 'Target' => 'World'})
22
+ end
23
+
24
+ sample("message" => "MazelTof {\"Hello\":\"World\"}") do
25
+ expect(subject['mapped_message']).to eq({'Greeting' => 'MazelTof', 'Target' => {'Hello' => 'World'}})
26
+ end
27
+ end
28
+
29
+ describe "Hello World Hate" do
30
+ let(:config) do <<-CONFIG
31
+ filter {
32
+ fieldmap {
33
+ src_field => 'message'
34
+ dst_field => 'mapped_message'
35
+ keys => ['Greeting', 'Target']
36
+ }
37
+ }
38
+ CONFIG
39
+ end
40
+
41
+ sample("message" => "Hello Haters") do
42
+ expect(subject).to include("message")
43
+ expect(subject['mapped_message']).to eq({'Greeting' => 'Hello', 'Target' => 'Haters'})
44
+ end
45
+ end
46
+ 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-fieldmap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Christopher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-30 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: coffeepac@gmail.com
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/fieldmap.rb
61
+ - logstash-filter-fieldmap.gemspec
62
+ - spec/filters/fieldmap_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 will split the src_field on delimiter and then create a map in the dst_field by pairing the elements of the keys config item with the values from the split src field
90
+ test_files:
91
+ - spec/filters/fieldmap_spec.rb
92
+ - spec/spec_helper.rb