fluent-plugin-script-filter 0.0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09bdc6238083ca2bcbe6a5a0c395c4f93bf92287
4
+ data.tar.gz: 5f5943d8de10241de444af680b2d80a87002e826
5
+ SHA512:
6
+ metadata.gz: be35f929697e222368a5b750b1671b6bf2ac023dc666d2bfbe4b016a1883902b350d4542623b055078e1aa2823088fa6f28dc3ca6fab47c6c29bd69dd327d7fb
7
+ data.tar.gz: 731905af425fd9352b450098d760999d41f99e11618163bb1f0523134fb846aba5cd6da6f6fe4636b520914aa306459c42c15f1691917349243b3a49a1e2fdc0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.2"
4
+ - "2.1.6"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 SNakano
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.
22
+
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # fluent-plugin-script
2
+
3
+ Fluent filter plugin to external ruby script.
4
+
5
+ [![Build Status](https://travis-ci.org/SNakano/fluent-plugin-script.svg)](https://travis-ci.org/SNakano/fluent-plugin-script)
6
+ [![Gem](https://img.shields.io/gem/dt/fluent-plugin-script.svg)](https://rubygems.org/gems/fluent-plugin-script)
7
+
8
+ ## install
9
+
10
+ ``
11
+ gem install fluent-plugin-filter-script
12
+ ``
13
+
14
+ ## Configuration
15
+
16
+ #### fluent.conf
17
+ ```
18
+ <filter foo.bar.*>
19
+ type script
20
+ path /etc/fluentd/example.rb
21
+ </filter>
22
+ ```
23
+
24
+ #### external ruby script
25
+
26
+ ```
27
+ def start
28
+ super
29
+ # This is the first method to be called when it starts running
30
+ # Use it to allocate resources, etc.
31
+ end
32
+
33
+ def shutdown
34
+ super
35
+ # This method is called when Fluentd is shutting down.
36
+ # Use it to free up resources, etc.
37
+ end
38
+
39
+ def filter(tag, time, record)
40
+ # This method implements the filtering logic for individual filters
41
+ record
42
+ end
43
+
44
+ ```
45
+
46
+ ref. http://docs.fluentd.org/articles/plugin-development#filter-plugins
47
+
48
+ ## Example
49
+
50
+ #### example.rb
51
+
52
+ ```ruby
53
+ def filter(tag, time, record)
54
+ case tag
55
+ when /.+\.code$/
56
+ code(record)
57
+ when /.+\.msg$/
58
+ message(record)
59
+ end
60
+ end
61
+
62
+ def code(record)
63
+ if record.has_key?("key1")
64
+ record["code"] = record["key1"].to_i
65
+ record.delete("key1")
66
+ end
67
+ record
68
+ end
69
+
70
+ def message(record)
71
+ case record["key2"].to_i
72
+ when 100..200
73
+ level = "INFO"
74
+ when 201..300
75
+ level = "WARN"
76
+ else
77
+ level = "ERROR"
78
+ end
79
+ record.delete("key2")
80
+
81
+ record["message"] = level + ":" + record["key3"]
82
+ record.delete("key3")
83
+ record
84
+ end
85
+ ```
86
+
87
+ #### Example 1
88
+ ##### input
89
+ ```
90
+ foo.bar.code: {"key1": "200"}
91
+ ```
92
+
93
+ ##### output
94
+ ```
95
+ foo.bar.code: {"code":200}
96
+ ```
97
+
98
+ #### Example 2
99
+ ##### input
100
+ ```
101
+ foo.bar.msg: {"key2":280,"key3":"Something happend."}
102
+ ```
103
+
104
+ ##### output
105
+ ```
106
+ foo.bar.msg: {"message":"WARN:Something happend."}
107
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << "lib" << "test"
7
+ test.pattern = "test/**/test_*.rb"
8
+ test.verbose = true
9
+ end
10
+
11
+ task default: :test
data/example.rb ADDED
@@ -0,0 +1,32 @@
1
+ def filter(tag, time, record)
2
+ case tag
3
+ when /.+\.code$/
4
+ code(record)
5
+ when /.+\.msg$/
6
+ message(record)
7
+ end
8
+ end
9
+
10
+ def code(record)
11
+ if record.has_key?("key1")
12
+ record["code"] = record["key1"].to_i
13
+ record.delete("key1")
14
+ end
15
+ record
16
+ end
17
+
18
+ def message(record)
19
+ case record["key2"].to_i
20
+ when 100..200
21
+ level = "INFO"
22
+ when 201..300
23
+ level = "WARN"
24
+ else
25
+ level = "ERROR"
26
+ end
27
+ record.delete("key2")
28
+
29
+ record["message"] = level + ":" + record["key3"]
30
+ record.delete("key3")
31
+ record
32
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "fluent-plugin-script-filter"
3
+ s.version = "0.0.3.1"
4
+ s.licenses = ["MIT"]
5
+ s.summary = "Fluentd filter plugin to external ruby script"
6
+ s.description = s.summary
7
+ s.authors = ["KushalBhandari"]
8
+ s.email = ["kushwiz@gmail.com"]
9
+ s.homepage = "https://github.com/kushwiz/fluent-plugin-script"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files -- test/*`.split("\n")
12
+ s.require_paths = ["lib"]
13
+
14
+ s.add_runtime_dependency "fluentd", "~> 0.12"
15
+ s.add_development_dependency "rake", "~> 10.4.2"
16
+ s.add_development_dependency "test-unit", "~> 3.1.3"
17
+ end
@@ -0,0 +1,22 @@
1
+ module Fluent
2
+ class ScriptFilter < Filter
3
+ Plugin.register_filter('script', self)
4
+
5
+ config_param :path, :string
6
+
7
+ def filter(tag, time, record)
8
+ record
9
+ end
10
+
11
+ def configure(conf)
12
+ super
13
+ load_script_file(conf['path'].to_s)
14
+ end
15
+
16
+ def load_script_file(path)
17
+ raise ConfigError, "Ruby script file does not exist: #{path}" unless File.exist?(path)
18
+ eval "self.instance_eval do;" + IO.read(path) + ";end"
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,4 @@
1
+ def filter(tag, time, record)
2
+ record['message'].gsub!(/GET/, "PUT")
3
+ record
4
+ end
@@ -0,0 +1,46 @@
1
+ require 'test/unit'
2
+ require 'fluent/log'
3
+ require 'fluent/test'
4
+ require 'fluent/plugin/filter_script'
5
+
6
+ class RubyFilterTest < Test::Unit::TestCase
7
+ include Fluent
8
+
9
+ setup do
10
+ Fluent::Test.setup
11
+ end
12
+
13
+ def create_driver(conf = '')
14
+ Test::FilterTestDriver.new(ScriptFilter).configure(conf, true)
15
+ end
16
+
17
+ sub_test_case 'configure' do
18
+ test 'not set required' do
19
+ conf = ''
20
+ assert_raises(ConfigError) { create_driver(conf) }
21
+ end
22
+ test 'wrong file path' do
23
+ conf = 'path /not-exit-ruby-file-path'
24
+ assert_raises(ConfigError) { create_driver(conf) }
25
+ end
26
+ test 'file exist' do
27
+ conf = "path #{__dir__}/example.rb"
28
+ assert_nothing_raised { create_driver(conf) }
29
+ end
30
+ end
31
+
32
+ sub_test_case 'filter' do
33
+ def emit(conf, msg)
34
+ d = create_driver(conf)
35
+ d.run {
36
+ d.emit({'foo' => 'bar', 'message' => msg}, Fluent::Engine.now)
37
+ }.filtered
38
+ end
39
+ test 'execute filter' do
40
+ conf = "path #{__dir__}/example.rb"
41
+ msg = "2015/02/10T01:10:20.123456 INFO GET /ping"
42
+ es = emit(conf, msg)
43
+ assert_equal("2015/02/10T01:10:20.123456 INFO PUT /ping", es.first[1]['message'])
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-script-filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - KushalBhandari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-27 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'
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.4.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.4.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.3
55
+ description: Fluentd filter plugin to external ruby script
56
+ email:
57
+ - kushwiz@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - example.rb
69
+ - fluent-plugin-script.gemspec
70
+ - lib/fluent/plugin/filter_script.rb
71
+ - test/plugin/example.rb
72
+ - test/plugin/test_filter_script.rb
73
+ homepage: https://github.com/kushwiz/fluent-plugin-script
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.10
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Fluentd filter plugin to external ruby script
97
+ test_files:
98
+ - test/plugin/example.rb
99
+ - test/plugin/test_filter_script.rb