fluent-plugin-format 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab742e2958a313675dffc077f30329c1f96b3bfa
4
+ data.tar.gz: 18a07bc6d76325e9fafa6b2b7f3bffeafbfb4eb9
5
+ SHA512:
6
+ metadata.gz: fd37c653ac6a7016a943f184fea57d4d3520d7fa95292de5b52de0a7f912ea194d5bd4349092352b7d5210b64844b303f7da4d2898db634b15c0c5fb0877f7e8
7
+ data.tar.gz: 21c57f7532882d3d235db5afd1cade627659fe7fe2cab613cb2b0cc8d805852c120f7bd40e8f1c837467671f663044e27c7ff75197e438222de882489a27bb59
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-format.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Akinori Machino
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,66 @@
1
+ # Fluent::Plugin::Format
2
+
3
+ Output plugin to format fields of records.
4
+ You can add or change fields using existing values.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fluent-plugin-format'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-format
19
+
20
+ ## Usage
21
+
22
+ <match pattern>
23
+ type format
24
+ tag new_tag
25
+ key1 %{key1} changed!
26
+ new_key1 key1 -> %{key1}
27
+ new_key2 key1 -> %{key1}, key2 -> %{key2}
28
+ </match>
29
+
30
+ Pass
31
+
32
+ {
33
+ "key1": "val1",
34
+ "key2": "val2"
35
+ }
36
+
37
+ Then you get
38
+
39
+ {
40
+ "key1": "val1 changed!",
41
+ "key2": "val2",
42
+ "new_key1": "key1 -> val1",
43
+ "new_key2": "key1 -> val1, key2 -> val2"
44
+ }
45
+
46
+ You can set `include_original_fields false` to exclude original fields.
47
+
48
+ <match pattern>
49
+ type format
50
+ tag new_tag
51
+ include_original_fields false
52
+ html <h1>%{title}</h1><div><%{content}/div>
53
+ </match>
54
+
55
+ Pass
56
+
57
+ {
58
+ "title": "Fluentd: Open Source Log Management",
59
+ "content": "Fluentd is an open-source tool to collect events and logs. 150+ plugins instantly enables you to store the massive data for Log Search, Big Data Analytics, and Archiving (MongoDB, S3, Hadoop)."
60
+ }
61
+
62
+ Then you get
63
+
64
+ {
65
+ "html": "<h1>Fluentd: Open Source Log Management</h1><div>Fluentd is an open-source tool to collect events and logs. 150+ plugins instantly enables you to store the massive data for Log Search, Big Data Analytics, and Archiving (MongoDB, S3, Hadoop).</div>"
66
+ }
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.test_files = FileList['test/*.rb']
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: 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 |spec|
6
+ spec.name = "fluent-plugin-format"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Akinori Machino"]
9
+ spec.email = ["akinori.machino@icloud.com"]
10
+ spec.description = %q{Output plugin to format fields of records and re-emit them.}
11
+ spec.summary = %q{Output plugin to format fields and re-emit them.}
12
+ spec.homepage = "https://github.com/mach/fluent-plugin-format"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "fluentd"
23
+ spec.add_runtime_dependency "fluentd"
24
+ end
@@ -0,0 +1,45 @@
1
+ module Fluent
2
+ class FormatOutput < Output
3
+ Fluent::Plugin.register_output('format', self)
4
+
5
+ config_param :tag, :string
6
+ config_param :include_original_fields, :bool, :default => true
7
+
8
+ CONF_KEYS = %w{type tag include_original_fields}
9
+
10
+ def configure(conf)
11
+ super
12
+
13
+ @fields = {}
14
+ conf.each do |k, v|
15
+ unless CONF_KEYS.include?(k)
16
+ @fields[k] = v
17
+ end
18
+ end
19
+ end
20
+
21
+ def emit(tag, es, chain)
22
+ es.each do |time, record|
23
+ Engine.emit(@tag, time, format_record(record))
24
+ end
25
+
26
+ chain.next
27
+ end
28
+
29
+ private
30
+
31
+ def format_record(record)
32
+ result = {}
33
+
34
+ if @include_original_fields
35
+ result.merge!(record)
36
+ end
37
+
38
+ @fields.each do |k, v|
39
+ result[k] = v.gsub(/%{(.+?)}/).each { record[$1] }
40
+ end
41
+
42
+ return result
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,96 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/out_format'
3
+
4
+ class FormatOutputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ def create_driver(conf)
10
+ Fluent::Test::OutputTestDriver.new(Fluent::FormatOutput).configure(conf)
11
+ end
12
+
13
+ def test_format
14
+ d1 = create_driver %[
15
+ type format
16
+ tag formatted
17
+ key1 %{key1} changed!
18
+ new_key1 key1 -> %{key1}
19
+ new_key2 key1 -> %{key1}, key2 -> %{key2}
20
+ ]
21
+
22
+ d1.run do
23
+ d1.emit({'key1' => 'val1', 'key2' => 'val2'})
24
+ d1.emit({'key1' => 'val1'})
25
+ end
26
+
27
+ assert_equal [
28
+ {
29
+ 'key1' => 'val1 changed!',
30
+ 'key2' => 'val2',
31
+ 'new_key1' => 'key1 -> val1',
32
+ 'new_key2' => 'key1 -> val1, key2 -> val2'
33
+ },
34
+ {
35
+ 'key1' => 'val1 changed!',
36
+ 'new_key1' => 'key1 -> val1',
37
+ 'new_key2' => 'key1 -> val1, key2 -> '
38
+ }
39
+ ], d1.records
40
+
41
+ d2 = create_driver %[
42
+ type format
43
+ tag formatted
44
+ include_original_fields true
45
+ key1 %{key1} changed!
46
+ new_key1 key1 -> %{key1}
47
+ new_key2 key1 -> %{key1}, key2 -> %{key2}
48
+ ]
49
+
50
+ d2.run do
51
+ d2.emit({'key1' => 'val1', 'key2' => 'val2'})
52
+ d2.emit({'key1' => 'val1'})
53
+ end
54
+
55
+ assert_equal [
56
+ {
57
+ 'key1' => 'val1 changed!',
58
+ 'key2' => 'val2',
59
+ 'new_key1' => 'key1 -> val1',
60
+ 'new_key2' => 'key1 -> val1, key2 -> val2'
61
+ },
62
+ {
63
+ 'key1' => 'val1 changed!',
64
+ 'new_key1' => 'key1 -> val1',
65
+ 'new_key2' => 'key1 -> val1, key2 -> '
66
+ }
67
+ ], d2.records
68
+
69
+ d3 = create_driver %[
70
+ type format
71
+ tag formatted
72
+ include_original_fields false
73
+ key1 %{key1} changed!
74
+ new_key1 key1 -> %{key1}
75
+ new_key2 key1 -> %{key1}, key2 -> %{key2}
76
+ ]
77
+
78
+ d3.run do
79
+ d3.emit({'key1' => 'val1', 'key2' => 'val2'})
80
+ d3.emit({'key1' => 'val1'})
81
+ end
82
+
83
+ assert_equal [
84
+ {
85
+ 'key1' => 'val1 changed!',
86
+ 'new_key1' => 'key1 -> val1',
87
+ 'new_key2' => 'key1 -> val1, key2 -> val2'
88
+ },
89
+ {
90
+ 'key1' => 'val1 changed!',
91
+ 'new_key1' => 'key1 -> val1',
92
+ 'new_key2' => 'key1 -> val1, key2 -> '
93
+ }
94
+ ], d3.records
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-format
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Akinori Machino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: fluentd
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: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Output plugin to format fields of records and re-emit them.
70
+ email:
71
+ - akinori.machino@icloud.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - fluent-plugin-format.gemspec
82
+ - lib/fluent/plugin/out_format.rb
83
+ - test/test_cout_format.rb
84
+ homepage: https://github.com/mach/fluent-plugin-format
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Output plugin to format fields and re-emit them.
108
+ test_files:
109
+ - test/test_cout_format.rb