fluent-plugin-record-reformer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +78 -0
- data/Rakefile +15 -0
- data/fluent-plugin-record-reformer.gemspec +24 -0
- data/lib/fluent/plugin/out_record_reformer.rb +52 -0
- data/spec/out_record_expander_spec.rb +60 -0
- data/spec/spec_helper.rb +16 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7d6ae389089e590c847be0a6f9969cab1e56138
|
4
|
+
data.tar.gz: 69a52f47a536d08d3d317ce8803d761cba44ea97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f4bb261c67b3842003d83b54729a3b0e453b09f8d6a3efce0f741acebe0d8b569e644898bc634bb20ea3440fe815c456c48a0e0a495abe3109ce8523ce734830
|
7
|
+
data.tar.gz: bb9f7cce04fc9ea24db7e25a6ed9d882824328433b1a99ce427a00b1c90260d1751dc4ca2661ecfbc73aebb7b4d89dbd7253a0c7c20013c3bbd53a887e073529
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: i4DJCtdksuIwhBck1tukIjzKoMCxWIIvQ
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Naotoshi SEO
|
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,78 @@
|
|
1
|
+
# fluent-plugin-record-reformer [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-record-reformer.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-record-reformer) [![Dependency Status](https://gemnasium.com/sonots/fluent-plugin-record-reformer.png)](https://gemnasium.com/sonots/fluent-plugin-record-reformer) [![Coverage Status](https://coveralls.io/repos/sonots/fluent-plugin-record-reformer/badge.png?branch=master)](https://coveralls.io/r/sonots/fluent-plugin-record-reformer)
|
2
|
+
|
3
|
+
Add or replace fields of a event record
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Use RubyGems:
|
8
|
+
|
9
|
+
gem install fluent-plugin-record-reformer
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
<match foo.**>
|
14
|
+
type record_reformer
|
15
|
+
output_tag reformed
|
16
|
+
|
17
|
+
hostname ${hostname}
|
18
|
+
tag ${tag}
|
19
|
+
time ${time.strftime('%Y-%m-%dT%H:%M:%S%z')}
|
20
|
+
message ${hostname} ${tags.last} ${message}
|
21
|
+
</match>
|
22
|
+
|
23
|
+
Assume following input is coming:
|
24
|
+
|
25
|
+
```js
|
26
|
+
foo.bar {"message":"hello world!", "foo":"bar"}
|
27
|
+
```
|
28
|
+
|
29
|
+
then output becomes as below (indented):
|
30
|
+
|
31
|
+
```js
|
32
|
+
reformed {
|
33
|
+
"hostname":"your_hostname",
|
34
|
+
"tag":"foo.bar",
|
35
|
+
"time":"2013-05-01T01:13:14Z",
|
36
|
+
"message":"your_hostname bar hello world!",
|
37
|
+
"foo":"bar"
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
### Placeholders
|
42
|
+
|
43
|
+
The keys of input json are available as placeholders. In the above example,
|
44
|
+
|
45
|
+
* ${foo}
|
46
|
+
* ${message}
|
47
|
+
|
48
|
+
shall be available. In addition, following placeholders are reserved:
|
49
|
+
|
50
|
+
* ${hostname} hostname
|
51
|
+
* ${tag} input tag
|
52
|
+
* ${tags} input tag splitted by '.'
|
53
|
+
* ${time} time of the event
|
54
|
+
|
55
|
+
It is also possible to write a ruby code in placeholders, so you may write some codes as
|
56
|
+
|
57
|
+
* ${time.strftime('%Y-%m-%dT%H:%M:%S%z')}
|
58
|
+
* ${tags.last}
|
59
|
+
|
60
|
+
## Relatives
|
61
|
+
|
62
|
+
* [fluent-plugin-record-modifier](https://github.com/repeatedly/fluent-plugin-record-modifier)
|
63
|
+
|
64
|
+
## ChangeLog
|
65
|
+
|
66
|
+
See [CHANGELOG.md](CHANGELOG.md) for details.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new [Pull Request](../../pull/new/master)
|
75
|
+
|
76
|
+
## Copyright
|
77
|
+
|
78
|
+
Copyright (c) 2013 Naotoshi SEO. See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rspec/core'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
+
end
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
desc 'Open an irb session preloaded with the gem library'
|
12
|
+
task :console do
|
13
|
+
sh 'irb -rubygems -I lib'
|
14
|
+
end
|
15
|
+
task :c => :console
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-record-reformer"
|
6
|
+
gem.version = "0.0.1"
|
7
|
+
gem.authors = ["Naotoshi Seo"]
|
8
|
+
gem.email = "sonots@gmail.com"
|
9
|
+
gem.homepage = "https://github.com/sonots/fluent-plugin-record-reformer"
|
10
|
+
gem.description = "Output filter plugin for reforming each event record"
|
11
|
+
gem.summary = gem.description
|
12
|
+
gem.has_rdoc = false
|
13
|
+
|
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_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "pry"
|
23
|
+
gem.add_development_dependency 'coveralls'
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class RecordReformerOutput < Output
|
5
|
+
Fluent::Plugin.register_output('record_reformer', self)
|
6
|
+
|
7
|
+
config_param :output_tag, :string
|
8
|
+
|
9
|
+
BUILTIN_CONFIGURATIONS = %W(type output_tag)
|
10
|
+
|
11
|
+
def configure(conf)
|
12
|
+
super
|
13
|
+
|
14
|
+
@map = {}
|
15
|
+
conf.each_pair { |k, v|
|
16
|
+
next if BUILTIN_CONFIGURATIONS.include?(k)
|
17
|
+
conf.has_key?(k)
|
18
|
+
@map[k] = v
|
19
|
+
}
|
20
|
+
|
21
|
+
@hostname = Socket.gethostname
|
22
|
+
end
|
23
|
+
|
24
|
+
def emit(tag, es, chain)
|
25
|
+
tags = tag.split('.')
|
26
|
+
es.each { |time, record|
|
27
|
+
Engine.emit(@output_tag, time, expand_record(record, tag, tags, time))
|
28
|
+
}
|
29
|
+
chain.next
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def expand_record(record, tag, tags, time)
|
35
|
+
time = Time.at(time)
|
36
|
+
@map.each_pair { |k, v|
|
37
|
+
record[k] = expand(v, record, tag, tags, time)
|
38
|
+
}
|
39
|
+
record
|
40
|
+
end
|
41
|
+
|
42
|
+
def expand(str, record, tag, tags, time)
|
43
|
+
struct = OpenStruct.new(record)
|
44
|
+
struct.tag = tag
|
45
|
+
struct.tags = tags
|
46
|
+
struct.time = time
|
47
|
+
struct.hostname = @hostname
|
48
|
+
str = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..}
|
49
|
+
eval "\"#{str}\"", struct.instance_eval { binding }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe Fluent::RecordReformerOutput do
|
5
|
+
before { Fluent::Test.setup }
|
6
|
+
CONFIG = %[
|
7
|
+
type reformed
|
8
|
+
output_tag reformed
|
9
|
+
|
10
|
+
hostname ${hostname}
|
11
|
+
tag ${tag}
|
12
|
+
time ${time.strftime('%S')}
|
13
|
+
message ${hostname} ${tags.last} ${message}
|
14
|
+
]
|
15
|
+
let(:tag) { 'test.tag' }
|
16
|
+
let(:tags) { tag.split('.') }
|
17
|
+
let(:hostname) { Socket.gethostname.chomp }
|
18
|
+
let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::RecordReformerOutput, tag).configure(config) }
|
19
|
+
|
20
|
+
describe 'test configure' do
|
21
|
+
describe 'good configuration' do
|
22
|
+
subject { driver.instance }
|
23
|
+
|
24
|
+
context "check default" do
|
25
|
+
let(:config) { CONFIG }
|
26
|
+
its(:output_tag) { should == 'reformed' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'test emit' do
|
32
|
+
let(:time) { Time.now }
|
33
|
+
let(:emit) do
|
34
|
+
driver.run do
|
35
|
+
driver.emit({'foo'=>'bar', 'message' => 1}, time.to_i)
|
36
|
+
driver.emit({'foo'=>'bar', 'message' => 2}, time.to_i)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:config) { CONFIG }
|
41
|
+
before do
|
42
|
+
Fluent::Engine.stub(:now).and_return(time)
|
43
|
+
Fluent::Engine.should_receive(:emit).with("reformed", time.to_i, {
|
44
|
+
'foo' => 'bar',
|
45
|
+
'hostname' => hostname,
|
46
|
+
'tag' => tag,
|
47
|
+
'time' => time.strftime('%S'),
|
48
|
+
'message' => "#{hostname} #{tags.last} 1",
|
49
|
+
})
|
50
|
+
Fluent::Engine.should_receive(:emit).with("reformed", time.to_i, {
|
51
|
+
'foo' => 'bar',
|
52
|
+
'hostname' => hostname,
|
53
|
+
'tag' => tag,
|
54
|
+
'time' => time.strftime('%S'),
|
55
|
+
'message' => "#{hostname} #{tags.last} 2",
|
56
|
+
})
|
57
|
+
end
|
58
|
+
it { emit }
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup(:default, :test)
|
5
|
+
Bundler.require(:default, :test)
|
6
|
+
|
7
|
+
require 'coveralls'
|
8
|
+
Coveralls.wear!
|
9
|
+
|
10
|
+
require 'fluent/test'
|
11
|
+
require 'rspec'
|
12
|
+
require 'pry'
|
13
|
+
|
14
|
+
$TESTING=true
|
15
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
16
|
+
require 'fluent/plugin/out_record_reformer'
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-record-reformer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naotoshi Seo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.17
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.17
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Output filter plugin for reforming each event record
|
84
|
+
email: sonots@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- .coveralls.yml
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- CHANGELOG.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- fluent-plugin-record-reformer.gemspec
|
99
|
+
- lib/fluent/plugin/out_record_reformer.rb
|
100
|
+
- spec/out_record_expander_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/sonots/fluent-plugin-record-reformer
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.0
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Output filter plugin for reforming each event record
|
125
|
+
test_files:
|
126
|
+
- spec/out_record_expander_spec.rb
|
127
|
+
- spec/spec_helper.rb
|