fluent-plugin-map 0.0.1
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 +32 -0
- data/Rakefile +10 -0
- data/fluent-plugin-map.gemspec +24 -0
- data/lib/fluent/plugin/out_map.rb +32 -0
- data/test/helper.rb +25 -0
- data/test/plugin/test_out_map.rb +50 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# fluent-plugin-map
|
2
|
+
|
3
|
+
fluent-plugin-map(out\_map) is the non-buffered plugin that can convert an event log to different event log(s)
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
This sample config output code file and time file.
|
8
|
+
|
9
|
+
<source>
|
10
|
+
type tail
|
11
|
+
format apache
|
12
|
+
path /var/log/httpd-access.log
|
13
|
+
tag tag
|
14
|
+
</source>
|
15
|
+
<match tag>
|
16
|
+
type map
|
17
|
+
map [["code." + tag, time, {"code" => record["code"].to_i}], ["time." + tag, time, {"time" => record["time"].to_i}]]
|
18
|
+
multi true
|
19
|
+
</match>
|
20
|
+
<match code.tag>
|
21
|
+
type file
|
22
|
+
path code.log
|
23
|
+
</match>
|
24
|
+
<match time.tag>
|
25
|
+
type file
|
26
|
+
path time.log
|
27
|
+
</match>
|
28
|
+
|
29
|
+
|
30
|
+
The parameter "map" 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.
|
31
|
+
The config file parses # as the begin of comment. So the "map" value cannot use #{tag} operation.
|
32
|
+
This plugin can output multi logs by seting multi to true.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-map"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Kohei Tomita"]
|
8
|
+
s.email = ["tommy.fmale@gmail.com"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{fluent-plugin-map is the non-buffered plugin that can convert an event log to different event log(s). }
|
11
|
+
s.description = %q{fluent-plugin-map is the non-buffered plugin that can convert an event log to different event log(s). }
|
12
|
+
|
13
|
+
s.rubyforge_project = "fluent-plugin-map"
|
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 "rake"
|
22
|
+
s.add_development_dependency "fluentd"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
module Fluent
|
3
|
+
class MapOutput < Fluent::Output
|
4
|
+
Fluent::Plugin.register_output('map', self)
|
5
|
+
|
6
|
+
config_param :map, :string
|
7
|
+
config_param :multi, :bool, :default => false
|
8
|
+
|
9
|
+
def configure(conf)
|
10
|
+
super
|
11
|
+
$log.debug { "map: #{@map}" }
|
12
|
+
end
|
13
|
+
|
14
|
+
def emit(tag, es, chain)
|
15
|
+
tuples = []
|
16
|
+
es.each {|time, record|
|
17
|
+
new_tuple = eval(@map)
|
18
|
+
if @multi
|
19
|
+
tuples.concat new_tuple
|
20
|
+
else
|
21
|
+
tuples << new_tuple
|
22
|
+
end
|
23
|
+
}
|
24
|
+
tuples.each do |tag, time, record|
|
25
|
+
$log.trace { [tag, time, record].inspect }
|
26
|
+
Fluent::Engine::emit(tag, time, record)
|
27
|
+
end
|
28
|
+
chain.next
|
29
|
+
tuples
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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_map"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class MapOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
map [tag, time, record]
|
10
|
+
multi false
|
11
|
+
]
|
12
|
+
|
13
|
+
def create_driver(conf = CONFIG, tag='test.input')
|
14
|
+
Fluent::Test::OutputTestDriver.new(Fluent::MapOutput, tag).configure(conf)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tag_convert
|
18
|
+
tag = 'tag'
|
19
|
+
time = Time.local(2012, 10, 10, 10, 10, 10)
|
20
|
+
record = {'code' => '300'}
|
21
|
+
|
22
|
+
d1 = create_driver %[
|
23
|
+
map ["newtag", time, record]
|
24
|
+
], tag
|
25
|
+
d1.run do
|
26
|
+
d1.emit(record, time)
|
27
|
+
end
|
28
|
+
emits = d1.emits
|
29
|
+
assert_equal 1, emits.length
|
30
|
+
assert_equal ["newtag", time.to_i, record], emits[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_convert_multi_tag
|
34
|
+
tag = 'tag'
|
35
|
+
time = Time.local(2012, 10, 10, 10, 10, 10)
|
36
|
+
record = {'code' => '300'}
|
37
|
+
|
38
|
+
d1 = create_driver %[
|
39
|
+
map [["tag1", time, record], ["tag2", time, record]]
|
40
|
+
multi true
|
41
|
+
], tag
|
42
|
+
d1.run do
|
43
|
+
d1.emit(record, time)
|
44
|
+
end
|
45
|
+
emits = d1.emits
|
46
|
+
assert_equal 2, emits.length
|
47
|
+
assert_equal ["tag1", time.to_i, record], emits[0]
|
48
|
+
assert_equal ["tag2", time.to_i, record], emits[1]
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-map
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kohei Tomita
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-10 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70350721521500 !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: *70350721521500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fluentd
|
27
|
+
requirement: &70350721520660 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70350721520660
|
36
|
+
description: ! 'fluent-plugin-map is the non-buffered plugin that can convert an event
|
37
|
+
log to different event log(s). '
|
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-map.gemspec
|
49
|
+
- lib/fluent/plugin/out_map.rb
|
50
|
+
- test/helper.rb
|
51
|
+
- test/plugin/test_out_map.rb
|
52
|
+
homepage: ''
|
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-map
|
72
|
+
rubygems_version: 1.8.17
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: fluent-plugin-map is the non-buffered plugin that can convert an event log
|
76
|
+
to different event log(s).
|
77
|
+
test_files:
|
78
|
+
- test/helper.rb
|
79
|
+
- test/plugin/test_out_map.rb
|