fluent-plugin-record-modifier 0.1.0
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/ChangeLog +3 -0
- data/Gemfile +3 -0
- data/README.md +64 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/fluent-plugin-record-modifier.gemspec +22 -0
- data/lib/fluent/plugin/out_record_modifier.rb +44 -0
- data/test/out_record_modifier.rb +49 -0
- metadata +107 -0
data/ChangeLog
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Output filter plugin for modifying each event record
|
2
|
+
|
3
|
+
Adding arbitary field to event record without custmizing existence plugin.
|
4
|
+
|
5
|
+
For example, generated event from *in_tail* doesn't contain "hostname" of running machine.
|
6
|
+
In this case, you can use *record_modifier* to add "hostname" field to event record.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Use RubyGems:
|
11
|
+
|
12
|
+
gem install fluent-plugin-record-modifier
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
|
16
|
+
<match pattern>
|
17
|
+
type record_modifier
|
18
|
+
tag foo.filtered
|
19
|
+
|
20
|
+
gen_host ${hostname}
|
21
|
+
foo bar
|
22
|
+
</match>
|
23
|
+
|
24
|
+
If following record is passed:
|
25
|
+
|
26
|
+
```js
|
27
|
+
{"message":"hello world!"}
|
28
|
+
```
|
29
|
+
|
30
|
+
then you got new record like below:
|
31
|
+
|
32
|
+
```js
|
33
|
+
{"message":"hello world!", "gen_host":"oreore-mac.local", "foo":"bar"}
|
34
|
+
```
|
35
|
+
|
36
|
+
### Mixins
|
37
|
+
|
38
|
+
* [SetTagKeyMixin](https://github.com/fluent/fluentd/blob/master/lib/fluent/mixin.rb#L181)
|
39
|
+
* [fluent-mixin-config-placeholders](https://github.com/tagomoris/fluent-mixin-config-placeholders)
|
40
|
+
|
41
|
+
## TODO
|
42
|
+
|
43
|
+
* Adding following features if needed
|
44
|
+
|
45
|
+
* Use HandleTagNameMixin to keep original tag
|
46
|
+
|
47
|
+
* Remove record field
|
48
|
+
|
49
|
+
* Replace record value
|
50
|
+
|
51
|
+
|
52
|
+
## Copyright
|
53
|
+
|
54
|
+
<table>
|
55
|
+
<tr>
|
56
|
+
<td>Author</td><td>Masahiro Nakagawa <repeatedly@gmail.com></td>
|
57
|
+
</tr>
|
58
|
+
<tr>
|
59
|
+
<td>Copyright</td><td>Copyright (c) 2013- Masahiro Nakagawa</td>
|
60
|
+
</tr>
|
61
|
+
<tr>
|
62
|
+
<td>License</td><td>MIT License</td>
|
63
|
+
</tr>
|
64
|
+
</table>
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:build]
|
14
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-record-modifier"
|
6
|
+
gem.description = "Output filter plugin for modifying each event record"
|
7
|
+
gem.homepage = "https://github.com/repeatedly/fluent-plugin-record-modifier"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["Masahiro Nakagawa"]
|
11
|
+
gem.email = "repeatedly@gmail.com"
|
12
|
+
gem.has_rdoc = false
|
13
|
+
#gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_dependency "fluentd", "~> 0.10.17"
|
20
|
+
gem.add_dependency "fluent-mixin-config-placeholders", "~> 0.2.0"
|
21
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'fluent/mixin/config_placeholders'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class RecordModifierOutput < Output
|
5
|
+
Fluent::Plugin.register_output('record_modifier', self)
|
6
|
+
|
7
|
+
config_param :tag, :string
|
8
|
+
|
9
|
+
include SetTagKeyMixin
|
10
|
+
include Fluent::Mixin::ConfigPlaceholders
|
11
|
+
|
12
|
+
BUILTIN_CONFIGURATIONS = %W(type tag include_tag_key tag_key)
|
13
|
+
|
14
|
+
def configure(conf)
|
15
|
+
super
|
16
|
+
|
17
|
+
@map = {}
|
18
|
+
conf.each_pair { |k, v|
|
19
|
+
unless BUILTIN_CONFIGURATIONS.include?(k)
|
20
|
+
conf.has_key?(k)
|
21
|
+
@map[k] = v
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def emit(tag, es, chain)
|
27
|
+
es.each { |time, record|
|
28
|
+
Engine.emit(@tag, time, modify_record(record))
|
29
|
+
}
|
30
|
+
|
31
|
+
chain.next
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def modify_record(record)
|
37
|
+
@map.each_pair { |k, v|
|
38
|
+
record[k] = v
|
39
|
+
}
|
40
|
+
|
41
|
+
record
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'fluent/plugin/out_record_modifier'
|
3
|
+
|
4
|
+
|
5
|
+
class RecordModifierOutputTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
CONFIG = %[
|
11
|
+
type record_modifier
|
12
|
+
tag foo.filtered
|
13
|
+
|
14
|
+
gen_host ${hostname}
|
15
|
+
foo bar
|
16
|
+
]
|
17
|
+
|
18
|
+
def create_driver(conf = CONFIG)
|
19
|
+
Fluent::Test::OutputTestDriver.new(Fluent::RecordModifierOutput).configure(conf)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_hostname
|
23
|
+
require 'socket'
|
24
|
+
Socket.gethostname.chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_configure
|
28
|
+
d = create_driver
|
29
|
+
map = d.instance.instance_variable_get(:@map)
|
30
|
+
|
31
|
+
assert_equal get_hostname, map['gen_host']
|
32
|
+
assert_equal 'bar', map['foo']
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_format
|
36
|
+
d = create_driver
|
37
|
+
|
38
|
+
d.run do
|
39
|
+
d.emit("a" => 1)
|
40
|
+
d.emit("a" => 2)
|
41
|
+
end
|
42
|
+
|
43
|
+
mapped = {'gen_host' => get_hostname, 'foo' => 'bar'}
|
44
|
+
assert_equal [
|
45
|
+
{"a" => 1}.merge(mapped),
|
46
|
+
{"a" => 2}.merge(mapped),
|
47
|
+
], d.records
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-record-modifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Masahiro Nakagawa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-07 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.10.17
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.17
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fluent-mixin-config-placeholders
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.2.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.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.2
|
62
|
+
description: Output filter plugin for modifying each event record
|
63
|
+
email: repeatedly@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ChangeLog
|
69
|
+
- Gemfile
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- VERSION
|
73
|
+
- fluent-plugin-record-modifier.gemspec
|
74
|
+
- lib/fluent/plugin/out_record_modifier.rb
|
75
|
+
- test/out_record_modifier.rb
|
76
|
+
homepage: https://github.com/repeatedly/fluent-plugin-record-modifier
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
hash: -302354387031894905
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
hash: -302354387031894905
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.23
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Output filter plugin for modifying each event record
|
106
|
+
test_files:
|
107
|
+
- test/out_record_modifier.rb
|