fluent-plugin-filter-list 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d59e0c9511bee9b07d913940698e10474ff94f71
4
- data.tar.gz: b40e7e4c5831ccdce088917b3bd3609cbbf83f2b
3
+ metadata.gz: 9ea3dab5080825c71ef4c5809764f0a677d46b2f
4
+ data.tar.gz: 1d3bee1125fba97deee08dff1f7337ed268b1a3d
5
5
  SHA512:
6
- metadata.gz: d83ac5416fd197ea9c556174eebc306441edc3ebe45d4b3b156c3eabe4b3db6da5efd8f3d1f284ed5c84c97980bb40e38be62448e1e013907514bbedc1d6719e
7
- data.tar.gz: 6b8fd6b97f2f30fbc98e5d95056fe56e9bb2558f353039af335cba9f090183fa7ef05c756406992f8f3ebe79d40578ce4309c35ce51754b67ce9a893d9ab246a
6
+ metadata.gz: c1325ec3086b46309c0e183b6059753ac9b298e9efb2a3c3ca55dcded59d6d0783f7b97c1f842a2116751c2e991b8a25ee92af8df1f2ffa5b22c30dfadc5a8de
7
+ data.tar.gz: bef22cada3e0ee5c7fc909c0e05b004fb7f2a724c5a7f1b6120fc86dcee2fb9a1e4f747caca1b0e20a070c889180ef6626c6f1e94525a9da2bada360d9df760c
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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
4
 
