fluent-plugin-dict-map 0.1.0

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: bd4e2441b2f79a58ae9613eaa8c2b1416b62ae71
4
+ data.tar.gz: a6d72c1e02117f5397623715cf45c44b9b867ca3
5
+ SHA512:
6
+ metadata.gz: da87fd811c9dcb21b3de4b990862eefe6221f47309ee546b0250ce488291725583714c0147d429741070898792b84cdae82c0716d5651475b960654243189f46
7
+ data.tar.gz: b46e61c2961e75c84002c0cfb517473eecc1c84d20e08058876a17d9dbcd4807884aafb6c23e64a00f35e9477bb4a6259e7bb3b076467df76e6f581522728b82
@@ -0,0 +1,7 @@
1
+ Gemfile.lock
2
+ Gemfile.local
3
+ README
4
+ pkg/*
5
+ test/*
6
+ vendor/*
7
+ .ruby-version
@@ -0,0 +1,4 @@
1
+ Release 0.1.0 - 2018/03/05
2
+
3
+ * First release
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,83 @@
1
+ # Dictionary based map filter for [Fluentd](http://fluentd.org)
2
+
3
+ Map field to other value with dictionary
4
+
5
+ ## Installation
6
+
7
+ Use RubyGems:
8
+
9
+ gem install fluent-plugin-dict-map
10
+
11
+ ## Configuration
12
+
13
+ Use `@type dict_map` in `<filter>`.
14
+
15
+ <filter pattern>
16
+ @type dict_map
17
+ key_name level
18
+ dictionary {"I":"INFO","W":"WARN","E":"ERROR"}
19
+ </filter>
20
+
21
+ For example, if following record is passed,
22
+
23
+ ```js
24
+ {"msg":"hello!","level":"I"}
25
+ ```
26
+
27
+ then you got filtered record like below:
28
+
29
+ ```js
30
+ {"msg":"hello!","level":"INFO"}
31
+ ```
32
+
33
+ ### key_name
34
+
35
+ The target key name.
36
+
37
+ ### destination_key_name
38
+
39
+ The destination key name for mapped result. If not specified, the value is overwritten in `key_name`.
40
+
41
+ Example:
42
+
43
+ # configuration
44
+ destination_key_name mapped
45
+ # filtered record
46
+ {"msg":"hello!","level":"I","mapped":"INFO"}
47
+
48
+ ### default_value
49
+
50
+ This value is used when incoming value is missing in the dictionary. If not specified, value mapping doesn't happen.
51
+
52
+ # configuration
53
+ default_value UNKNOWN
54
+ # incoming record
55
+ {"msg":"hello!","level":"Z"}
56
+ # filtered record
57
+ {"msg":"hello!","level":"UNKNOWN"}
58
+
59
+ ### dictionary
60
+
61
+ The json dictionary for value mapping.
62
+
63
+ ### dictionary_path
64
+
65
+ Use json file instead of in-place `dictionary` parameter. This is useful for large dictionary. File ext must be `json`.
66
+
67
+ Example:
68
+
69
+ dictionary_path /path/to/dict.json
70
+
71
+ ## Copyright
72
+
73
+ <table>
74
+ <tr>
75
+ <td>Author</td><td>Masahiro Nakagawa <repeatedly@gmail.com></td>
76
+ </tr>
77
+ <tr>
78
+ <td>Copyright</td><td>Copyright (c) 2018- Masahiro Nakagawa</td>
79
+ </tr>
80
+ <tr>
81
+ <td>License</td><td>Apache 2 License</td>
82
+ </tr>
83
+ </table>
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/test_*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:build]
13
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "foo" : "bar",
3
+ "num" : "100",
4
+ "10" : "ten"
5
+ }
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-dict-map"
6
+ gem.description = "Dictionary based map filter for Fluentd"
7
+ gem.homepage = "https://github.com/repeatedly/fluent-plugin-record-dict-map"
8
+ gem.summary = gem.description
9
+ gem.version = "0.1.0"
10
+ gem.authors = ["Masahiro Nakagawa"]
11
+ gem.email = "repeatedly@gmail.com"
12
+ gem.has_rdoc = false
13
+ #gem.platform = Gem::Platform::RUBY
14
+ gem.license = 'MIT'
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency "fluentd", [">= 1.0", "< 2"]
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ gem.add_development_dependency "test-unit", "~> 3.1"
23
+ end
@@ -0,0 +1,50 @@
1
+ require 'fluent/plugin/filter'
2
+ require 'json'
3
+
4
+ module Fluent::Plugin
5
+ class DictMapFilter < Filter
6
+ Fluent::Plugin.register_filter('dict_map', self)
7
+
8
+ config_param :key_name, :string, :desc => 'The source key name'
9
+ config_param :destination_key_name, :string, :default => nil, :desc => 'The destination key name for mapped result'
10
+ config_param :default_value, :string, :default => nil, :desc => 'The value is used when incoming value is missing in the dictionary'
11
+ config_param :dictionary, :hash, :default => nil, :desc => 'The json dictionary for value mapping'
12
+ config_param :dictionary_path, :string, :default => nil, :desc => 'The path of dictionary file. File ext must be `json`'
13
+
14
+ def configure(conf)
15
+ super
16
+
17
+ if !@dictionary and !@dictionary_path
18
+ raise Fluent::ConfigError, "dictionary or dictionary_path parameter is required"
19
+ end
20
+
21
+ @dict = @dictionary ? @dictionary : load_dict(@dictionary_path)
22
+ @target = @destination_key_name.nil? ? @key_name : @destination_key_name
23
+ end
24
+
25
+ def filter(tag, time, record)
26
+ value = record[@key_name]
27
+ return record unless value
28
+
29
+ if @dict.include?(value)
30
+ record[@target] = @dict[value]
31
+ elsif !@default_value.nil?
32
+ record[@target] = @default_value
33
+ end
34
+
35
+ record
36
+ end
37
+
38
+ private
39
+
40
+ def load_dict(dict_path)
41
+ case
42
+ when dict_path.end_with?(".json")
43
+ require 'json'
44
+ JSON.parse(File.read(dict_path))
45
+ else
46
+ raise Fluent::ConfigError, "Invalid file type. Supported type is only JSON: #{dict_path}"
47
+ end
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-dict-map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro Nakagawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-06 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: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.2
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: test-unit
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.1'
61
+ description: Dictionary based map filter for Fluentd
62
+ email: repeatedly@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ChangeLog
69
+ - Gemfile
70
+ - README.md
71
+ - Rakefile
72
+ - example/dict.json
73
+ - fluent-plugin-dict-map.gemspec
74
+ - lib/fluent/plugin/filter_dict_map.rb
75
+ homepage: https://github.com/repeatedly/fluent-plugin-record-dict-map
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.13
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Dictionary based map filter for Fluentd
99
+ test_files: []