fluent-plugin-select 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +28 -0
- data/Rakefile +10 -0
- data/fluent-plugin-select.gemspec +22 -0
- data/lib/fluent/plugin/out_select.rb +33 -0
- data/test/helper.rb +25 -0
- data/test/plugin/test_out_select.rb +89 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
fluent-plugin-select-if rename to fluent-plugin-select
|
2
|
+
|
3
|
+
# fluent-plugin-select
|
4
|
+
|
5
|
+
fluent-plugin-select(out\_select) is the non-buffered output plugin that can filter event logs by using ruby script.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
This sample config outputs access logs that have status code 200.
|
10
|
+
|
11
|
+
<source>
|
12
|
+
type tail
|
13
|
+
format apache
|
14
|
+
path /var/log/httpd-access.log
|
15
|
+
tag tag
|
16
|
+
</source>
|
17
|
+
<match tag>
|
18
|
+
type select
|
19
|
+
select_if record["code"] == "200"
|
20
|
+
add_prefix filtered
|
21
|
+
</match>
|
22
|
+
<match filtered.tag>
|
23
|
+
type file
|
24
|
+
path output.log
|
25
|
+
</match>
|
26
|
+
|
27
|
+
|
28
|
+
The parameter "select" can use 3 variables in event log; tag, time, record. The format of time is an integer number of seconds since the Epoch. The format of record is hash.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-select"
|
6
|
+
s.version = "0.0.2"
|
7
|
+
s.authors = ["Kohei Tomita"]
|
8
|
+
s.email = ["tommy.fmale@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/tomity/fluent-plugin-select"
|
10
|
+
s.summary = %q{fluent-plugin-select is the non-buffered plugin that can be filtered by ruby script. }
|
11
|
+
s.description = %q{fluent-plugin-select is the non-buffered plugin that can be filtered by ruby script. }
|
12
|
+
|
13
|
+
s.rubyforge_project = "fluent-plugin-select-if"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rake", "~> 0.9.2.2"
|
21
|
+
s.add_development_dependency "fluentd", "~> 0.10.24"
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
module Fluent
|
3
|
+
class SelectOutput < Fluent::Output
|
4
|
+
Fluent::Plugin.register_output('select', self)
|
5
|
+
|
6
|
+
config_param :select, :string
|
7
|
+
config_param :add_prefix, :string
|
8
|
+
config_param :timeout, :integer, :default => 1
|
9
|
+
|
10
|
+
def emit(tag, es, chain)
|
11
|
+
begin
|
12
|
+
time_records = []
|
13
|
+
es.each {|time, record|
|
14
|
+
if eval(@select)
|
15
|
+
$log.trace {"hoge"}
|
16
|
+
time_records << [time, record]
|
17
|
+
else
|
18
|
+
$log.trace {"filtered: #{Time.at(time)} #{tag} #{record.inspect}"}
|
19
|
+
end
|
20
|
+
}
|
21
|
+
time_records.each do |time, record|
|
22
|
+
Fluent::Engine::emit(@add_prefix + "." + tag, time, record)
|
23
|
+
end
|
24
|
+
chain.next
|
25
|
+
time_records #for test
|
26
|
+
rescue SyntaxError => e
|
27
|
+
chain.next
|
28
|
+
$log.error "Select command is syntax error: #{@select}"
|
29
|
+
e #for test
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
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_select"
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class SelectOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
select tag == "tag" or record["code"] == "200" or Time.at(time).sec == 0
|
10
|
+
add_prefix prefix
|
11
|
+
]
|
12
|
+
|
13
|
+
def create_driver(conf = CONFIG, tag='test.input')
|
14
|
+
Fluent::Test::OutputTestDriver.new(Fluent::SelectOutput, tag).configure(conf)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_match_tag
|
18
|
+
tag = 'tag' #match
|
19
|
+
time = Time.local(2012, 10, 10, 10, 10, 10) #not match
|
20
|
+
record = {'code' => '300'} #not match
|
21
|
+
|
22
|
+
d1 = create_driver(CONFIG, tag)
|
23
|
+
d1.run do
|
24
|
+
d1.emit(record, time)
|
25
|
+
end
|
26
|
+
emits = d1.emits
|
27
|
+
assert_equal 1, emits.length
|
28
|
+
assert_equal ["prefix.#{tag}", time.to_i, record], emits[0]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_match_time
|
32
|
+
tag = 'test.tag1' #not match
|
33
|
+
time = Time.local(2012, 10, 10, 10, 10, 0) #match
|
34
|
+
record = {'code' => '300'} #not match
|
35
|
+
|
36
|
+
d1 = create_driver(CONFIG, tag)
|
37
|
+
d1.run do
|
38
|
+
d1.emit(record, time)
|
39
|
+
end
|
40
|
+
emits = d1.emits
|
41
|
+
assert_equal 1, emits.length
|
42
|
+
assert_equal ["prefix.#{tag}", time.to_i, record], emits[0]
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def test_match_record
|
47
|
+
tag = 'test.tag1' #not match
|
48
|
+
time = Time.local(2012, 10, 10, 10, 10, 10) #not match
|
49
|
+
record = {'code' => '200'} #match
|
50
|
+
|
51
|
+
d1 = create_driver(CONFIG, tag)
|
52
|
+
d1.run do
|
53
|
+
d1.emit(record, time)
|
54
|
+
end
|
55
|
+
emits = d1.emits
|
56
|
+
assert_equal 1, emits.length
|
57
|
+
assert_equal ["prefix.#{tag}", time.to_i, record], emits[0]
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_not_match
|
61
|
+
tag = 'test.tag1' #not match
|
62
|
+
time = Time.local(2012, 10, 10, 10, 10, 10) #not match
|
63
|
+
record = {'code' => '300'} #not match
|
64
|
+
|
65
|
+
d1 = create_driver(CONFIG, tag)
|
66
|
+
d1.run do
|
67
|
+
d1.emit(record, time)
|
68
|
+
end
|
69
|
+
emits = d1.emits
|
70
|
+
assert_equal 0, emits.length
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_syntax_error
|
74
|
+
tag = "tag"
|
75
|
+
time = Time.local(2012, 10, 10, 10, 10, 0)
|
76
|
+
record = {'code' => '300'}
|
77
|
+
|
78
|
+
#select_if is syntax error
|
79
|
+
syntax_error_config = %[
|
80
|
+
select tag.
|
81
|
+
add_prefix prefix
|
82
|
+
]
|
83
|
+
d1 = create_driver(syntax_error_config, tag)
|
84
|
+
es = Fluent::OneEventStream.new(time.to_i, record)
|
85
|
+
chain = Fluent::Test::TestOutputChain.new
|
86
|
+
e = d1.instance.emit(tag, es, chain)
|
87
|
+
assert e.kind_of?(SyntaxError)
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kohei Tomita
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70228126073860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70228126073860
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fluentd
|
27
|
+
requirement: &70228126071880 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.10.24
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70228126071880
|
36
|
+
description: ! 'fluent-plugin-select is the non-buffered plugin that can be filtered
|
37
|
+
by ruby script. '
|
38
|
+
email:
|
39
|
+
- tommy.fmale@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.markdown
|
47
|
+
- Rakefile
|
48
|
+
- fluent-plugin-select.gemspec
|
49
|
+
- lib/fluent/plugin/out_select.rb
|
50
|
+
- test/helper.rb
|
51
|
+
- test/plugin/test_out_select.rb
|
52
|
+
homepage: https://github.com/tomity/fluent-plugin-select
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: fluent-plugin-select-if
|
72
|
+
rubygems_version: 1.8.17
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: fluent-plugin-select is the non-buffered plugin that can be filtered by ruby
|
76
|
+
script.
|
77
|
+
test_files:
|
78
|
+
- test/helper.rb
|
79
|
+
- test/plugin/test_out_select.rb
|