fluent-plugin-filter 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/ChangeLog +0 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.rdoc +49 -0
- data/Rakefile +11 -0
- data/fluent-plugin-filter.gemspec +23 -0
- data/lib/fluent/plugin/out_filter.rb +75 -0
- data/sample.conf +13 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_out_filter.rb +160 -0
- metadata +82 -0
data/.gitignore
ADDED
data/ChangeLog
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 muddydixon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= fluent-plugin-filter
|
2
|
+
|
3
|
+
== Component
|
4
|
+
|
5
|
+
=== FilterOutput
|
6
|
+
|
7
|
+
Filtering messages by simple allow/deny rules.
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'fluent-plugin-filter'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fluent-plugin-filter
|
22
|
+
|
23
|
+
== Configuration
|
24
|
+
|
25
|
+
=== FilterOutput
|
26
|
+
|
27
|
+
Filter out messages contains <tt>{status : 404}</tt> :
|
28
|
+
|
29
|
+
<match accesslog.**>
|
30
|
+
type filter
|
31
|
+
all allow
|
32
|
+
deny status: 404
|
33
|
+
</match>
|
34
|
+
<match filtered.**>
|
35
|
+
type stdout
|
36
|
+
</match>
|
37
|
+
|
38
|
+
in above configuration, {status: 404} is filtered out and {status: 200}, {status: 303}, {status: 401} passed.
|
39
|
+
Messages passing filter are add_prefix (default filtered.)
|
40
|
+
|
41
|
+
So you catch "filtered" tag and do next process.
|
42
|
+
|
43
|
+
== Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ["muddydixon"]
|
4
|
+
gem.email = ["muddydixon@gmail.com"]
|
5
|
+
gem.description = %q{Simple output filter}
|
6
|
+
gem.summary = %q{Simple output filter}
|
7
|
+
gem.homepage = "https://github.com/muddydixon/fluent-plugin-filter"
|
8
|
+
gem.rubyforge_project = "fluent-plugin-filter"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "fluent-plugin-filter"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.0"
|
16
|
+
|
17
|
+
gem.extra_rdoc_files = [
|
18
|
+
"ChangeLog",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
gem.add_development_dependency "fluentd"
|
22
|
+
gem.add_runtime_dependency "fluentd"
|
23
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Fluent
|
2
|
+
class FilterOutput < Output
|
3
|
+
Plugin.register_output('filter', self)
|
4
|
+
|
5
|
+
config_param :all, :string, :default => 'allow'
|
6
|
+
config_param :allow, :string, :default => ''
|
7
|
+
config_param :deny, :string, :default => ''
|
8
|
+
config_param :add_prefix, :string, :default => 'filtered'
|
9
|
+
|
10
|
+
attr_accessor :allows
|
11
|
+
attr_accessor :denies
|
12
|
+
|
13
|
+
def configure(conf)
|
14
|
+
super
|
15
|
+
@allows = toMap(@allow)
|
16
|
+
@denies = toMap(@deny)
|
17
|
+
end
|
18
|
+
|
19
|
+
def toMap (str)
|
20
|
+
str.split(/\s*,\s*/).map do|pair|
|
21
|
+
k, v = pair.split(/\s*:\s*/)
|
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[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[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[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[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
|
+
def emit(tag, es, chain)
|
64
|
+
if @add_prefix
|
65
|
+
tag = @add_prefix + '.' + tag
|
66
|
+
end
|
67
|
+
es.each do |time, record|
|
68
|
+
next unless passRules(record)
|
69
|
+
Engine.emit(tag, time, record)
|
70
|
+
end
|
71
|
+
chain.next
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/sample.conf
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/out_filter'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class Filter < 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::OutputTestDriver.new(Fluent::FilterOutput, tag).configure(conf)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_configure
|
19
|
+
# add tag
|
20
|
+
d = create_driver %[
|
21
|
+
all deny
|
22
|
+
allow status: 200
|
23
|
+
add_prefix hoge
|
24
|
+
]
|
25
|
+
assert_equal "hoge", d.instance.add_prefix
|
26
|
+
assert_equal [['status', 200]], d.instance.allows
|
27
|
+
assert_equal [], d.instance.denies
|
28
|
+
|
29
|
+
# int value
|
30
|
+
d = create_driver %[
|
31
|
+
all deny
|
32
|
+
allow status: 200
|
33
|
+
]
|
34
|
+
assert_equal [['status', 200]], d.instance.allows
|
35
|
+
assert_equal [], d.instance.denies
|
36
|
+
|
37
|
+
# float value
|
38
|
+
d = create_driver %[
|
39
|
+
all deny
|
40
|
+
allow status: 200.0
|
41
|
+
]
|
42
|
+
assert_equal [['status', 200.0]], d.instance.allows
|
43
|
+
assert_equal [], d.instance.denies
|
44
|
+
|
45
|
+
# text value
|
46
|
+
d = create_driver %[
|
47
|
+
all deny
|
48
|
+
allow status: "200"
|
49
|
+
]
|
50
|
+
assert_equal [['status', '200']], d.instance.allows
|
51
|
+
assert_equal [], d.instance.denies
|
52
|
+
|
53
|
+
# regexp value
|
54
|
+
d = create_driver %[
|
55
|
+
all deny
|
56
|
+
allow url: /hoge/
|
57
|
+
]
|
58
|
+
assert_equal [['url', /hoge/]], d.instance.allows
|
59
|
+
assert_equal [], d.instance.denies
|
60
|
+
|
61
|
+
end
|
62
|
+
def test_emit
|
63
|
+
data = [
|
64
|
+
{'status' => 200, 'agent' => 'IE'},
|
65
|
+
{'status' => 303, 'agent' => 'Gecko'},
|
66
|
+
{'status' => 200, 'agent' => 'IE'},
|
67
|
+
{'status' => 401, 'agent' => 'Gecko'},
|
68
|
+
{'status' => 200, 'agent' => 'Gecka'},
|
69
|
+
{'status' => 404, 'agent' => 'Gecko'},
|
70
|
+
]
|
71
|
+
|
72
|
+
d = create_driver(CONFIG, 'test.input')
|
73
|
+
d.run do
|
74
|
+
data.each do |dat|
|
75
|
+
d.emit dat
|
76
|
+
end
|
77
|
+
end
|
78
|
+
assert_equal 5, d.emits.length
|
79
|
+
|
80
|
+
d = create_driver(%[
|
81
|
+
all deny
|
82
|
+
allow status: 200
|
83
|
+
], 'test.input')
|
84
|
+
d.run do
|
85
|
+
data.each do |dat|
|
86
|
+
d.emit dat
|
87
|
+
end
|
88
|
+
end
|
89
|
+
assert_equal 3, d.emits.length
|
90
|
+
|
91
|
+
d = create_driver(%[
|
92
|
+
all deny
|
93
|
+
allow status: 200, status: 303
|
94
|
+
], 'test.input')
|
95
|
+
d.run do
|
96
|
+
data.each do |dat|
|
97
|
+
d.emit dat
|
98
|
+
end
|
99
|
+
end
|
100
|
+
assert_equal 4, d.emits.length
|
101
|
+
|
102
|
+
d = create_driver(%[
|
103
|
+
all deny
|
104
|
+
allow agent: Gecko
|
105
|
+
], 'test.input')
|
106
|
+
d.run do
|
107
|
+
data.each do |dat|
|
108
|
+
d.emit dat
|
109
|
+
end
|
110
|
+
end
|
111
|
+
assert_equal 3, d.emits.length
|
112
|
+
|
113
|
+
d = create_driver(%[
|
114
|
+
all deny
|
115
|
+
allow agent: "Gecko"
|
116
|
+
], 'test.input')
|
117
|
+
d.run do
|
118
|
+
data.each do |dat|
|
119
|
+
d.emit dat
|
120
|
+
end
|
121
|
+
end
|
122
|
+
assert_equal 3, d.emits.length
|
123
|
+
|
124
|
+
d = create_driver(%[
|
125
|
+
all deny
|
126
|
+
allow agent: "Gecko"
|
127
|
+
deny status: 200
|
128
|
+
], 'test.input')
|
129
|
+
d.run do
|
130
|
+
data.each do |dat|
|
131
|
+
d.emit dat
|
132
|
+
end
|
133
|
+
end
|
134
|
+
assert_equal 3, d.emits.length
|
135
|
+
|
136
|
+
d = create_driver(%[
|
137
|
+
all deny
|
138
|
+
allow agent: /Geck/
|
139
|
+
], 'test.input')
|
140
|
+
d.run do
|
141
|
+
data.each do |dat|
|
142
|
+
d.emit dat
|
143
|
+
end
|
144
|
+
end
|
145
|
+
assert_equal 4, d.emits.length
|
146
|
+
|
147
|
+
d = create_driver(%[
|
148
|
+
all deny
|
149
|
+
allow agent: /Geck/
|
150
|
+
add_prefix hoge
|
151
|
+
], 'test.input')
|
152
|
+
d.run do
|
153
|
+
data.each do |dat|
|
154
|
+
d.emit dat
|
155
|
+
end
|
156
|
+
end
|
157
|
+
assert_equal "hoge.test.input", d.emits[0][0]
|
158
|
+
|
159
|
+
end
|
160
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- muddydixon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: &2152828080 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152828080
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fluentd
|
27
|
+
requirement: &2152827620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152827620
|
36
|
+
description: Simple output filter
|
37
|
+
email:
|
38
|
+
- muddydixon@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files:
|
42
|
+
- ChangeLog
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- ChangeLog
|
47
|
+
- Gemfile
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- fluent-plugin-filter.gemspec
|
52
|
+
- lib/fluent/plugin/out_filter.rb
|
53
|
+
- sample.conf
|
54
|
+
- test/helper.rb
|
55
|
+
- test/plugin/test_out_filter.rb
|
56
|
+
homepage: https://github.com/muddydixon/fluent-plugin-filter
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project: fluent-plugin-filter
|
76
|
+
rubygems_version: 1.8.11
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Simple output filter
|
80
|
+
test_files:
|
81
|
+
- test/helper.rb
|
82
|
+
- test/plugin/test_out_filter.rb
|