fluent-plugin-filter 0.0.3 → 0.0.4

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: 64a2e9dee2d826e3d964fa0d58d3cb33bd9ddef1
4
- data.tar.gz: 313910f1c212e5c4f35b1146660a7b2056ffedf6
3
+ metadata.gz: 215960b8db1dca534d808e0913b522ca527c6457
4
+ data.tar.gz: 81761e8e0861c39afa42fe64dd50e3cab426d63b
5
5
  SHA512:
6
- metadata.gz: a223df306aedc58dbc2ee178b9acd0dbecc02780a62b4cc9cacbbb3aa56772bf853c6df60c3a5a667c5d4fc50d0131c6b33b6ccfd1cb94f748748d8b0ef811b1
7
- data.tar.gz: dd3dc2d2184ad4ae9ceb74dd9f155700a631a70b0ead42339d9ca5615ba13a0714b748698fb05eb8cec4a7bbac5f03a6eee5e311c8816613d32e92fdebc3cc1b
6
+ metadata.gz: 087f920ff64c50ae1e6f299b6fa7d09d787e507895a3d4b640d4d653e84fd5b9dea01454dd0c2324014e8d3109fc2462e404961bef4f27e63a57afeb57c1edbb
7
+ data.tar.gz: c7e1bc599c28d15f4e9283bb91229dc95b05e6317b845798e90fc5ef0f16f307d587365d5c8d8e969a5bc2cb12621e2170df8865edd860351934d45efbcdd69a
@@ -12,13 +12,13 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "fluent-plugin-filter"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.0.3"
15
+ gem.version = "0.0.4"
16
16
 
17
17
  gem.extra_rdoc_files = [
18
18
  "ChangeLog",
19
19
  "README.rdoc"
20
20
  ]
21
21
  gem.add_development_dependency "rake"
22
- gem.add_development_dependency "fluentd"
22
+ gem.add_development_dependency "test-unit", "~> 3.1.0"
23
23
  gem.add_runtime_dependency "fluentd"
24
24
  end