5
- [Fluentd](http://fluentd.org/) output plugin that filters messages whose value of specified field matches values in a list of patterns (like agrep). This plugin not only filters messages and discards them but also provides the feature to retag filtered records.
5
+ Want to filter fluentd messages containing black-listed words in the list effectively? Use the _fluent-plugin-filter-list_ plugin. The plugin enables you to filter messages in the list of words you provide. You can either discard such messages simply, or process them in a different flow by retagging them.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,13 +22,52 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ This repository contains two plugins: _Filter_ and _Output_, and expects two main use cases.
26
+
27
+ ### Filter plugin
28
+
29
+ Use the `filter_list` filter. Configure fluentd as follows.
30
+
31
+ ```
32
+ <filter pattern>
33
+ @type filter_list
34
+
35
+ key_to_filter xyz
36
+ patterns_file_path blacklist.txt
37
+ </filter>
38
+ ```
39
+
40
+ Given the `blacklist.txt` is as follows.
41
+
42
+ ```
43
+ foo
44
+ bar
45
+ buzz
46
+ ```
47
+
48
+ The following message is discarded since its `x` field contains the sequence of characters _bar_, contained in the list.
49
+
50
+ ```json
51
+ {"x":"halbart","y":1}
52
+ ```
53
+
54
+ While the following message is passed through as the target field specified in the config is not _y_ but _x_ .
55
+
56
+ ```json
57
+ {"x":1,"y":"halbart"}
25
58
  ```
26
- <match your_tag>
59
+
60
+ ### Output plugin
61
+
62
+ The other use case is to filter messages likewise, but process the filtered messages in a different tag. You need to configure the plugin to tell it how to retag both non-filtered messages and filtered messages. We provide two mutually-exclusive parameters: `tag` and `add_prefix`. THe `tag` parameter tells the plugin to retag the message with the value exactly provided by the parameter. The `add_prefix` parameter tells the plugin to retag the messages with the original tag prepended with the value you provide. So if the original message had a tag _foo_ and you set the `add_prefix` parameter _filtered_, then the processed message would have the tag _filtered.foo_ (note that the period before the original tag value is also prepended).
63
+
64
+ ```
65
+ <match pattern>
27
66
  @type filter_list
28
-
67
+
29
68
  key_to_filter field_name_you_want_to_filter
30
69
  patterns_file_path file_including_patterns_separated_by_new_line
31
-
70
+
32
71
  <retag>
33
72
  add_prefix x # retag non-filtered messages whose tag will be "x.your_tag"
34
73
  </retag>
@@ -7,7 +7,7 @@ require 'fluent/plugin/out_filter_list/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
9
  spec.name = 'fluent-plugin-filter-list'
10
- spec.version = Fluent::OutFilterList::VERSION
10
+ spec.version = Fluent::Plugin::FilterList::VERSION
11
11
  spec.authors = ['Shun Yanaura']
12
12
  spec.email = ['metroplexity@gmail.com']
13
13
 
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'rake', '~> 12.0'
28
28
  spec.add_development_dependency 'minitest', '~> 5.0'
29
29
  spec.add_development_dependency 'test-unit', '~> 3.2'
30
- spec.add_runtime_dependency 'fluentd', '~> 0.12', '>= 0.12.0'
30
+ spec.add_runtime_dependency 'fluentd', '~> 0.14', '>= 0.14.0'
31
31
  end
@@ -2,24 +2,26 @@ require 'fluent/plugin/out_filter_list/version'
2
2
  require 'aho_corasick'
3
3
 
4
4
  module Fluent
5
- class FilterListFilter < Filter
6
- include Matchers
5
+ module Plugin
6
+ class FilterListFilter < Filter
7
+ include Matchers
7
8
 
8
- Plugin.register_filter('filter_list', self)
9
+ Plugin.register_filter('filter_list', self)
9
10
 
10
- config_param :key_to_filter, :string, default: nil
11
- config_param :patterns_file_path, :string, default: ''
11
+ config_param :key_to_filter, :string, default: nil
12
+ config_param :patterns_file_path, :string, default: ''
12
13
 
13
- def configure(conf)
14
- super
15
- patterns = @patterns_file_path.empty? ? [] : File.readlines(@patterns_file_path).map(&:chomp).reject(&:empty?)
16
- @matcher = ACMatcher.new(patterns)
17
- end
14
+ def configure(conf)
15
+ super
16
+ patterns = @patterns_file_path.empty? ? [] : File.readlines(@patterns_file_path).map(&:chomp).reject(&:empty?)
17
+ @matcher = ACMatcher.new(patterns)
18
+ end
18
19
 
19
- def filter(_tag, _time, record)
20
- target = record[@key_to_filter]
21
- return nil if target && @matcher.matches?(target)
22
- record
20
+ def filter(_tag, _time, record)
21
+ target = record[@key_to_filter]
22
+ return nil if target && @matcher.matches?(target)
23
+ record
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -1,66 +1,75 @@
1
+ require 'fluent/plugin/output'
1
2
  require 'fluent/plugin/out_filter_list/version'
2
3
  require 'aho_corasick'
3
4
 
4
5
  module Fluent
5
- class FilterListOutput < Output
6
- include Matchers
6
+ module Plugin
7
+ class FilterListOutput < Output
8
+ include Matchers
7
9
 
8
- Plugin.register_output('filter_list', self)
10
+ Plugin.register_output('filter_list', self)
9
11
 
10
- config_param :key_to_filter, :string, default: nil
11
- config_param :patterns_file_path, :string, default: ''
12
+ helpers :event_emitter
12
13
 
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
14
+ config_param :key_to_filter, :string, default: nil
15
+ config_param :patterns_file_path, :string, default: ''
17
16
 
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
17
+ config_section :retag, required: true, multi: false do
18
+ config_param :tag, :string, default: nil
19
+ config_param :add_prefix, :string, default: nil
20
+ end
22
21
 
23
- def initialize
24
- super
25
- end
22
+ config_section :retag_filtered, param_name: :retag_for_filtered, required: false, multi: false do
23
+ config_param :tag, :string, default: nil
24
+ config_param :add_prefix, :string, default: nil
25
+ end
26
26
 
27
- def validate(retag)
28
- return unless retag
29
- raise Fluent::ConfigError, "missing tag and add_prefix" unless retag.tag || retag.add_prefix
30
- raise Fluent::ConfigError, "tag and add_prefix are mutually exclusive" if retag.tag && retag.add_prefix
31
- end
27
+ def initialize
28
+ super
29
+ end
32
30
 
33
- def configure_prefixes
34
- @prefix_for_filtered_tag = @retag_for_filtered.add_prefix + '.' if @retag_for_filtered && @retag_for_filtered.add_prefix
35
- @prefix_for_filtered_tag = @retag_for_filtered && @retag_for_filtered.add_prefix ? @retag_for_filtered.add_prefix + '.' : ''
36
- @prefix = @retag && @retag.add_prefix ? @retag.add_prefix + '.' : ''
37
- end
31
+ def validate(retag)
32
+ return unless retag
33
+ raise Fluent::ConfigError, "missing tag and add_prefix" unless retag.tag || retag.add_prefix
34
+ raise Fluent::ConfigError, "tag and add_prefix are mutually exclusive" if retag.tag && retag.add_prefix
35
+ end
38
36
 
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
- configure_prefixes
45
- log.debug "prefix: #{@prefix}, prefix_for_filtered_tag: #{@prefix_for_filtered_tag || ''}"
46
- end
37
+ def configure_prefixes
38
+ @prefix_for_filtered_tag = @retag_for_filtered.add_prefix + '.' if @retag_for_filtered && @retag_for_filtered.add_prefix
39
+ @prefix_for_filtered_tag = @retag_for_filtered && @retag_for_filtered.add_prefix ? @retag_for_filtered.add_prefix + '.' : ''
40
+ @prefix = @retag && @retag.add_prefix ? @retag.add_prefix + '.' : ''
41
+ end
42
+
43
+ def configure(conf)
44
+ super
45
+ [@retag, @retag_for_filtered].each { |c| validate c }
46
+ patterns = @patterns_file_path.empty? ? [] : File.readlines(@patterns_file_path).map(&:chomp).reject(&:empty?)
47
+ @matcher = ACMatcher.new(patterns)
48
+ configure_prefixes
49
+ log.debug "prefix: #{@prefix}, prefix_for_filtered_tag: #{@prefix_for_filtered_tag || ''}"
50
+ end
51
+
52
+ def multi_workers_ready?
53
+ true
54
+ end
47
55
 
48
- def emit(tag, es, _chain)
49
- es.each do |time, record|
50
- target = record[@key_to_filter]
51
- log.debug "target: #{target}"
52
- # Do filter
53
- if target && @matcher.matches?(target)
54
- if @retag_for_filtered
55
- tag = @retag_for_filtered.tag || ((tag && !tag.empty?) ? @prefix_for_filtered_tag + tag : @retag_for_filtered.add_prefix)
56
- log.debug "re-emit with tag: #{tag}"
57
- router.emit(tag, time, record)
56
+ def process(tag, es)
57
+ es.each do |time, record|
58
+ target = record[@key_to_filter]
59
+ log.debug "target: #{target}"
60
+ # Do filter
61
+ if target && @matcher.matches?(target)
62
+ if @retag_for_filtered
63
+ tag = @retag_for_filtered.tag || ((tag && !tag.empty?) ? @prefix_for_filtered_tag + tag : @retag_for_filtered.add_prefix)
64
+ log.debug "re-emit with tag: #{tag}"
65
+ router.emit(tag, time, record)
66
+ end
67
+ next
58
68
  end
59
- next
69
+ tag = @retag.tag || ((tag && !tag.empty?) ? @prefix + tag : @retag.add_prefix)
70
+ log.debug "re-emit with tag: #{tag}"
71
+ router.emit(tag, time, record)
60
72
  end
61
- tag = @retag.tag || ((tag && !tag.empty?) ? @prefix + tag : @retag.add_prefix)
62
- log.debug "re-emit with tag: #{tag}"
63
- router.emit(tag, time, record)
64
73
  end
65
74
  end
66
75
  end
@@ -1,5 +1,7 @@
1
1
  module Fluent
2
- module OutFilterList
3
- VERSION = "0.2.4"
2
+ module Plugin
3
+ module FilterList
4
+ VERSION = "0.3.0"
5
+ end
4
6
  end
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-filter-list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shun Yanaura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2017-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,20 +72,20 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.12'
75
+ version: '0.14'
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 0.12.0
78
+ version: 0.14.0
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - "~>"
84
84
  - !ruby/object:Gem::Version
85
- version: '0.12'
85
+ version: '0.14'
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 0.12.0
88
+ version: 0.14.0
89
89
  description: A fluentd output plugin to filter keywords from messages
90
90
  email:
91
91
  - metroplexity@gmail.com