fluent-plugin-eval-filter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e8885658d2dab4edc7a5362fc98ffe1055226f7
4
+ data.tar.gz: e83788f2f6847157bd21b4aac0d7e8c1fd585078
5
+ SHA512:
6
+ metadata.gz: e264e6087ad6ed705f52b3b4c93918868dae10fd2cecac4437ba8c485bea2f020a8f6612117eee716f26ff4f5887ef80bc64951b2bce59ca6cd89ae97fa17bca
7
+ data.tar.gz: c0e8a5b0880e68f142442eb23fd78c7717d637d99a9cda028cb05e13190ff1cf2a83f67caec8abf4ce346da683a7de7691c34615c11ee26f422cae542c511c88
@@ -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-eval-filter.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013- Yuzuki Masaru
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.
@@ -0,0 +1,37 @@
1
+ # fluent-plugin-eval-filter
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'fluent-plugin-eval-filter'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install fluent-plugin-eval-filter
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ <match raw.apache.access>
21
+ type eval_filter
22
+ remove_tag_prefix raw
23
+ add_tag_prefix filtered
24
+
25
+ config1 @hostname = `hostname -s`.chomp
26
+
27
+ filter1 [[tag, @hostname].join('.'), time, record] if record['method'] == 'GET'
28
+ </match>
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
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-eval-filter"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Yuzuki Masaru"]
9
+ spec.email = ["ephemeralsnow@gmail.com"]
10
+ spec.summary = %q{Fluentd Output eval filter plugin.}
11
+ spec.homepage = "https://github.com/ephemeralsnow/fluent-plugin-eval-filter"
12
+ spec.license = "Apache 2.0"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "fluentd"
20
+ spec.add_development_dependency "rake"
21
+ end
@@ -0,0 +1,68 @@
1
+ class Fluent::EvalFilterOutput < Fluent::Output
2
+ include Fluent::HandleTagNameMixin
3
+
4
+ Fluent::Plugin.register_output('eval_filter', self)
5
+
6
+ def configure(conf)
7
+ super
8
+
9
+ conf.keys.select { |key| key =~ /^config\d+$/ }.sort_by { |key| key.sub('config', '').to_i }.each do |key|
10
+ instance_eval("#{conf[key]}")
11
+ end
12
+
13
+ @filters = []
14
+ conf.keys.select { |key| key =~ /^filter\d+$/ }.sort_by { |key| key.sub('filter', '').to_i }.each do |key|
15
+ @filters << instance_eval("lambda do |tag, time, record| #{conf[key]} end")
16
+ end
17
+ end
18
+
19
+ def emit(tag, es, chain)
20
+ es.each do |time, record|
21
+ result = filter_record(tag.clone, time, record)
22
+ Fluent::Engine.emit(*result) if result
23
+ end
24
+ chain.next
25
+ end
26
+
27
+ def filter_record(tag, time, record)
28
+ super
29
+
30
+ @filters.each do |filter|
31
+ filter_result = filter.call(tag, time, record)
32
+ result = create_result(tag, time, record, filter_result) if filter_result
33
+ return result if result
34
+ end
35
+ nil
36
+ end
37
+
38
+ def create_result(tag, time, record, result)
39
+ if result.is_a?(String)
40
+ [result, time, record]
41
+ elsif result.is_a?(Integer)
42
+ [tag, result, record]
43
+ elsif result.is_a?(Hash)
44
+ [tag, time, result]
45
+ elsif result.is_a?(Array)
46
+ if result.size == 1
47
+ if result[0].is_a?(String)
48
+ [result[0], time, record]
49
+ elsif result[0].is_a?(Integer)
50
+ [tag, result[0], record]
51
+ elsif result[0].is_a?(Hash)
52
+ [tag, time, record[0]]
53
+ end
54
+ elsif result.size == 2
55
+ if result[0].is_a?(String) && result[1].is_a?(Integer)
56
+ [result[0], result[1], record]
57
+ elsif result[0].is_a?(String) && result[1].is_a?(Hash)
58
+ [result[0], time, result[1]]
59
+ elsif result[0].is_a?(Integer) && result[1].is_a?(Hash)
60
+ [tag, result[0], result[1]]
61
+ end
62
+ elsif result.size == 3 && result[0].is_a?(String) && result[1].is_a?(Integer) && result[2].is_a?(Hash)
63
+ [result[0], result[1], result[2]]
64
+ end
65
+ end
66
+ end
67
+
68
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-eval-filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuzuki Masaru
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: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ description:
42
+ email:
43
+ - ephemeralsnow@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - fluent-plugin-eval-filter.gemspec
54
+ - lib/fluent/plugin/out_eval_filter.rb
55
+ homepage: https://github.com/ephemeralsnow/fluent-plugin-eval-filter
56
+ licenses:
57
+ - Apache 2.0
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.1.11
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Fluentd Output eval filter plugin.
79
+ test_files: []