fluent-plugin-named_pipe 0.1.0

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: eee85e2fbf3e52df81b72475238c435dce417ee7
4
+ data.tar.gz: ba29697a82c0f05ad6d55624bd4bd56af36aa410
5
+ SHA512:
6
+ metadata.gz: 9efcfa764c8b4dc21be6d381165b18dead49d2bd7521a9a105c978684a8a6c286cd2f0abd56e120c39c53d6c3317e1bcfe6c4611c5e40b399e494784f56ca625
7
+ data.tar.gz: ef59af3499e6116275c6a4fce0347502e818b6ecae1e85d788789d0b356ce679a1b9d9b0b1f1c6f00a95243e5986003abb151ed4f0a8b4e34bf903bcb68fff16
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ coverage
12
+ .yardoc
13
+ .ruby-version
14
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format Fuubar
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.*
5
+ gemfile:
6
+ - Gemfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (2014/11/22)
2
+
3
+ First version
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naotoshi Seo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # fluent-plugin-named_pipe
2
+
3
+ [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-named_pipe.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-named_pipe)
4
+
5
+ Named pipe input/output plugin for Fluentd.
6
+
7
+ # Input Plugin
8
+
9
+ ## Configuration
10
+
11
+ ```apache
12
+ <source>
13
+ type named_pipe
14
+ path /path/to/file
15
+ tag foo.bar
16
+ format ltsv
17
+ </match>
18
+ ```
19
+
20
+ ## Parameters
21
+
22
+ - path
23
+
24
+ The file path of the named pipe
25
+
26
+ - tag
27
+
28
+ The emit tag name
29
+
30
+ - format
31
+
32
+ The input format such as regular expression, `apache2`, `ltsv`, etc. Same with `in_tail` plugin. See http://docs.fluentd.org/articles/in_tail
33
+
34
+ # Output Plugin
35
+
36
+ ## Configuration
37
+
38
+ ```apache
39
+ <match foo.bar.**>
40
+ type named_pipe
41
+ path /path/to/file
42
+ </match>
43
+ ```
44
+
45
+ The output to the named pipe would be like:
46
+
47
+ ```
48
+ foo.bar: {"foo":"bar"}
49
+ ```
50
+
51
+ ## Parameters
52
+
53
+ - path
54
+
55
+ The file path of the named pipe
56
+
57
+ - format
58
+
59
+ The output format such as `out_file`, `json`, `ltsv`, `single_value`. Default is `out_file`.
60
+
61
+ ## ChangeLog
62
+
63
+ See [CHANGELOG.md](CHANGELOG.md) for details.
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new [Pull Request](../../pull/new/master)
72
+
73
+ ## Copyright
74
+
75
+ Copyright (c) 2014 Naotoshi Seo. See [LICENSE](LICENSE) for details.
76
+
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ desc 'Run test_unit based test'
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.test_files = Dir["test/**/test_*.rb"].sort
9
+ t.verbose = true
10
+ #t.warning = true
11
+ end
12
+ task :default => :test
13
+
14
+ desc 'Open an irb session preloaded with the gem library'
15
+ task :console do
16
+ sh 'irb -rubygems -I lib'
17
+ end
18
+ task :c => :console
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-named_pipe"
6
+ s.version = "0.1.0"
7
+ s.authors = ["Naotoshi Seo"]
8
+ s.email = ["sonots@gmail.com"]
9
+ s.homepage = "https://github.com/sonots/fluent-plugin-named_pipe"
10
+ s.summary = "Named pipe input/output plugin for Fluentd"
11
+ s.description = s.summary
12
+ s.licenses = ["MIT"]
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency "fluentd"
20
+ s.add_runtime_dependency "ruby-fifo"
21
+ if RUBY_PLATFORM =~ /mswin|mingw/i
22
+ s.add_runtime_dependency "win32-pipe"
23
+ else
24
+ s.add_runtime_dependency "mkfifo"
25
+ end
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency "test-unit"
28
+ s.add_development_dependency "pry"
29
+ s.add_development_dependency "pry-nav"
30
+ end
@@ -0,0 +1,68 @@
1
+ module Fluent
2
+ class NamedPipeInput < Input
3
+ Fluent::Plugin.register_input('named_pipe', self)
4
+
5
+ config_param :path, :string
6
+ config_param :tag, :string
7
+ config_param :format, :string
8
+
9
+ unless method_defined?(:log)
10
+ define_method(:log) { $log }
11
+ end
12
+
13
+ def initialize
14
+ require 'fifo'
15
+ super
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+
21
+ begin
22
+ pipe = Fifo.new(@path, :r, :nowait)
23
+ pipe.close # just to try open
24
+ rescue => e
25
+ raise ConfigError, "#{e.class}: #{e.message}"
26
+ end
27
+
28
+ config['format'] = @format
29
+ configure_parser(conf)
30
+ end
31
+
32
+ def configure_parser(conf)
33
+ @parser = TextParser.new
34
+ @parser.configure(conf)
35
+ end
36
+
37
+ def start
38
+ super
39
+ @running = true
40
+ @thread = Thread.new(&method(:run))
41
+ end
42
+
43
+ def shutdown
44
+ @running = false
45
+ @thread.join
46
+ @pipe.close
47
+ end
48
+
49
+ def run
50
+ @pipe = Fifo.new(@path, :r, :wait)
51
+
52
+ while @running
53
+ begin
54
+ line = @pipe.readline # blocking
55
+ time, record = @parser.parse(line)
56
+ if time and record
57
+ Engine.emit(@tag, time, record)
58
+ else
59
+ log.warn "Pattern not match: #{line.inspect}"
60
+ end
61
+ rescue => e
62
+ log.error "in_named_pipe: unexpected error", :error_class => e.class, :error => e.to_s
63
+ log.error_backtrace
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,46 @@
1
+ module Fluent
2
+ class NamedPipeOutput < Output
3
+ Plugin.register_output('named_pipe', self)
4
+
5
+ config_param :path, :string
6
+ config_param :format, :string, :default => 'out_file'
7
+
8
+ unless method_defined?(:log)
9
+ define_method(:log) { $log }
10
+ end
11
+
12
+ def initialize
13
+ require 'fifo'
14
+ super
15
+ end
16
+
17
+ def configure(conf)
18
+ super
19
+
20
+ begin
21
+ @pipe = Fifo.new(@path, :w, :nowait)
22
+ rescue => e
23
+ raise ConfigError, "#{e.class}: #{e.message}"
24
+ end
25
+
26
+ conf['format'] = @format
27
+ @formatter = TextFormatter.create(conf)
28
+ end
29
+
30
+ def shutdown
31
+ @pipe.close
32
+ end
33
+
34
+ def emit(tag, es, chain)
35
+ es.each do |time, record|
36
+ @pipe.write @formatter.format(tag, time, record)
37
+ end
38
+
39
+ chain.next
40
+ rescue => e
41
+ log.error "out_named_pipe: unexpected error", :error_class => e.class, :error => e.to_s
42
+ log.error_backtrace
43
+ end
44
+ end
45
+ end
46
+
data/test/helper.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'fluent/log'
3
+ require 'fluent/test'
4
+
5
+ unless defined?(Test::Unit::AssertionFailedError)
6
+ class Test::Unit::AssertionFailedError < StandardError
7
+ end
8
+ end
9
+
10
+ # Stop non required sleep at
11
+ # https://github.com/fluent/fluentd/blob/018791f6b1b0400b71e37df2fb3ad80e456d2c11/lib/fluent/test/base.rb#L56
12
+ # module Fluent
13
+ # module Test
14
+ # class TestDriver
15
+ # def run(&block)
16
+ # @instance.start
17
+ # begin
18
+ # # wait until thread starts
19
+ # # 10.times { sleep 0.05 }
20
+ # return yield
21
+ # ensure
22
+ # @instance.shutdown
23
+ # end
24
+ # end
25
+ # end
26
+ # end
27
+ # end
@@ -0,0 +1,58 @@
1
+ require_relative 'helper'
2
+ require 'fluent/test'
3
+ require 'fluent/plugin/in_named_pipe'
4
+
5
+ class NamedPipeInputTest < Test::Unit::TestCase
6
+ TEST_PATH = 'in_named_pipe'
7
+
8
+ setup do
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ teardown do
13
+ File.unlink(TEST_PATH) rescue nil
14
+ end
15
+
16
+ def create_driver(conf)
17
+ Fluent::Test::InputTestDriver.new(Fluent::NamedPipeInput).configure(conf)
18
+ end
19
+
20
+ sub_test_case 'configure' do
21
+ test 'required parameters' do
22
+ assert_raise_message("'path' parameter is required") do
23
+ create_driver(%[
24
+ tag foo
25
+ ])
26
+ end
27
+
28
+ assert_raise_message("'tag' parameter is required") do
29
+ create_driver(%[
30
+ path #{TEST_PATH}
31
+ ])
32
+ end
33
+ end
34
+ end
35
+
36
+ sub_test_case "emit" do
37
+ CONFIG = %[
38
+ path #{TEST_PATH}
39
+ tag named_pipe
40
+ format ltsv
41
+ ]
42
+
43
+ test 'read and emit' do
44
+ d = create_driver(CONFIG)
45
+ d.run {
46
+ pipe = Fifo.new(TEST_PATH, :w, :nowait)
47
+ pipe.write "foo:bar\n"
48
+ }
49
+
50
+ emits = d.emits
51
+ emits.each do |tag, time, record|
52
+ assert_equal("named_pipe", tag)
53
+ assert_equal({"foo"=>"bar\n"}, record)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,71 @@
1
+ require_relative 'helper'
2
+ require 'fluent/test'
3
+ require 'fluent/plugin/out_named_pipe'
4
+ require 'fifo'
5
+
6
+ Fluent::Test.setup
7
+
8
+ class NamedPipeOutputTest < Test::Unit::TestCase
9
+ TEST_PATH = "out_named_pipe"
10
+
11
+ setup do
12
+ @tag = 'foo.bar'
13
+ end
14
+
15
+ teardown do
16
+ File.unlink(TEST_PATH) rescue nil
17
+ end
18
+
19
+ def create_driver(conf)
20
+ Fluent::Test::OutputTestDriver.new(Fluent::NamedPipeOutput, @tag).configure(conf)
21
+ end
22
+
23
+ sub_test_case 'configure' do
24
+ test 'required parameter' do
25
+ assert_raise_message("'path' parameter is required") do
26
+ create_driver('')
27
+ end
28
+
29
+ d = create_driver(%[path #{TEST_PATH}])
30
+ assert_equal TEST_PATH, d.instance.path
31
+ end
32
+
33
+ test 'option parameter' do
34
+ config = %[
35
+ path #{TEST_PATH}
36
+ ]
37
+ d = create_driver(config + %[format ltsv])
38
+ assert_equal TEST_PATH, d.instance.path
39
+ end
40
+ end
41
+
42
+ sub_test_case 'write' do
43
+ CONFIG = %[
44
+ path #{TEST_PATH}
45
+ format ltsv
46
+ ]
47
+
48
+ test 'reader is waiting' do
49
+ readline = nil
50
+ thread = Thread.new {
51
+ pipe = Fifo.new(TEST_PATH, :r, :wait)
52
+ readline = pipe.readline
53
+ }
54
+
55
+ d = create_driver(CONFIG)
56
+ d.run do
57
+ d.emit({'foo' => 'bar'})
58
+ end
59
+
60
+ thread.join
61
+ assert_equal "foo:bar\n", readline
62
+ end
63
+
64
+ test 'reader is not waiting' do
65
+ d = create_driver(CONFIG)
66
+ assert_nothing_raised do
67
+ d.emit({'foo' => 'bar'})
68
+ end
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-named_pipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-21 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: ruby-fifo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mkfifo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rake
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: test-unit
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
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Named pipe input/output plugin for Fluentd
112
+ email:
113
+ - sonots@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CHANGELOG.md
122
+ - Gemfile
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - fluent-plugin-named_pipe.gemspec
127
+ - lib/fluent/plugin/in_named_pipe.rb
128
+ - lib/fluent/plugin/out_named_pipe.rb
129
+ - test/helper.rb
130
+ - test/test_in_named_pipe.rb
131
+ - test/test_out_named_pipe.rb
132
+ homepage: https://github.com/sonots/fluent-plugin-named_pipe
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Named pipe input/output plugin for Fluentd
156
+ test_files:
157
+ - test/helper.rb
158
+ - test/test_in_named_pipe.rb
159
+ - test/test_out_named_pipe.rb