fluent-plugin-filter_keys 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-filter_keys.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kohei Hasegawa
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,46 @@
1
+ # fluent-plugin-filter_keys
2
+ [![Build Status](https://secure.travis-ci.org/banyan/fluent-plugin-filter_keys.png)](http://travis-ci.org/banyan/fluent-plugin-filter_keys)
3
+
4
+ ## Overview
5
+
6
+ Fluentd plugin to filter if a specific key is present or not in event logs.
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install fluent-plugin-filter_keys
12
+ ```
13
+
14
+ ## Configuration
15
+
16
+ ```
17
+ <match test.**>
18
+ type filter_keys
19
+
20
+ add_tag_prefix filter_keys.
21
+ ensure_keys foo, bar
22
+ </match>
23
+
24
+ <match test.**>
25
+ type filter_keys
26
+
27
+ add_tag_prefix filter_keys.
28
+ denied_keys foo, bar
29
+ </match>
30
+ ```
31
+
32
+ #### ensure_keys
33
+
34
+ The keys to be existed in event logs. If it doesn't match, the event log will be discarded.
35
+
36
+ #### denied_keys
37
+
38
+ The keys to be not existed in event logs. If it matches, the event log will be discarded.
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ desc 'Default: run test.'
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new(:test) do |test|
9
+ test.libs << 'lib' << 'test'
10
+ test.pattern = 'test/**/test_*.rb'
11
+ test.verbose = true
12
+ end
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "fluent-plugin-filter_keys"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Kohei Hasegawa"]
5
+ spec.email = ["ameutau@gmail.com"]
6
+ spec.description = %q{Fluentd plugin to filter if a specific key is present or not in event logs.}
7
+ spec.summary = %q{Fluentd plugin to filter if a specific key is present or not in event logs.}
8
+ spec.homepage = "https://github.com/banyan/fluent-plugin-filter_keys"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_development_dependency "bundler"
17
+ spec.add_development_dependency "rake"
18
+ spec.add_development_dependency "fluentd"
19
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ module Fluent
4
+ class FilterKeysOutput < Output
5
+ include Fluent::HandleTagNameMixin
6
+
7
+ Fluent::Plugin.register_output('filter_keys', self)
8
+
9
+ config_param :ensure_keys, :string, :default => nil
10
+ config_param :denied_keys, :string, :default => nil
11
+
12
+ def configure(conf)
13
+ super
14
+
15
+ if (ensure_keys && denied_keys) || (ensure_keys.nil? && denied_keys.nil?)
16
+ raise ConfigError, "filter_keys: Either ensure_keys or denied_keys are required to be set."
17
+ end
18
+
19
+ @ensure_keys = ensure_keys && ensure_keys.split(/\s*,\s*/)
20
+ @denied_keys = denied_keys && denied_keys.split(/\s*,\s*/)
21
+ end
22
+
23
+ def emit(tag, es, chain)
24
+ es.each { |time, record|
25
+ t = tag.dup
26
+ filter_record(t, time, record)
27
+ if ensure_keys_in?(record) || denied_keys_not_in?(record)
28
+ Engine.emit(t, time, record)
29
+ end
30
+ }
31
+
32
+ chain.next
33
+ end
34
+
35
+ def filter_record(tag, time, record)
36
+ super(tag, time, record)
37
+ end
38
+
39
+ private
40
+ def ensure_keys_in?(record)
41
+ @ensure_keys && @ensure_keys.all? { |key| record.include? key }
42
+ end
43
+
44
+ def denied_keys_not_in?(record)
45
+ @denied_keys && !@denied_keys.any? { |key| record.include? key }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,182 @@
1
+ # coding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'fluent/plugin/out_filter_keys'
5
+
6
+ class FilterKeysOutputTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ end
10
+
11
+ def create_driver(conf, tag = 'test')
12
+ Fluent::Test::OutputTestDriver.new(
13
+ Fluent::FilterKeysOutput, tag
14
+ ).configure(conf)
15
+ end
16
+
17
+ def test_configure_on_success
18
+ d = create_driver(%[
19
+ add_tag_prefix filter_keys.
20
+ ensure_keys zoo, woo
21
+ ])
22
+
23
+ assert_equal 'filter_keys.', d.instance.add_tag_prefix
24
+ assert_equal %w(zoo woo), d.instance.ensure_keys
25
+ end
26
+
27
+ def test_configure_on_failure
28
+ # when mandatory keys not set
29
+ assert_raise(Fluent::ConfigError) do
30
+ create_driver(%[
31
+ blah blah
32
+ ])
33
+ end
34
+
35
+ # when ensure_keys and denied_keys are both set
36
+ assert_raise(Fluent::ConfigError) do
37
+ create_driver(%[
38
+ add_tag_prefix filter_keys.
39
+ ensure_keys zoo, woo
40
+ denied_keys foo, bar
41
+ ])
42
+ end
43
+ end
44
+
45
+ def test_emit_with_ensure_keys_exists
46
+ d = create_driver(%[
47
+ ensure_keys foo
48
+ add_tag_prefix filter_keys.
49
+ ])
50
+
51
+ record = {
52
+ 'foo' => "50",
53
+ 'bar' => "100",
54
+ }
55
+
56
+ d.run { d.emit(record) }
57
+ emits = d.emits
58
+
59
+ assert_equal 1, emits.count
60
+ assert_equal 'filter_keys.test', emits[0][0]
61
+ assert_equal '50', emits[0][2]['foo']
62
+ assert_equal '100', emits[0][2]['bar']
63
+ end
64
+
65
+ def test_emit_with_ensure_keys_exists_on_multiple_arguments
66
+ d = create_driver(%[
67
+ ensure_keys foo, bar
68
+ add_tag_prefix filter_keys.
69
+ ])
70
+
71
+ record = {
72
+ 'foo' => "50",
73
+ 'bar' => "100",
74
+ }
75
+
76
+ d.run { d.emit(record) }
77
+ emits = d.emits
78
+
79
+ assert_equal 1, emits.count
80
+ assert_equal 'filter_keys.test', emits[0][0]
81
+ assert_equal '50', emits[0][2]['foo']
82
+ assert_equal '100', emits[0][2]['bar']
83
+ end
84
+
85
+ def test_emit_with_ensure_keys_not_exists
86
+ d = create_driver(%[
87
+ ensure_keys foo
88
+ add_tag_prefix filter_keys.
89
+ ])
90
+
91
+ record = {
92
+ 'not' => "match",
93
+ 'at' => "all",
94
+ }
95
+
96
+ d.run { d.emit(record) }
97
+ emits = d.emits
98
+
99
+ assert_equal 0, emits.count
100
+ assert_equal [], emits
101
+ end
102
+
103
+ def test_emit_with_ensure_keys_not_exists_on_multiple_arguments
104
+ d = create_driver(%[
105
+ ensure_keys foo, bar
106
+ add_tag_prefix filter_keys.
107
+ ])
108
+
109
+ record = {
110
+ 'foo' => "50",
111
+ }
112
+
113
+ d.run { d.emit(record) }
114
+ emits = d.emits
115
+
116
+ assert_equal 0, emits.count
117
+ assert_equal [], emits
118
+ end
119
+
120
+ def test_emit_with_denied_keys_exists
121
+ d = create_driver(%[
122
+ denied_keys foo
123
+ add_tag_prefix filter_keys.
124
+ ])
125
+
126
+ record = {
127
+ 'foo' => "50",
128
+ 'bar' => "100",
129
+ }
130
+
131
+ d.run { d.emit(record) }
132
+ emits = d.emits
133
+
134
+ assert_equal 0, emits.count
135
+ assert_equal [], emits
136
+ end
137
+
138
+ def test_emit_with_denied_keys_not_exists
139
+ d = create_driver(%[
140
+ denied_keys foo
141
+ add_tag_prefix filter_keys.
142
+ ])
143
+
144
+ record = {
145
+ 'baz' => "50",
146
+ 'bar' => "100",
147
+ }
148
+
149
+ d.run { d.emit(record) }
150
+ emits = d.emits
151
+
152
+ assert_equal 1, emits.count
153
+ assert_equal 'filter_keys.test', emits[0][0]
154
+ assert_equal '50', emits[0][2]['baz']
155
+ assert_equal '100', emits[0][2]['bar']
156
+ end
157
+
158
+ def test_emit_multi_records
159
+ d = create_driver(%[
160
+ add_tag_prefix filter_keys.
161
+ ensure_keys baz
162
+ ])
163
+
164
+ record = {
165
+ 'baz' => "50",
166
+ 'bar' => "100",
167
+ }
168
+
169
+ d.run do
170
+ 3.times { d.emit(record) }
171
+ end
172
+ emits = d.emits
173
+
174
+ assert_equal 3, emits.count
175
+
176
+ emits.each do |e|
177
+ assert_equal 'filter_keys.test', e[0]
178
+ assert_equal '50', e[2]['baz']
179
+ assert_equal '100', e[2]['bar']
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ require 'fluent/test'
7
+
8
+ unless ENV.has_key?('VERBOSE')
9
+ nulllogger = Object.new
10
+ nulllogger.instance_eval {|obj|
11
+ def method_missing(method, *args)
12
+ # pass
13
+ end
14
+ }
15
+ $log = nulllogger
16
+ end
17
+
18
+ class Test::Unit::TestCase
19
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-filter_keys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kohei Hasegawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fluentd
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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'
62
+ description: Fluentd plugin to filter if a specific key is present or not in event
63
+ logs.
64
+ email:
65
+ - ameutau@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - fluent-plugin-filter_keys.gemspec
77
+ - lib/fluent/plugin/out_filter_keys.rb
78
+ - test/plugin/test_out_filter_keys.rb
79
+ - test/test_helper.rb
80
+ homepage: https://github.com/banyan/fluent-plugin-filter_keys
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.23
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Fluentd plugin to filter if a specific key is present or not in event logs.
105
+ test_files:
106
+ - test/plugin/test_out_filter_keys.rb
107
+ - test/test_helper.rb
108
+ has_rdoc: