fluent-plugin-redeliver 0.0.2

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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-redeliver.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Masatoshi Kawazoe (acidlemon)
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.md ADDED
@@ -0,0 +1,100 @@
1
+ # Fluent::Plugin::Redeliver
2
+
3
+ Simple re-delivery plugin to process log record as another tag
4
+
5
+ ## Synopsis
6
+
7
+ ### Basic
8
+
9
+ ```
10
+ <match foo.**>
11
+ type redeliver
12
+ regexp ^foo\.(.*)$
13
+ replace bar.\1
14
+ # add original tag to record['__tag'] (optional)
15
+ tag_attr __tag
16
+ </match>
17
+
18
+ <match bar.**>
19
+ # write your output process
20
+
21
+ </match>
22
+ ```
23
+
24
+ ### More Effective
25
+
26
+ ```
27
+ <match myapp.error.*>
28
+ type copy
29
+
30
+ <store>
31
+ type file
32
+ path /path/to/file
33
+ </store>
34
+
35
+ <store>
36
+ type redeliver
37
+ regexp ^myapp\.error\.(.*)$
38
+ replace logging.error.\1
39
+ tag_attr __tag
40
+ </store>
41
+ </match>
42
+
43
+ <match logging.error.*>
44
+ type copy
45
+
46
+ # store all logs
47
+ <store>
48
+ type mongo
49
+ host remotehost
50
+ database fluent
51
+ collection errorlog
52
+ </store>
53
+
54
+ # and suppress log and notify... (using fluent-plugin-suppress)
55
+ <store>
56
+ type suppress
57
+ interval 10
58
+ num 2
59
+ attr_keys message
60
+ add_tag_prefix sp.
61
+ </store>
62
+ </match>
63
+
64
+ # write <match sp.logging.error.*> for notify...
65
+ # write <match logging.**> for mongo...
66
+ :
67
+ :
68
+ ```
69
+
70
+
71
+ ## Configuration
72
+
73
+ * `regexp`: redelivers the record if tag matches specified pattern.
74
+ * `replace`: rewrites tag for re-emit. You can use n-th matched subexpression(\1,\2...) for replace string.
75
+ * `tag_attr`: adds original tag to specified key if regexp matches.
76
+
77
+
78
+ ## Installation
79
+
80
+ Add this line to your application's Gemfile:
81
+
82
+ gem 'fluent-plugin-redeliver'
83
+
84
+ And then execute:
85
+
86
+ $ bundle
87
+
88
+ Or install it yourself as:
89
+
90
+ $ gem install fluent-plugin-redeliver
91
+
92
+ ## Contributing
93
+
94
+ 1. Fork it
95
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
96
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
97
+ 4. Push to the branch (`git push origin my-new-feature`)
98
+ 5. Create new Pull Request
99
+
100
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
11
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "fluent-plugin-redeliver"
7
+ gem.version = "0.0.2"
8
+ gem.authors = ["Masatoshi Kawazoe (acidlemon)"]
9
+ gem.email = ["acidlemon@beatsync.net"]
10
+ gem.description = %q{simple tag-based redeliver plugin}
11
+ gem.summary = %q{simple tag-based redeliver plugin}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency "fluentd"
20
+ gem.add_runtime_dependency "fluentd"
21
+ end
@@ -0,0 +1,43 @@
1
+ class Fluent::RedeliverOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('redeliver', self)
3
+
4
+ config_param :regexp, :string, :default => nil
5
+ config_param :replace, :string, :default => nil
6
+ config_param :tag_attr, :string, :default => nil
7
+
8
+ def initialize
9
+ super
10
+ end
11
+
12
+ def configure(conf)
13
+ super
14
+ end
15
+
16
+ def start
17
+ super
18
+ end
19
+
20
+ def shutdown
21
+ super
22
+ end
23
+
24
+ def emit(tag, es, chain)
25
+ newtag = ''
26
+ if @regexp and @replace
27
+ newtag = tag.sub(Regexp.new(@regexp), @replace)
28
+ end
29
+
30
+ if newtag != tag and newtag.length > 0
31
+ es.each do |time, record|
32
+ if (record)
33
+ record[tag_attr] = tag if tag_attr
34
+ Fluent::Engine.emit(newtag, time, record)
35
+ end
36
+ end
37
+ end
38
+
39
+ chain.next
40
+ end
41
+
42
+ end
43
+
data/test/helper.rb ADDED
@@ -0,0 +1,29 @@
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_redeliver'
26
+
27
+ class Test::Unit::TestCase
28
+ end
29
+
@@ -0,0 +1,119 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class RedeliverOutputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ CONFIG = %[
10
+ ]
11
+
12
+ def create_driver(conf = CONFIG, tag='test')
13
+ Fluent::Test::OutputTestDriver.new(Fluent::RedeliverOutput, tag).configure(conf)
14
+ end
15
+
16
+ def test_configure
17
+ d = create_driver %[
18
+ regexp ^app\\.(.*)\\.(.*)$
19
+ replace test.hoge.\\1_\\2
20
+ ]
21
+
22
+ assert_equal '^app\.(.*)\.(.*)$', d.instance.regexp
23
+ assert_equal 'test.hoge.\1_\2', d.instance.replace
24
+ assert_equal nil, d.instance.tag_attr
25
+
26
+ d = create_driver %[
27
+ regexp ^debug\\.(.*)$
28
+ replace ignore.\\1
29
+ tag_attr __tag
30
+ ]
31
+
32
+ assert_equal '^debug\.(.*)$', d.instance.regexp
33
+ assert_equal 'ignore.\1', d.instance.replace
34
+ assert_equal '__tag', d.instance.tag_attr
35
+
36
+ end
37
+
38
+ def test_emit
39
+ # constants
40
+ now1 = Time.now
41
+ now2 = Time.now + 100
42
+
43
+ # basic test
44
+ d1 = create_driver %[
45
+ regexp ^app\\.(.*)\\.(.*)$
46
+ replace test.hoge.\\1_\\2
47
+ ], 'app.foo.bar'
48
+
49
+ d1.run do
50
+ d1.emit({ "test" => "value1" }, now1)
51
+ d1.emit({ "test" => "value2" }, now2)
52
+ end
53
+
54
+ emits = d1.emits
55
+
56
+ assert_equal 2, emits.length
57
+
58
+ assert_equal 'test.hoge.foo_bar', emits[0][0]
59
+ assert_equal now1.to_i, emits[0][1]
60
+ assert_equal 'value1', emits[0][2]['test']
61
+ assert_equal nil, emits[0][2]['tag']
62
+ assert_equal nil, emits[1][2]['__tag']
63
+
64
+ assert_equal 'test.hoge.foo_bar', emits[1][0]
65
+ assert_equal now2.to_i, emits[1][1]
66
+ assert_equal 'value2', emits[1][2]['test']
67
+ assert_equal nil, emits[1][2]['tag']
68
+ assert_equal nil, emits[1][2]['__tag']
69
+
70
+ # not match test
71
+ d2 = create_driver %[
72
+ regexp ^app\\.bar\\.(.*)$
73
+ replace test.hoge.\\1
74
+ ], 'app.foo.bar'
75
+
76
+ d2.run do
77
+ d2.emit({ "test" => "value1" }, now1)
78
+ end
79
+
80
+ emits2 = d2.emits
81
+
82
+ assert_equal 0, emits2.length
83
+
84
+ # match with tag
85
+ d3 = create_driver %[
86
+ regexp ^app\\.(.*)\\.(.*)$
87
+ replace test.hoge.\\1_\\2
88
+ tag_attr __tag
89
+ ], 'app.foo.bar'
90
+
91
+ d3.run do
92
+ d3.emit({ "test" => "value1" }, now1)
93
+ end
94
+
95
+ emits = d3.emits
96
+
97
+ assert_equal 1, emits.length
98
+
99
+ assert_equal 'test.hoge.foo_bar', emits[0][0]
100
+ assert_equal now1.to_i, emits[0][1]
101
+ assert_equal 'value1', emits[0][2]['test']
102
+ assert_equal nil, emits[0][2]['tag']
103
+ assert_equal 'app.foo.bar', emits[0][2]['__tag']
104
+
105
+
106
+ # empty regexp
107
+ d4 = create_driver %[], 'debug.foo'
108
+
109
+ d4.run do
110
+ d4.emit({ "test" => "value" }, now1)
111
+ end
112
+
113
+ emits = d4.emits
114
+
115
+ assert_equal 0, emits.length
116
+
117
+ end
118
+
119
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-redeliver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Masatoshi Kawazoe (acidlemon)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: simple tag-based redeliver plugin
47
+ email:
48
+ - acidlemon@beatsync.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - fluent-plugin-redeliver.gemspec
59
+ - lib/fluent/plugin/out_redeliver.rb
60
+ - test/helper.rb
61
+ - test/plugin/test_out_redeliver.rb
62
+ homepage: ''
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: simple tag-based redeliver plugin
86
+ test_files:
87
+ - test/helper.rb
88
+ - test/plugin/test_out_redeliver.rb