fluent-plugin-retag 0.0.1
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 +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +54 -0
- data/Rakefile +10 -0
- data/fluent-plugin-retag.gemspec +21 -0
- data/lib/fluent/plugin/out_retag.rb +48 -0
- data/test/helper.rb +29 -0
- data/test/plugin/test_out_retag.rb +96 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013- Masahiro Yamauchi
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# fluent-plugin-retag
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
Output plugin only retagging.
|
6
|
+
|
7
|
+
* simple retag
|
8
|
+
* remove tag prefix
|
9
|
+
* add tag prefix
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
### Simple Configuration
|
14
|
+
|
15
|
+
To retag foo.bar to hoge.fuga:
|
16
|
+
|
17
|
+
<match foo.bar>
|
18
|
+
type retag
|
19
|
+
tag hoge.fuga
|
20
|
+
</match>
|
21
|
+
|
22
|
+
To retag foo.bar.** to xyz.bar.**:
|
23
|
+
|
24
|
+
<match foo.bar>
|
25
|
+
type retag
|
26
|
+
remove_prefix foo
|
27
|
+
add_prefix xyz
|
28
|
+
</match>
|
29
|
+
|
30
|
+
### Useful Configuration
|
31
|
+
|
32
|
+
If you want to use branch condition, it is useful to use out_copy with fluent-plugin-retag.
|
33
|
+
|
34
|
+
<match foo.bar.**>
|
35
|
+
type copy
|
36
|
+
<store>
|
37
|
+
type retag
|
38
|
+
add_prefix copied
|
39
|
+
</store>
|
40
|
+
<store>
|
41
|
+
...
|
42
|
+
</store>
|
43
|
+
</match>
|
44
|
+
|
45
|
+
<match copied.foo.bar.**>
|
46
|
+
...
|
47
|
+
</match>
|
48
|
+
|
49
|
+
## Copyright
|
50
|
+
|
51
|
+
* Copyright (c) 2013- Masahiro Yamauchi
|
52
|
+
* License
|
53
|
+
* Apache License, Version 2.0
|
54
|
+
|
data/Rakefile
ADDED
@@ -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-retag"
|
7
|
+
gem.version = "0.0.1"
|
8
|
+
gem.authors = ["Masahiro Yamauchi"]
|
9
|
+
gem.email = ["sgt.yamauchi@gmail.com"]
|
10
|
+
gem.description = %q{Output filter plugin to retag}
|
11
|
+
gem.summary = %q{Output filter plugin to retag}
|
12
|
+
gem.homepage = "https://github.com/algas/fluent-plugin-retag"
|
13
|
+
|
14
|
+
gem.rubyforge_project = "fluent-plugin-retag"
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency "fluentd"
|
20
|
+
gem.add_runtime_dependency "fluentd"
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Fluent::RetagOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('retag', self)
|
3
|
+
|
4
|
+
config_param :tag, :string, :default => nil
|
5
|
+
config_param :remove_prefix, :string, :default => nil
|
6
|
+
config_param :add_prefix, :string, :default => nil
|
7
|
+
|
8
|
+
def configure(conf)
|
9
|
+
super
|
10
|
+
if not @tag and not @remove_prefix and not @add_prefix
|
11
|
+
raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix"
|
12
|
+
end
|
13
|
+
if @tag and (@remove_prefix or @add_prefix)
|
14
|
+
raise Fluent::ConfigError, "both of tag and remove_prefix/add_prefix must not be specified"
|
15
|
+
end
|
16
|
+
if @remove_prefix
|
17
|
+
@removed_prefix_string = @remove_prefix + '.'
|
18
|
+
@removed_length = @removed_prefix_string.length
|
19
|
+
end
|
20
|
+
if @add_prefix
|
21
|
+
@added_prefix_string = @add_prefix + '.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def emit(tag, es, chain)
|
26
|
+
tag = if @tag
|
27
|
+
@tag
|
28
|
+
else
|
29
|
+
if @remove_prefix and
|
30
|
+
( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
|
31
|
+
tag = tag[@removed_length..-1]
|
32
|
+
end
|
33
|
+
if @add_prefix
|
34
|
+
tag = if tag and tag.length > 0
|
35
|
+
@added_prefix_string + tag
|
36
|
+
else
|
37
|
+
@add_prefix
|
38
|
+
end
|
39
|
+
end
|
40
|
+
tag
|
41
|
+
end
|
42
|
+
es.each do |time,record|
|
43
|
+
Fluent::Engine.emit(tag, time, record)
|
44
|
+
end
|
45
|
+
chain.next
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
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_retag'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class RetagOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
tag hoge
|
10
|
+
]
|
11
|
+
CONFIG2 = %[
|
12
|
+
remove_prefix foo
|
13
|
+
]
|
14
|
+
CONFIG3 = %[
|
15
|
+
remove_prefix foo
|
16
|
+
add_prefix head
|
17
|
+
]
|
18
|
+
|
19
|
+
def create_driver(conf = CONFIG, tag='test')
|
20
|
+
Fluent::Test::OutputTestDriver.new(Fluent::RetagOutput, tag).configure(conf)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_configure
|
24
|
+
assert_raise(Fluent::ConfigError) {
|
25
|
+
create_driver ('')
|
26
|
+
}
|
27
|
+
assert_raise(Fluent::ConfigError) {
|
28
|
+
create_driver %[
|
29
|
+
tag a
|
30
|
+
remove_prefix b
|
31
|
+
]
|
32
|
+
}
|
33
|
+
assert_raise(Fluent::ConfigError) {
|
34
|
+
create_driver %[
|
35
|
+
tag a
|
36
|
+
add_prefix c
|
37
|
+
]
|
38
|
+
}
|
39
|
+
d1 = create_driver %[
|
40
|
+
tag a
|
41
|
+
]
|
42
|
+
d1.instance.inspect
|
43
|
+
assert_equal 'a', d1.instance.tag
|
44
|
+
d2 = create_driver %[
|
45
|
+
remove_prefix b
|
46
|
+
add_prefix c
|
47
|
+
]
|
48
|
+
d2.instance.inspect
|
49
|
+
assert_equal 'b', d2.instance.remove_prefix
|
50
|
+
assert_equal 'c', d2.instance.add_prefix
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_emit
|
54
|
+
d = create_driver(CONFIG, 'foo.bar')
|
55
|
+
time = Time.parse('2011-03-11 14:46:01').to_i
|
56
|
+
d.run do
|
57
|
+
d.emit({'a' => 'b'})
|
58
|
+
d.emit({'c' => 'd'})
|
59
|
+
end
|
60
|
+
emits = d.emits
|
61
|
+
assert_equal 2, emits.length
|
62
|
+
p emits[0]
|
63
|
+
assert_equal 'hoge', emits[0][0]
|
64
|
+
assert_equal 'b', emits[0][2]['a']
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_emit2
|
68
|
+
d = create_driver(CONFIG2, 'foo.bar')
|
69
|
+
time = Time.parse('2011-03-11 14:46:01').to_i
|
70
|
+
d.run do
|
71
|
+
d.emit({'a' => 'b'})
|
72
|
+
d.emit({'c' => 'd'})
|
73
|
+
end
|
74
|
+
emits = d.emits
|
75
|
+
assert_equal 2, emits.length
|
76
|
+
p emits[0]
|
77
|
+
assert_equal 'bar', emits[0][0]
|
78
|
+
assert_equal 'b', emits[0][2]['a']
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_emit3
|
82
|
+
d = create_driver(CONFIG3, 'foo.bar')
|
83
|
+
time = Time.parse('2011-03-11 14:46:01').to_i
|
84
|
+
d.run do
|
85
|
+
d.emit({'a' => 'b'})
|
86
|
+
d.emit({'c' => 'd'})
|
87
|
+
end
|
88
|
+
emits = d.emits
|
89
|
+
assert_equal 2, emits.length
|
90
|
+
p emits[0]
|
91
|
+
assert_equal 'head.bar', emits[0][0]
|
92
|
+
assert_equal 'b', emits[0][2]['a']
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-retag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Masahiro Yamauchi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-15 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: Output filter plugin to retag
|
47
|
+
email:
|
48
|
+
- sgt.yamauchi@gmail.com
|
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-retag.gemspec
|
59
|
+
- lib/fluent/plugin/out_retag.rb
|
60
|
+
- test/helper.rb
|
61
|
+
- test/plugin/test_out_retag.rb
|
62
|
+
homepage: https://github.com/algas/fluent-plugin-retag
|
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: fluent-plugin-retag
|
82
|
+
rubygems_version: 1.8.23
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Output filter plugin to retag
|
86
|
+
test_files:
|
87
|
+
- test/helper.rb
|
88
|
+
- test/plugin/test_out_retag.rb
|