logstash-filter-hashtree 6.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3b4c8faaed777caefd7eabc4087fbaf946010586fa69633f3c29098c5f9fc4e9
4
+ data.tar.gz: 8404bf6fe091b3f590d3ab2455d8a28ffef060cff161b8558eae2ba8aa08da4e
5
+ SHA512:
6
+ metadata.gz: a7bab3cc38e90ad88faf13580eb9304cb55cf80ce35ef4ea927b7d9a31daab5548601f6c14170795bfe1b2bf2c33d7caa92d7ab2256128e596fcb44feae1f94b
7
+ data.tar.gz: b31867537862aca57d7905d04648f2c7190841dced184511f1a1cf560204171e2cef69af63044763c6d37d6737bfa15217620df4f3be3040ddf2dd3b269a80ba
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -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
+ * Gunter Zeilinger (gunterze@gmail.com)
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.
@@ -0,0 +1,2 @@
1
+ # logstash-filter-hashtree
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.
@@ -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,76 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+
4
+ # Combine fingerprints of one field of consecutive messages.
5
+ class LogStash::Filters::Hashtree < LogStash::Filters::Base
6
+ config_name "hashtree"
7
+
8
+ # The name of the source field whose contents will be used
9
+ # to create the fingerprint.
10
+ config :source, :validate => :string, :default => 'message'
11
+
12
+ # The name of the field where the generated fingerprint will be stored.
13
+ # Any current contents of that field will be overwritten.
14
+ config :target, :validate => :string, :default => 'fingerprint'
15
+
16
+ # The name of the field where the fingerprint of the previous message will be stored.
17
+ # Any current contents of that field will be overwritten.
18
+ config :previous, :validate => :string, :default => 'fingerprint_previous'
19
+
20
+ # Path of the file where the generated fingerprint will be stored.
21
+ config :file, :validate => :string, :default => 'fingerprint.txt'
22
+
23
+ # The fingerprint method to use.
24
+ config :method, :validate => ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5'], :default => 'SHA1'
25
+
26
+ public
27
+ def register
28
+ # convert to symbol for faster comparisons
29
+ @method = @method.to_sym
30
+ end
31
+
32
+ public
33
+ def filter(event)
34
+ fingerprint = fingerprint(event.get(@source))
35
+ File.open(@file, File::RDWR|File::CREAT, 0644) {|f|
36
+ f.flock(File::LOCK_EX)
37
+ event.set(@previous, previous = f.read)
38
+ event.set(@target, combined = fingerprint(fingerprint + previous))
39
+ f.rewind
40
+ f.write(combined)
41
+ }
42
+ filter_matched(event)
43
+ end
44
+
45
+ def fingerprint(data)
46
+ # since OpenSSL::Digest instances aren't thread safe, we must ensure that
47
+ # each pipeline worker thread gets its own instance.
48
+ # Also, since a logstash pipeline may contain multiple fingerprint filters
49
+ # we must include the id in the thread local variable name, so that we can
50
+ # store multiple digest instances
51
+ digest_string = "digest-#{id}"
52
+ Thread.current[digest_string] ||= select_digest(@method)
53
+ digest = Thread.current[digest_string]
54
+ # in JRuby 1.7.11 outputs as ASCII-8BIT
55
+ digest.hexdigest(data.to_s).force_encoding(Encoding::UTF_8)
56
+ end
57
+
58
+ def select_digest(method)
59
+ case method
60
+ when :SHA1
61
+ OpenSSL::Digest::SHA1.new
62
+ when :SHA256
63
+ OpenSSL::Digest::SHA256.new
64
+ when :SHA384
65
+ OpenSSL::Digest::SHA384.new
66
+ when :SHA512
67
+ OpenSSL::Digest::SHA512.new
68
+ when :MD5
69
+ OpenSSL::Digest::MD5.new
70
+ else
71
+ # we really should never get here
72
+ raise(LogStash::ConfigurationError, "Unknown digest for method=#{method.to_s}")
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-hashtree'
3
+ s.version = '6.4.3'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Combine fingerprints of one field of consecutive messages'
6
+ s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program.'
7
+ s.homepage = 'https://github.com/dcm4che/logstash-filter-hashtree'
8
+ s.authors = ['Gunter Zeilinger']
9
+ s.email = 'gunterze@gmail.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,25 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/hashtree"
4
+
5
+ describe LogStash::Filters::Hashtree do
6
+ describe "Set to Hello World" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ hashtree {
10
+ target => "current"
11
+ previous => "previous"
12
+ file => "file.txt"
13
+ }
14
+ }
15
+ CONFIG
16
+ end
17
+
18
+ sample("message" => "some text") do
19
+ File.write('file.txt','37aa63c77398d954473262e1a0057c1e632eda77')
20
+ expect(subject).to include("message")
21
+ expect(subject.get('previous')).to eq('37aa63c77398d954473262e1a0057c1e632eda77')
22
+ expect(subject.get('current')).to eq('9c3a0b7800edb149bada08a999b16f7bdd9388db')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-hashtree
3
+ version: !ruby/object:Gem::Version
4
+ version: 6.4.3
5
+ platform: ruby
6
+ authors:
7
+ - Gunter Zeilinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-17 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 gem is a logstash plugin required to be installed on top of the
42
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
43
+ gem is not a stand-alone program.
44
+ email: gunterze@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - CONTRIBUTORS
51
+ - DEVELOPER.md
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - lib/logstash/filters/hashtree.rb
56
+ - logstash-filter-hashtree.gemspec
57
+ - spec/filters/hashtree_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/dcm4che/logstash-filter-hashtree
60
+ licenses:
61
+ - Apache-2.0
62
+ metadata:
63
+ logstash_plugin: 'true'
64
+ logstash_group: filter
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.7.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Combine fingerprints of one field of consecutive messages
85
+ test_files:
86
+ - spec/filters/hashtree_spec.rb
87
+ - spec/spec_helper.rb