fluent-plugin-script 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 681833251ac110f795a5275712827c905b91893b
4
+ data.tar.gz: 7c6ae71bc32bb20f1898bb67671258d0b3f60d1e
5
+ SHA512:
6
+ metadata.gz: 4c52aa57a97b6de84bc69e3fb070e667ee3fca33a6e62e979be5eb849f83c048a0067f4d2313d1690a94887e178593b933c08d2e1dba809b2241a1f1e5ab08ea
7
+ data.tar.gz: 6f27a5df442fd52707e17592b5e59bc4aa6855f01645751cedbd56fec9c860cb9fd1ac4dafb4026b325e431dab1b82fbc3f184631e67f3fd2fefd0158897a74a
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,78 @@
1
+ # fluent-plugin-script
2
+
3
+ Fluent filter plugin to external ruby script
4
+
5
+ ## install
6
+
7
+ ``
8
+ gem install fluent-plugin-filter-script
9
+ ``
10
+
11
+ ## Configuration Example
12
+
13
+ #### fluent.conf
14
+ ```
15
+ <filter foo.bar.*>
16
+ type script
17
+ path /etc/fluentd/example.rb
18
+ </filter>
19
+ ```
20
+
21
+ #### example.rb
22
+
23
+ ```ruby
24
+ def filter(tag, time, record)
25
+ case tag
26
+ when /.+\.code$/
27
+ code(record)
28
+ when /.+\.msg$/
29
+ message(record)
30
+ end
31
+ end
32
+
33
+ def code(record)
34
+ if record.has_key?("key1")
35
+ record["code"] = record["key1"].to_i
36
+ record.delete("key1")
37
+ end
38
+ record
39
+ end
40
+
41
+ def message(record)
42
+ case record["key2"].to_i
43
+ when 100..200
44
+ level = "INFO"
45
+ when 201..300
46
+ level = "WARN"
47
+ else
48
+ level = "ERROR"
49
+ end
50
+ record.delete("key2")
51
+
52
+ record["message"] = level + ":" + record["key3"]
53
+ record.delete("key3")
54
+ record
55
+ end
56
+ ```
57
+
58
+ #### Example 1
59
+ ##### input
60
+ ```
61
+ foo.bar.code: {"key1": "200"}
62
+ ```
63
+
64
+ ##### output
65
+ ```
66
+ foo.bar.code: {"code":200}
67
+ ```
68
+
69
+ #### Example 2
70
+ ##### input
71
+ ```
72
+ foo.bar.msg: {"key2":280,"key3":"Something happend."}
73
+ ```
74
+
75
+ ##### output
76
+ ```
77
+ foo.bar.msg: {"message":"WARN:Something happend."}
78
+ ```
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"
3
+ s.version = "0.0.2"
4
+ s.licenses = ["MIT"]
5
+ s.summary = "Fluentd filter plugin to external ruby script"
6
+ s.description = s.summary
7
+ s.authors = ["SNakano"]
8
+ s.email = ["pp.nakano@gmail.com"]
9
+ s.homepage = "https://github.com/SNakano/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,17 @@
1
+ module Fluent
2
+ class ScriptFilter < Filter
3
+ Plugin.register_filter('script', self)
4
+
5
+ config_param :path, :string
6
+
7
+ def configure(conf)
8
+ load_script_file(conf['path'].to_s)
9
+ end
10
+
11
+ def load_script_file(path)
12
+ raise ConfigError, "Ruby script file does not exist: #{path}" unless File.exist?(path)
13
+ eval "self.instance_eval do;" + IO.read(path) + ";end"
14
+ end
15
+ end
16
+ end
17
+
@@ -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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - SNakano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-10 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
+ - pp.nakano@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/SNakano/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.4.5
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