fluent-plugin-ruby_one_liner 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: ee8982dd5c09e3e52bc04221f58e68fb8b1f1e2e
4
+ data.tar.gz: 16a2c28532ab18063c073afa1513c5ba1b837ea6
5
+ SHA512:
6
+ metadata.gz: 7da6bd78b617c8d11c1141b3460663ab50b0b2cb180e47bc5182bd1322c0d1d148f162de048137917bbcf4082bc92a1659ec0ac8ca28721e3eb819d49d5bd37f
7
+ data.tar.gz: c7a9acbe948b1d2b70348dbe614ae2d90356cf4408995553b577604e9409da46fabe0b3f3ae0373322c51c25ed0e1dcff31d1f18b86fa1192b3df059f21fc229
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ vendor
19
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # fluent-plugin-ruby_one_liner
2
+
3
+ Run ruby one line of script in this plugin.
4
+
5
+ ## Input Plugin
6
+
7
+ ````
8
+ <source>
9
+ type ruby_one_liner
10
+ require_libs open-uri
11
+ command Engine.emit('hoge',Engine.now,{'hoge' => @config['any_config']})
12
+ run_interval 120
13
+ any_config 2
14
+ </source>
15
+
16
+ <match hoge.**>
17
+ type stdout
18
+ </match>
19
+ ````
20
+
21
+ ````
22
+ 2014-02-03 00:38:58 +0900 hoge: {"hoge":"2"}
23
+ ````
24
+
25
+ ## Output Plugin
26
+
27
+ ````
28
+ <source>
29
+ type exec
30
+ command echo http://example.com
31
+ keys uri
32
+ tag example
33
+ run_interval 5s
34
+ </source>
35
+
36
+ <match example.**>
37
+ type ruby_one_liner
38
+ require_libs open-uri
39
+ command puts time; puts record['uri']; puts @config['any_config']
40
+ run_interval 120
41
+ any_config 2
42
+ </match>
43
+ ````
44
+
45
+ ````
46
+ 1397928852
47
+ http://example.com
48
+ 2
49
+ ````
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-ruby_one_liner"
7
+ spec.version = '0.0.2'
8
+ spec.authors = ["bash0C7"]
9
+ spec.email = ["koshiba+github@4038nullpointer.com"]
10
+ spec.description = "Fluentd plugin to run ruby one line of script"
11
+ spec.summary = "Fluentd plugin to run ruby one line of script"
12
+ spec.homepage = "https://github.com/bash0C7/fluent-plugin-ruby_one_liner"
13
+ spec.license = "Ruby's"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "fluentd"
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,44 @@
1
+ module Fluent
2
+ class Fluent::RubyOneLinerInput < Fluent::Input
3
+ Fluent::Plugin.register_input('ruby_one_liner', self)
4
+
5
+ config_param :require_libs, :string,:default => ''
6
+ config_param :command, :string
7
+ config_param :run_interval, :integer
8
+
9
+ def initialize
10
+ super
11
+ end
12
+
13
+ def configure(config)
14
+ super
15
+
16
+ libs = @require_libs.split(',')
17
+ libs.each {|lib| require lib}
18
+
19
+ @config = config
20
+ @lambda = eval("lambda {#{@command}}")
21
+ end
22
+
23
+ def start
24
+ super
25
+ @thread = Thread.new(&method(:run))
26
+ end
27
+
28
+ def run
29
+ loop do
30
+ begin
31
+ @lambda.call
32
+ sleep @run_interval
33
+ rescue
34
+ $log.warn "raises exception: #{$!.class}, '#{$!.message}, #{param}'"
35
+ end
36
+ end
37
+ end
38
+
39
+ def shutdown
40
+ Thread.kill(@thread)
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,70 @@
1
+ module Fluent
2
+ class Fluent::RubyOneLinerOutput < Fluent::Output
3
+ Fluent::Plugin.register_output('ruby_one_liner', self)
4
+
5
+ config_param :require_libs, :string,:default => ''
6
+ config_param :command, :string
7
+ config_param :run_interval, :integer
8
+
9
+ def initialize
10
+ super
11
+ end
12
+
13
+ def configure(config)
14
+ super
15
+
16
+ libs = @require_libs.split(',')
17
+ libs.each {|lib| require lib}
18
+
19
+ @config = config
20
+ @lambda = eval("lambda {|tag, time, record| #{@command}}")
21
+ @q = Queue.new
22
+ end
23
+
24
+ def start
25
+ super
26
+
27
+ @thread = Thread.new(&method(:run))
28
+ rescue
29
+ $log.warn "raises exception: #{$!.class}, '#{$!.message}"
30
+ end
31
+
32
+ def shutdown
33
+ super
34
+
35
+ Thread.kill(@thread)
36
+ end
37
+
38
+ def emit(tag, es, chain)
39
+ es.each {|time, record|
40
+ param = OpenStruct.new
41
+ param.tag = tag
42
+ param.time = time
43
+ param.record = record
44
+
45
+ @q.push param
46
+ }
47
+
48
+ chain.next
49
+ end
50
+
51
+ private
52
+
53
+ def run
54
+ loop do
55
+ param = @q.pop
56
+ tag = param.tag
57
+ time = param.time
58
+ record = param.record
59
+
60
+ begin
61
+ @lambda.call tag, time, record
62
+ sleep @run_interval
63
+ rescue
64
+ $log.warn "raises exception: #{$!.class}, '#{$!.message}, #{param}'"
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe do
4
+ let(:driver) {Fluent::Test::InputTestDriver.new(Fluent::RubyOneLinerInput).configure(config)}
5
+
6
+ describe 'emit' do
7
+ let(:tag) {'test.metrics'}
8
+ let(:record1) {{ 'field1' => 50, 'otherfield' => 99}}
9
+ let(:time) {0}
10
+
11
+ context do
12
+ let(:config) {
13
+ %[
14
+ require_libs open-uri
15
+ command Engine.emit('test.metrics', 0, {'field1' => 50, 'otherfield' => 99})
16
+ run_interval 1
17
+ ]
18
+ }
19
+
20
+ it do
21
+ d = driver
22
+ d.run do
23
+ sleep 2
24
+ end
25
+ emits = d.emits
26
+
27
+ expect(emits.size).to be >= 1
28
+ expect(emits[0]).to eq([tag, time, record1])
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe do
4
+ let(:driver) {Fluent::Test::OutputTestDriver.new(Fluent::RubyOneLinerOutput, tag).configure(config)}
5
+
6
+ describe 'emit' do
7
+ let(:tag) {'test.metrics'}
8
+ let(:record1) {{ 'field1' => 50, 'otherfield' => 99}}
9
+ let(:record2) {{ 'field1' => 150, 'otherfield' => 199}}
10
+ let(:time) {0}
11
+
12
+ context do
13
+ let(:config) {
14
+ %[
15
+ require_libs open-uri
16
+ command Engine.emit(tag, time, record)
17
+ run_interval 0
18
+ ]
19
+ }
20
+
21
+ it do
22
+ d = driver
23
+
24
+ d.run do
25
+ d.emit(record1, Time.at(time))
26
+ d.emit(record2, Time.at(time))
27
+ sleep 1
28
+ end
29
+ emits = d.emits
30
+
31
+ expect(emits.size).to eq(2)
32
+ expect(emits[0]).to eq([tag, time, record1])
33
+ expect(emits[1]).to eq([tag, time, record2])
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = 'random'
16
+
17
+ require 'pry'
18
+
19
+ require 'fluent/load'
20
+ require 'fluent/test'
21
+
22
+ require 'fluent/plugin/in_ruby_one_liner'
23
+ require 'fluent/plugin/out_ruby_one_liner'
24
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-ruby_one_liner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - bash0C7
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-29 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Fluentd plugin to run ruby one line of script
84
+ email:
85
+ - koshiba+github@4038nullpointer.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - fluent-plugin-ruby_one_liner.gemspec
96
+ - lib/fluent/plugin/in_ruby_one_liner.rb
97
+ - lib/fluent/plugin/out_ruby_one_liner.rb
98
+ - spec/lib/fluent/plugin/in_ruby_one_liner_spec.rb
99
+ - spec/lib/fluent/plugin/out_ruby_one_liner_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/bash0C7/fluent-plugin-ruby_one_liner
102
+ licenses:
103
+ - Ruby's
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.0
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Fluentd plugin to run ruby one line of script
125
+ test_files:
126
+ - spec/lib/fluent/plugin/in_ruby_one_liner_spec.rb
127
+ - spec/lib/fluent/plugin/out_ruby_one_liner_spec.rb
128
+ - spec/spec_helper.rb