fluent-plugin-filter-list 0.2.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: 52c5a00e64374a2b7299e3f279b6cf70ead7af0e
4
+ data.tar.gz: c1b067e9b9319c1bfc71371f91b3fa3b7af1a3d4
5
+ SHA512:
6
+ metadata.gz: ffce82c944c72031923e98c2ad22d86653b16397f74b481a686290bcfe81c2ebcf50e16274553f65a09c25beb6acc1282898edc1e215e8619abd8d6f882cc6c6
7
+ data.tar.gz: 31cef37f016b9fb187fa202a2e022d52f7bc79816737d6215c2e6a5648051882c8a3bef51a2ff3ea347a2ebecfc1c37e853a99daa1beb26afda6b6b90065e2be
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ # Used by dotenv library to load environment variables.
2
+ # .env
3
+
4
+ ## Specific to RubyMotion:
5
+ .dat*
6
+ .repl_history
7
+ build/
8
+ *.bridgesupport
9
+ build-iPhoneOS/
10
+ build-iPhoneSimulator/
11
+
12
+ ## Specific to RubyMotion (use of CocoaPods):
13
+ #
14
+ # We recommend against adding the Pods directory to your .gitignore. However
15
+ # you should judge for yourself, the pros and cons are mentioned at:
16
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
17
+ #
18
+ # vendor/Pods/
19
+
20
+ ## Documentation cache and generated files:
21
+ /.yardoc/
22
+ /_yardoc/
23
+ /doc/
24
+ /rdoc/
25
+
26
+ ## Environment normalization:
27
+ /.bundle/
28
+ /vendor/bundle
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ Gemfile.lock
34
+ .ruby-version
35
+ .ruby-gemset
36
+ *.gem
37
+
38
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ - 2.3.3
5
+ - 2.4.1
6
+ before_install: gem update bundler
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at metroplexity@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-out_filter_list.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Shun Yanaura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # fluent-plugin-filter-list
2
+
3
+ [![Build Status](https://travis-ci.org/yanana/fluent-plugin-filter-list.svg?branch=master)](https://travis-ci.org/yanana/fluent-plugin-filter-list)
4
+
5
+ This is a plugin to filter for [Fluentd](http://fluentd.org/) ≧ v0.12.0.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fluent-plugin-out_filter_list'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fluent-plugin-out_filter_list
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-plugin-out_filter_list. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Fluent::Plugin::OutFilterList project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fluent-plugin-out_filter_list/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test' << 'lib'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/out_filter_list"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fluent/plugin/out_filter_list/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-filter-list"
8
+ spec.version = Fluent::Plugin::OutFilterList::VERSION
9
+ spec.authors = ["Shun Yanaura"]
10
+ spec.email = ["metroplexity@gmail.com"]
11
+
12
+ spec.summary = %q{A fluentd output plugin to filter keywords from messages}
13
+ spec.description = %q{A fluentd output plugin to filter keywords from messages}
14
+ spec.homepage = "https://github.com/yanana/fluent-plugin-filter-list"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 12.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "test-unit", "~> 3.2"
28
+ spec.add_runtime_dependency "fluentd", "~> 0.12", ">= 0.12.0"
29
+ end
@@ -0,0 +1,85 @@
1
+ module Matchers
2
+ class ACMatcher
3
+ attr_reader :trie
4
+
5
+ def initialize(patterns)
6
+ patterns = (patterns || []).compact.reject(&:empty?)
7
+ @trie = Trie.new patterns
8
+ end
9
+
10
+ def matches?(str)
11
+ node = @trie.root
12
+ str.split('').each do |char|
13
+ node = node.failure while node.children[char].nil? # Follow failure if it exists in case pattern doesn't match
14
+ node = node.children[char]
15
+ return true unless node.output.nil?
16
+ end
17
+ false
18
+ end
19
+ end
20
+
21
+ class Trie
22
+ attr_reader :root
23
+ def initialize(patterns)
24
+ @root = Node.new
25
+ @root.children.default = @root
26
+ patterns.each do |pattern|
27
+ insert(pattern)
28
+ end
29
+ build
30
+ end
31
+
32
+ def insert(pattern = '')
33
+ current_node = @root
34
+ pattern.split('').each_with_index do |char, i|
35
+ current_node = current_node.insert(char)
36
+ if i == pattern.length - 1
37
+ current_node.output = pattern
38
+ end
39
+ end
40
+ end
41
+
42
+ def new_queue
43
+ q = Queue.new
44
+ @root.children.values.each do |child|
45
+ q.push(child)
46
+ child.failure = @root # set root on root's children's failure
47
+ end
48
+ q
49
+ end
50
+
51
+ def build
52
+ # Update failure on each node.
53
+ # Search longest matching suffix (which becomes failure) by BFS. In case no matching suffix, root becomes failure.
54
+ q = new_queue
55
+ until q.empty?
56
+ cur_node = q.pop
57
+ cur_node.children.each do |char, child|
58
+ q.push(child)
59
+ detect_node = cur_node.failure || @root
60
+ while detect_node.children[char].nil?
61
+ detect_node = detect_node.failure
62
+ end
63
+ child.failure = detect_node.children[char]
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ class Node
70
+ attr_reader :children
71
+ attr_accessor :failure, :output
72
+
73
+ def initialize
74
+ @children = {}
75
+ @children.default = nil
76
+ @output = nil
77
+ @failure = nil
78
+ end
79
+
80
+ def insert(char)
81
+ @children[char] = Node.new unless @children.key?(char)
82
+ @children[char]
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,68 @@
1
+ require 'fluent/plugin/out_filter_list/version'
2
+ require 'aho_corasick'
3
+
4
+ module Fluent
5
+ class FilterListOutput < Output
6
+ include Matchers
7
+
8
+ Plugin.register_output('filter_list', self)
9
+
10
+ config_param :key_to_filter, :string, :default => nil
11
+ config_param :patterns_file_path, :string, :default => ''
12
+
13
+ config_section :retag, required: true, multi: false do
14
+ config_param :tag, :string, :default => nil
15
+ config_param :add_prefix, :string, :default => nil
16
+ end
17
+
18
+ config_section :retag_filtered, param_name: :retag_for_filtered, required: false, multi: false do
19
+ config_param :tag, :string, :default => nil
20
+ config_param :add_prefix, :string, :default => nil
21
+ end
22
+
23
+ def initialize
24
+ super
25
+ end
26
+
27
+ def validate(retag)
28
+ if !retag
29
+ return
30
+ end
31
+ if !(retag.tag || retag.add_prefix)
32
+ raise Fluent::ConfigError, "missing tag and add_prefix"
33
+ end
34
+ if retag.tag && retag.add_prefix
35
+ raise Fluent::ConfigError, "tag and add_prefix are mutually exclusive"
36
+ end
37
+ end
38
+
39
+ def configure(conf)
40
+ super
41
+ [@retag, @retag_for_filtered].each { |c| validate c }
42
+ patterns = @patterns_file_path.empty? ? [] : File.readlines(@patterns_file_path).map(&:chomp).reject(&:empty?)
43
+ @matcher = ACMatcher.new(patterns)
44
+ if @retag_for_filtered && @retag_for_filtered.add_prefix
45
+ @prefix_for_filtered_tag = @retag_for_filtered.add_prefix + "."
46
+ end
47
+ if @retag && @retag.add_prefix
48
+ @prefix = @retag.add_prefix + "."
49
+ end
50
+ end
51
+
52
+ def emit(tag, es, chain)
53
+ es.each do |time, record|
54
+ target = record[@key_to_filter]
55
+ # Do filter
56
+ if target && @matcher.matches?(target)
57
+ if @retag_for_filtered
58
+ tag = @retag_for_filtered.tag || ((tag && !tag.empty?) ? @prefix_for_filtered_tag + tag : @retag_for_filtered.add_prefix)
59
+ router.emit(tag, time, record)
60
+ end
61
+ next
62
+ end
63
+ tag = @retag.tag || ((tag && !tag.empty?) ? @prefix + tag : @retag.add_prefix)
64
+ router.emit(tag, time, record)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ module Fluent
2
+ module Plugin
3
+ module OutFilterList
4
+ VERSION = "0.2.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-filter-list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Shun Yanaura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fluentd
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 0.12.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '0.12'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 0.12.0
89
+ description: A fluentd output plugin to filter keywords from messages
90
+ email:
91
+ - metroplexity@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - CODE_OF_CONDUCT.md
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - fluent-plugin-out_filter_list.gemspec
106
+ - lib/aho_corasick.rb
107
+ - lib/fluent/plugin/out_filter_list.rb
108
+ - lib/fluent/plugin/out_filter_list/version.rb
109
+ homepage: https://github.com/yanana/fluent-plugin-filter-list
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.11
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: A fluentd output plugin to filter keywords from messages
133
+ test_files: []