@@ -0,0 +1,26 @@
1
+ module Fluent
2
+ class FilterFilter < Filter
3
+ require 'fluent/plugin/filter_util'
4
+ include FilterUtil
5
+
6
+ Plugin.register_filter('filter', self)
7
+
8
+ config_param :all, :string, :default => 'allow'
9
+ config_param :allow, :string, :default => ''
10
+ config_param :deny, :string, :default => ''
11
+
12
+ attr_accessor :allows
13
+ attr_accessor :denies
14
+
15
+ def configure(conf)
16
+ super
17
+ @allows = toMap(@allow)
18
+ @denies = toMap(@deny)
19
+ end
20
+
21
+ def filter(tag, time, record)
22
+ record if passRules(record)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,47 @@
1
+ module Fluent
2
+ module FilterUtil
3
+ def toMap (str)
4
+ str.split(/\s*,\s*/).map do|pair|
5
+ k, v = pair.split(/\s*:\s*/, 2)
6
+ if v =~ /^\d+$/
7
+ v = v.to_i
8
+ elsif v =~ /^[\d\.]+(e\d+)?$/
9
+ v = v.to_f
10
+ elsif v =~ /^\/(\\\/|[^\/])+\/$/
11
+ v = Regexp.new(v.gsub(/^\/|\/$/, ''))
12
+ else
13
+ v = v.gsub(/^[\"\']|[\"\']$/, '')
14
+ end
15
+ [k, v]
16
+ end
17
+ end
18
+
19
+ def passRules (record)
20
+ if @all == 'allow'
21
+ @denies.each do |deny|
22
+ if (deny[1].is_a? Regexp and record.has_key?(deny[0]) and record[deny[0]].match(deny[1])) or record[deny[0]] == deny[1]
23
+ @allows.each do |allow|
24
+ if (allow[1].is_a? Regexp and record.has_key?(allow[0]) and record[allow[0]].match(allow[1])) or record[allow[0]] == allow[1]
25
+ return true
26
+ end
27
+ end
28
+ return false
29
+ end
30
+ end
31
+ return true
32
+ else
33
+ @allows.each do |allow|
34
+ if (allow[1].is_a? Regexp and record.has_key?(allow[0]) and record[allow[0]].match(allow[1])) or record[allow[0]] == allow[1]
35
+ @denies.each do |deny|
36
+ if (deny[1].is_a? Regexp and record.has_key?(deny[0]) and record[deny[0]].match(deny[1])) or record[deny[0]] == deny[1]
37
+ return false
38
+ end
39
+ end
40
+ return true
41
+ end
42
+ end
43
+ return false
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,8 @@
1
1
  module Fluent
2
2
  class FilterOutput < Output
3
+ require 'fluent/plugin/filter_util'
4
+ include FilterUtil
5
+
3
6
  Plugin.register_output('filter', self)
4
7
 
5
8
  config_param :all, :string, :default => 'allow'
@@ -16,50 +19,6 @@ class FilterOutput < Output
16
19
  @denies = toMap(@deny)
17
20
  end
18
21
 
19
- def toMap (str)
20
- str.split(/\s*,\s*/).map do|pair|
21
- k, v = pair.split(/\s*:\s*/, 2)
22
- if v =~ /^\d+$/
23
- v = v.to_i
24
- elsif v =~ /^[\d\.]+(e\d+)?$/
25
- v = v.to_f
26
- elsif v =~ /^\/(\\\/|[^\/])+\/$/
27
- v = Regexp.new(v.gsub(/^\/|\/$/, ''))
28
- else
29
- v = v.gsub(/^[\"\']|[\"\']$/, '')
30
- end
31
- [k, v]
32
- end
33
- end
34
-
35
- def passRules (record)
36
- if @all == 'allow'
37
- @denies.each do |deny|
38
- if (deny[1].is_a? Regexp and record.has_key?(deny[0]) and record[deny[0]].match(deny[1])) or record[deny[0]] == deny[1]
39
- @allows.each do |allow|
40
- if (allow[1].is_a? Regexp and record.has_key?(allow[0]) and record[allow[0]].match(allow[1])) or record[allow[0]] == allow[1]
41
- return true
42
- end
43
- end
44
- return false
45
- end
46
- end
47
- return true
48
- else
49
- @allows.each do |allow|
50
- if (allow[1].is_a? Regexp and record.has_key?(allow[0]) and record[allow[0]].match(allow[1])) or record[allow[0]] == allow[1]
51
- @denies.each do |deny|
52
- if (deny[1].is_a? Regexp and record.has_key?(deny[0]) and record[deny[0]].match(deny[1])) or record[deny[0]] == deny[1]
53
- return false
54
- end
55
- end
56
- return true
57
- end
58
- end
59
- return false
60
- end
61
- end
62
-
63
22
  def emit(tag, es, chain)
64
23
  if @add_prefix
65
24
  tag = @add_prefix + '.' + tag
data/test/helper.rb CHANGED
@@ -23,6 +23,7 @@ unless ENV.has_key?('VERBOSE')
23
23
  end
24
24
 
25
25
  require 'fluent/plugin/out_filter'
26
+ require 'fluent/plugin/filter_filter'
26
27
 
27
28
  class Test::Unit::TestCase
28
29
  end
@@ -0,0 +1,126 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestFilterFilter < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ CONFIG = %[
10
+ all allow
11
+ deny status: 404
12
+ ]
13
+
14
+ def create_driver(conf = CONFIG, tag='test.input')
15
+ Fluent::Test::FilterTestDriver.new(Fluent::FilterFilter, tag).configure(conf)
16
+ end
17
+
18
+ data("int value" => [{"allows" => [['status', 200]], "denies" => []},
19
+ %[
20
+ all deny
21
+ allow status: 200
22
+ ]],
23
+ "float value" => [{"allows" => [['status', 200.0]], "denies" => []},
24
+ %[
25
+ all deny
26
+ allow status: 200.0
27
+ ]],
28
+ "text value" => [{"allows" => [['status', '200']], "denies" => []},
29
+ %[
30
+ all deny
31
+ allow status: '200'
32
+ ]],
33
+ "text value with URL" =>
34
+ [{"allows" => [['status', 'https://my.website.com/']], "denies" => []},
35
+ %[
36
+ all deny
37
+ allow status: "https://my.website.com/"
38
+ ]],
39
+ "regexp value with forward slashes" =>
40
+ [{"allows" => [['url', Regexp.new("\\/users\\/\\d+")]], "denies" => []},
41
+ %[
42
+ all deny
43
+ allow url: /\\/users\\/\\d+/
44
+ ]])
45
+ def test_configure(data)
46
+ expected, target = data
47
+ d = create_driver target
48
+ assert_equal expected["allows"], d.instance.allows
49
+ assert_equal expected["denies"], d.instance.denies
50
+ end
51
+
52
+ data("config" => [5, CONFIG],
53
+ "allow status 200" => [3,
54
+ %[
55
+ all deny
56
+ allow status: 200
57
+ ]],
58
+ "allow status 200 and 303" => [4,
59
+ %[
60
+ all deny
61
+ allow status: 200, status: 303
62
+ ]],
63
+ "allow Gecko agent" => [3,
64
+ %[
65
+ all deny
66
+ allow agent: Gecko
67
+ ]],
68
+ "allow \"Gecko\" agent" => [3,
69
+ %[
70
+ all deny
71
+ allow agent: "Gecko"
72
+ ]],
73
+ "allow /Geck/ Regexp matched agent" => [4,
74
+ %[
75
+ all deny
76
+ allow agent: /Geck/
77
+ ]],
78
+ "allow /\\/users\\/\\d+/ Regexp matched path" => [3,
79
+ %[
80
+ all deny
81
+ allow path: /\\/users\\/\\d+/
82
+ ]])
83
+ def test_filter(data)
84
+ expected, target = data
85
+ inputs = [
86
+ {'status' => 200, 'agent' => 'IE', 'path' => '/users/1'},
87
+ {'status' => 303, 'agent' => 'Gecko'},
88
+ {'status' => 200, 'agent' => 'IE', 'path' => '/users/2'},
89
+ {'status' => 401, 'agent' => 'Gecko'},
90
+ {'status' => 200, 'agent' => 'Gecka', 'path' => '/users/3'},
91
+ {'status' => 404, 'agent' => 'Gecko', 'path' => '/wrong'},
92
+ ]
93
+ d = create_driver(target, 'test.input')
94
+ d.run do
95
+ inputs.each do |dat|
96
+ d.filter dat
97
+ end
98
+ end
99
+ assert_equal expected, d.filtered_as_array.length
100
+ end
101
+
102
+ data("allow message2" => [1,
103
+ %[
104
+ all deny
105
+ allow message2: /hoge2/
106
+ ]],
107
+ "deny message2" => [1,
108
+ %[
109
+ all allow
110
+ deny message2: /hoge2/
111
+ ]])
112
+ def test_filter_message(data)
113
+ expected, target = data
114
+ inputs = [
115
+ {'message' => 'hoge', 'message2' => 'hoge2'},
116
+ {'message' => 'hoge3'},
117
+ ]
118
+ d = create_driver(target, 'test.input')
119
+ d.run do
120
+ inputs.each do |dat|
121
+ d.filter dat
122
+ end
123
+ end
124
+ assert_equal expected, d.filtered_as_array.length
125
+ end
126
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muddy Dixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: fluentd
28
+ name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 3.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 3.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fluentd
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Simple output filter
@@ -61,17 +61,20 @@ extra_rdoc_files:
61
61
  - ChangeLog
62
62
  - README.rdoc
63
63
  files:
64
- - .gitignore
65
- - .travis.yml
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
66
  - ChangeLog
67
67
  - Gemfile
68
68
  - LICENSE
69
69
  - README.rdoc
70
70
  - Rakefile
71
71
  - fluent-plugin-filter.gemspec
72
+ - lib/fluent/plugin/filter_filter.rb
73
+ - lib/fluent/plugin/filter_util.rb
72
74
  - lib/fluent/plugin/out_filter.rb
73
75
  - sample.conf
74
76
  - test/helper.rb
77
+ - test/plugin/test_filter_filter.rb
75
78
  - test/plugin/test_out_filter.rb
76
79
  homepage: https://github.com/muddydixon/fluent-plugin-filter
77
80
  licenses: []
@@ -82,21 +85,21 @@ require_paths:
82
85
  - lib
83
86
  required_ruby_version: !ruby/object:Gem::Requirement
84
87
  requirements:
85
- - - '>='
88
+ - - ">="
86
89
  - !ruby/object:Gem::Version
87
90
  version: '0'
88
91
  required_rubygems_version: !ruby/object:Gem::Requirement
89
92
  requirements:
90
- - - '>='
93
+ - - ">="
91
94
  - !ruby/object:Gem::Version
92
95
  version: '0'
93
96
  requirements: []
94
97
  rubyforge_project: fluent-plugin-filter
95
- rubygems_version: 2.0.3
98
+ rubygems_version: 2.4.5
96
99
  signing_key:
97
100
  specification_version: 4
98
101
  summary: Simple output filter
99
102
  test_files:
100
103
  - test/helper.rb
104
+ - test/plugin/test_filter_filter.rb
101
105
  - test/plugin/test_out_filter.rb
102
- has_rdoc: