fluent-plugin-has-keys 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/.gitignore +36 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/Rakefile +12 -0
- data/fluent-plugin-has-keys.gemspec +21 -0
- data/lib/fluent/plugin/filter_has_keys.rb +31 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_filter_has_keys.rb +64 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d001634898485cc3c5a8d46a8b3d837fe6e56f5
|
4
|
+
data.tar.gz: 7744273ba81cf6716ab42b183a0ae50ebbb0c37c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43c260db3859bf75ca21b85f5c48c19ed129bc131a9c66755c99a97357a30d92a3047e15ae54fcbbc6582a3fe8e4a2795d4532edacb529febccfab5e7d8262d8
|
7
|
+
data.tar.gz: 53a4029371a6d0480b4a04e4ef691f61aff18a8228bf73b3e289d1ad059ea2f1a0efeda9baff5d0fb1fabafc746199efb86e6cc897498a33ce52a360f37a58e6
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Trickey
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# fluent-plugin-has-keys
|
2
|
+
This fluentd plugin is to filter records without the given keys.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
fluentd.conf
|
7
|
+
|
8
|
+
```
|
9
|
+
<filter **>
|
10
|
+
@type has_keys
|
11
|
+
keys hoge, foo
|
12
|
+
</filter>
|
13
|
+
```
|
14
|
+
|
15
|
+
Input messages:
|
16
|
+
|
17
|
+
```
|
18
|
+
2016-05-03T11:22:33 test {"hoge" => "fuga", "foo" => "bar"}
|
19
|
+
2016-05-03T11:22:34 test {"hoge" => "fuga"}
|
20
|
+
2016-05-03T11:22:35 test {"foo" => "bar"}
|
21
|
+
2016-05-03T11:22:36 test {"spam" => "ham"}
|
22
|
+
2016-05-03T11:22:37 test {"hoge" => "fuga", "foo" => "bar", "spam" => "ham"}
|
23
|
+
```
|
24
|
+
|
25
|
+
Output messages:
|
26
|
+
|
27
|
+
```
|
28
|
+
2016-05-03T11:22:33 test {"hoge" => "fuga", "foo" => "bar"}
|
29
|
+
2016-05-03T11:22:37 test {"hoge" => "fuga", "foo" => "bar", "spam" => "ham"}
|
30
|
+
```
|
31
|
+
|
32
|
+
## TODO
|
33
|
+
* Check whether this plugin works under a general operation.
|
34
|
+
|
35
|
+
## Copyright
|
36
|
+
Copyright (c) 2016 Trickey
|
37
|
+
Released under the MIT license
|
38
|
+
https://opensource.org/licenses/MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# -*- mode:ruby -*-
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
7
|
+
test.libs << 'lib' << 'test'
|
8
|
+
test.pattern = 'test/**/test_*.rb'
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- mode:ruby -*-
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Trickey"]
|
6
|
+
gem.email = ["cafegentle@gmail.com"]
|
7
|
+
gem.description = %q{Fluentd plugin to filter records without essential keys}
|
8
|
+
gem.summary = %q{Fluentd plugin to filter records without essential keys}
|
9
|
+
gem.homepage = "https://github.com/TrickyMonkey/fluent-plugin-has-keys"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "fluent-plugin-has-keys"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = "0.0.1"
|
18
|
+
|
19
|
+
gem.add_runtime_dependency "fluentd", ">= 0.12.0"
|
20
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Fluent
|
3
|
+
class HasKeysFilter < Filter
|
4
|
+
Fluent::Plugin.register_filter('has_keys', self)
|
5
|
+
|
6
|
+
config_param :keys, :string, :default => nil
|
7
|
+
|
8
|
+
def configure(conf)
|
9
|
+
super
|
10
|
+
@essential_keys = @keys ? @keys.split(",").map(&:strip) : nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def shutdown
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def filter_stream(tag, es)
|
22
|
+
new_es = MultiEventStream.new
|
23
|
+
es.each do |time, record|
|
24
|
+
if @essential_keys.nil? or @essential_keys.all? {|k| record.has_key?(k) }
|
25
|
+
new_es.add(time, record)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return new_es
|
29
|
+
end
|
30
|
+
end if defined?(Filter)
|
31
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/filter_has_keys'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fluent/log'
|
3
|
+
require 'fluent/test'
|
4
|
+
require 'fluent/plugin/filter_has_keys'
|
5
|
+
|
6
|
+
class HasKeysFilterTest < Test::Unit::TestCase
|
7
|
+
include Fluent
|
8
|
+
|
9
|
+
def setup
|
10
|
+
Fluent::Test.setup
|
11
|
+
end
|
12
|
+
|
13
|
+
TAG = 'test'
|
14
|
+
|
15
|
+
def create_driver(conf)
|
16
|
+
Fluent::Test::FilterTestDriver.new(Fluent::HasKeysFilter).configure(conf, TAG)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_emit_with_essential_keys
|
20
|
+
return unless defined? Fluent::Filter
|
21
|
+
|
22
|
+
driver = create_driver(%[ keys hoge, foo ])
|
23
|
+
es = Fluent::MultiEventStream.new
|
24
|
+
|
25
|
+
time = Time.parse("2016-05-06 11:22:33 UTC").to_i
|
26
|
+
driver.run do
|
27
|
+
driver.filter({"hoge" => "fuga", "foo" => "bar"})
|
28
|
+
driver.filter({"hoge" => "fuga"})
|
29
|
+
driver.filter({"foo" => "bar"})
|
30
|
+
driver.filter({"spam" => "ham"})
|
31
|
+
driver.filter({"hoge" => "fuga", "foo" => "bar", "spam" => "ham"})
|
32
|
+
end
|
33
|
+
|
34
|
+
filtered_records = driver.filtered_as_array
|
35
|
+
assert_equal 2, filtered_records.length
|
36
|
+
assert_equal({"hoge" => "fuga", "foo" => "bar"}, filtered_records[0][2])
|
37
|
+
assert_equal({"hoge" => "fuga", "foo" => "bar", "spam" => "ham"}, filtered_records[1][2])
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_emit_without_essential_keys
|
41
|
+
return unless defined? Fluent::Filter
|
42
|
+
|
43
|
+
driver = create_driver(%[ ])
|
44
|
+
es = Fluent::MultiEventStream.new
|
45
|
+
|
46
|
+
time = Time.parse("2016-05-06 11:22:33 UTC").to_i
|
47
|
+
driver.run do
|
48
|
+
driver.filter({"hoge" => "fuga", "foo" => "bar"})
|
49
|
+
driver.filter({"hoge" => "fuga"})
|
50
|
+
driver.filter({"foo" => "bar"})
|
51
|
+
driver.filter({"spam" => "ham"})
|
52
|
+
driver.filter({"hoge" => "fuga", "foo" => "bar", "spam" => "ham"})
|
53
|
+
end
|
54
|
+
|
55
|
+
filtered_records = driver.filtered_as_array
|
56
|
+
assert_equal 5, filtered_records.length
|
57
|
+
assert_equal({"hoge" => "fuga", "foo" => "bar"}, filtered_records[0][2])
|
58
|
+
assert_equal({"hoge" => "fuga"}, filtered_records[1][2])
|
59
|
+
assert_equal({"foo" => "bar"}, filtered_records[2][2])
|
60
|
+
assert_equal({"spam" => "ham"}, filtered_records[3][2])
|
61
|
+
assert_equal({"hoge" => "fuga", "foo" => "bar", "spam" => "ham"}, filtered_records[4][2])
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-has-keys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trickey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-07 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.12.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.12.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.9.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.2
|
41
|
+
description: Fluentd plugin to filter records without essential keys
|
42
|
+
email:
|
43
|
+
- cafegentle@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- fluent-plugin-has-keys.gemspec
|
54
|
+
- lib/fluent/plugin/filter_has_keys.rb
|
55
|
+
- test/helper.rb
|
56
|
+
- test/plugin/test_filter_has_keys.rb
|
57
|
+
homepage: https://github.com/TrickyMonkey/fluent-plugin-has-keys
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Fluentd plugin to filter records without essential keys
|
81
|
+
test_files:
|
82
|
+
- test/helper.rb
|
83
|
+
- test/plugin/test_filter_has_keys.rb
|