fluent-plugin-rewrite-tag-filter 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 +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +14 -0
- data/README.rdoc +26 -0
- data/Rakefile +1 -0
- data/fluent-plugin-rewrite-tag-filter.gemspec +23 -0
- data/lib/fluent/plugin/out_rewrite_tag_filter.rb +54 -0
- data/test/plugin/test_out_rewrite_tag_filter.rb +0 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (c) 2012- Kentaro Yoshida
|
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.
|
14
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= fluent-plugin-rewrite-tag-filter
|
2
|
+
|
3
|
+
== Component
|
4
|
+
|
5
|
+
=== RewriteTagFilterOutput
|
6
|
+
|
7
|
+
Modify Tags with data matches any of specified regexp patterns in specified attribute.
|
8
|
+
|
9
|
+
== Configuration
|
10
|
+
|
11
|
+
<match td.apache.access>
|
12
|
+
type rewrite_tag_filter
|
13
|
+
rewriterule1 domain ^maps\.google\.com$ site.Google.Map
|
14
|
+
rewriterule2 domain ^news.google\.com$ site.Google.News
|
15
|
+
rewriterule3 agent (Googlebot|Crawler|Spyder) agent.Robot
|
16
|
+
rewriterule4 referer headlines\.yahoo\.co\.jp referer.YahooHeadlines
|
17
|
+
</match>
|
18
|
+
|
19
|
+
== TODO
|
20
|
+
|
21
|
+
- patches welcome!
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright:: Copyright (c) 2012- Kentaro Yoshida (yoshi_ken)
|
26
|
+
License:: Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-rewrite-tag-filter"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Kentaro Yoshida"]
|
8
|
+
s.email = [""]
|
9
|
+
s.homepage = "https://github.com/y-ken/fluent-plugin-rewrite-tag-filter"
|
10
|
+
s.summary = %q{Output filter plugin to rewrite tags that matches specified attribute}
|
11
|
+
s.description = %q{Output filter plugin to rewrite tags that matches specified attribute}
|
12
|
+
|
13
|
+
s.rubyforge_project = "fluent-plugin-rewrite-tag-filter"
|
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
|
+
# specify any dependencies here; for example:
|
21
|
+
s.add_development_dependency "fluentd"
|
22
|
+
s.add_runtime_dependency "fluentd"
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Fluent::RewriteTagFilterOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('rewrite_tag_filter', self)
|
3
|
+
|
4
|
+
PATTERN_MAX_NUM = 50
|
5
|
+
|
6
|
+
config_param :rewriterule1, :string # string: NAME REGEXP
|
7
|
+
(2..PATTERN_MAX_NUM).each do |i|
|
8
|
+
config_param ('rewriterule' + i.to_s).to_sym, :string, :default => nil # NAME REGEXP
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure(conf)
|
12
|
+
super
|
13
|
+
|
14
|
+
@rewriterules = []
|
15
|
+
rewriterule_names = []
|
16
|
+
|
17
|
+
invalids = conf.keys.select{|k| k =~ /^rewriterule(\d+)$/}.select{|arg| arg =~ /^rewriterule(\d+)/ and not (1..PATTERN_MAX_NUM).include?($1.to_i)}
|
18
|
+
if invalids.size > 0
|
19
|
+
$log.warn "invalid number rewriterules (valid rewriterule number:1-{PATTERN_MAX_NUM}):" + invalids.join(",")
|
20
|
+
end
|
21
|
+
(1..PATTERN_MAX_NUM).each do |i|
|
22
|
+
next unless conf["rewriterule#{i}"]
|
23
|
+
name,regexp,tag = conf["rewriterule#{i}"].split(' ', 3)
|
24
|
+
@rewriterules.push([i, name, Regexp.new(regexp), tag])
|
25
|
+
rewriterule_names.push(name + regexp)
|
26
|
+
end
|
27
|
+
rewriterule_index_list = conf.keys.select{|s| s =~ /^rewriterule\d$/}.map{|v| (/^rewriterule(\d)$/.match(v))[1].to_i}
|
28
|
+
unless rewriterule_index_list.reduce(true){|v,i| v and @rewriterules[i - 1]}
|
29
|
+
raise Fluent::ConfigError, "jump of rewriterule index found" + @rewriterules.inspect
|
30
|
+
end
|
31
|
+
unless @rewriterules.length == rewriterule_names.uniq.length
|
32
|
+
raise Fluent::ConfigError, "duplicated rewriterules found" + @rewriterules.inspect
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def emit(tag, es, chain)
|
37
|
+
es.each do |time,record|
|
38
|
+
rewrite = false
|
39
|
+
@rewriterules.each do |index, rewritekey, regexp, rewritetag|
|
40
|
+
rewritevalue = record[rewritekey]
|
41
|
+
next if rewritevalue.nil?
|
42
|
+
if (regexp && regexp.match(rewritevalue))
|
43
|
+
rewrite = true
|
44
|
+
tag = rewritetag
|
45
|
+
break
|
46
|
+
end
|
47
|
+
end
|
48
|
+
Fluent::Engine.emit(tag, time, record) if (rewrite)
|
49
|
+
end
|
50
|
+
|
51
|
+
chain.next
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-rewrite-tag-filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kentaro Yoshida
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: &16391840 !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: *16391840
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fluentd
|
27
|
+
requirement: &16390600 !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: *16390600
|
36
|
+
description: Output filter plugin to rewrite tags that matches specified attribute
|
37
|
+
email:
|
38
|
+
- ''
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE.txt
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- fluent-plugin-rewrite-tag-filter.gemspec
|
49
|
+
- lib/fluent/plugin/out_rewrite_tag_filter.rb
|
50
|
+
- test/plugin/test_out_rewrite_tag_filter.rb
|
51
|
+
homepage: https://github.com/y-ken/fluent-plugin-rewrite-tag-filter
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project: fluent-plugin-rewrite-tag-filter
|
71
|
+
rubygems_version: 1.8.11
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Output filter plugin to rewrite tags that matches specified attribute
|
75
|
+
test_files:
|
76
|
+
- test/plugin/test_out_rewrite_tag_filter.rb
|