logstash-filter-record_split 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
+ SHA256:
3
+ metadata.gz: 816386d2a74de2fe87a6d34f76130b4f2f3beaca59a70bc2addeae994951810f
4
+ data.tar.gz: 14ac9c95a9d4302ff81f2b215f2a8f05dd761f65d30a0da390d7f3fbdd667e42
5
+ SHA512:
6
+ metadata.gz: 86ba5e4ded2772713efccce0a76a1989a989ac5f40e9ac054a262828065c82cff61d8c313cdee5912871f37bc0209c28155b44fe848d0f34e6e4c6ae22525986
7
+ data.tar.gz: c96c2e227050e17c65eeff1ad76d9276c8aeb8ef8b5f67fa65e79dad4fcd20c47d66676689faaa5baeaa418b3bb4a91faaa73f1e5dc71b73d8068ba28a0b8562
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
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
+ * -
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-record_split
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
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/logstash-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/logstash-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,75 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+
4
+ # This filter will replace the contents of the default
5
+ # message field with whatever you specify in the configuration.
6
+ #
7
+ # It is only intended to be used as an .
8
+ class LogStash::Filters::RecordSplit < LogStash::Filters::Base
9
+ PARSE_FAILURE_TAG = '_split_type_failure'.freeze
10
+ # Setting the config_name here is required. This is how you
11
+ # configure this filter from your Logstash config.
12
+ #
13
+ # filter {
14
+ # {
15
+ # message => "My message..."
16
+ # }
17
+ # }
18
+ #
19
+ config_name "record_split"
20
+
21
+ config :terminator, :validate => :string, :default => "\n"
22
+ config :field, :validate => :string, :default => "message"
23
+ config :target, :validate => :string
24
+
25
+
26
+ # Replace the message with this value.
27
+ config :message, :validate => :string, :default => "Hello World!"
28
+
29
+
30
+ public
31
+ def register
32
+ # Add instance variables
33
+ end # def register
34
+
35
+ public
36
+ def filter(event)
37
+ original_value = event.get(@field)
38
+
39
+ if original_value.is_a?(Array)
40
+ splits = @target.nil? ? event.remove(@field) : original_value
41
+ elsif original_value.is_a?(String)
42
+ # Using -1 for 'limit' on String#split makes ruby not drop trailing empty
43
+ # splits.
44
+ splits = original_value.split(@terminator, -1)
45
+ else
46
+ logger.warn("Only String and Array types are splittable. field:#{@field} is of type = #{original_value.class}")
47
+ event.tag(PARSE_FAILURE_TAG)
48
+ return
49
+ end
50
+
51
+ # Skip filtering if splitting this event resulted in only one thing found.
52
+ return if splits.length == 1 && original_value.is_a?(String)
53
+
54
+ # set event_target to @field if not configured
55
+ event_target = @target.nil? ? @field : @target
56
+ splits.each do |value|
57
+ next if value.nil? || (value.is_a?(String) && value.empty?)
58
+ @logger.debug? && @logger.debug("Split event", :value => value, :field => @field)
59
+
60
+ # OLD IMPLEMENTATION
61
+ # event_split = event.clone
62
+ # event_split.set(event_target, value)
63
+ # filter_matched(event_split)
64
+
65
+ event_split = LogStash::Event.new(value)
66
+ filter_matched(event_split)
67
+
68
+ # Push this new event onto the stack at the LogStash::FilterWorker
69
+ yield event_split
70
+ end
71
+
72
+ # Cancel this event, we'll use the newly generated ones above.
73
+ event.cancel
74
+ end
75
+ end # class LogStash::Filters::RecordSplit
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-record_split'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Logstash plugin to split array'
6
+ s.description = 'This plugin can split array'
7
+ s.homepage = 'https://rubygems.org/gems/logstash-filter-record_split'
8
+ s.authors = ['Ravi Shah']
9
+ s.email = 'ravi.shah@softwareag.com'
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-plugin-api", "~> 2.0"
22
+ s.add_development_dependency 'logstash-devutils'
23
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/record_split"
4
+
5
+ describe LogStash::Filters::RecordSplit do
6
+ describe "Set to Hello World" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ record_split {
10
+ message => "Hello World"
11
+ }
12
+ }
13
+ CONFIG
14
+ end
15
+
16
+ sample("message" => "some text") do
17
+ expect(subject).to include("message")
18
+ expect(subject.get('message')).to eq('Hello World')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-record_split
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ravi Shah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-14 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'
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: '2.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 plugin can split array
42
+ email: ravi.shah@softwareag.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CONTRIBUTORS
49
+ - DEVELOPER.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - lib/logstash/filters/record_split.rb
54
+ - logstash-filter-record_split.gemspec
55
+ - spec/filters/record_split_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: https://rubygems.org/gems/logstash-filter-record_split
58
+ licenses:
59
+ - Apache-2.0
60
+ metadata:
61
+ logstash_plugin: 'true'
62
+ logstash_group: filter
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.7.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Logstash plugin to split array
83
+ test_files:
84
+ - spec/filters/record_split_spec.rb
85
+ - spec/spec_helper.rb