fluent-plugin-tcp-client 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55d3d66e50383de883f0b96b3dbda9b11aaf018c
4
+ data.tar.gz: 9f9fc07d5bf60422e8013a7e612d55d63c8aa376
5
+ SHA512:
6
+ metadata.gz: b5efa08171a884902ca46264763b6e280bc0c86c7bf5cb726033c830e2d23760ab6d7612e8bf6d52576b62befad437abe791de931df9f8ec3992e921baca8b2f
7
+ data.tar.gz: b7fc7d6de33069e9e6bb4b3e1940a0595fcb41f7546c77283689e7109218c04465c015f4325d8c8a2b3e6f2aff9127061171cf3072939a9470fd63f52b0402c0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-tcp-client.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-tcp-client (0.1.0)
5
+ fluentd (~> 0.14.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ cool.io (1.4.6)
11
+ fluentd (0.14.11)
12
+ cool.io (~> 1.4.5)
13
+ http_parser.rb (>= 0.5.1, < 0.7.0)
14
+ msgpack (>= 0.7.0, < 2.0.0)
15
+ serverengine (>= 2.0.4, < 3.0.0)
16
+ sigdump (~> 0.2.2)
17
+ strptime (~> 0.1.7)
18
+ tzinfo (~> 1.0)
19
+ tzinfo-data (~> 1.0)
20
+ yajl-ruby (~> 1.0)
21
+ http_parser.rb (0.6.0)
22
+ msgpack (1.0.3)
23
+ power_assert (0.4.1)
24
+ rake (11.3.0)
25
+ serverengine (2.0.4)
26
+ sigdump (~> 0.2.2)
27
+ sigdump (0.2.4)
28
+ strptime (0.1.9)
29
+ test-unit (3.2.3)
30
+ power_assert
31
+ thread_safe (0.3.5)
32
+ tzinfo (1.2.2)
33
+ thread_safe (~> 0.1)
34
+ tzinfo-data (1.2016.10)
35
+ tzinfo (>= 1.0.0)
36
+ yajl-ruby (1.3.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ fluent-plugin-tcp-client!
43
+ rake (~> 11.0)
44
+ test-unit (~> 3.2)
45
+
46
+ BUNDLED WITH
47
+ 1.13.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Active Shadow LLC
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.
@@ -0,0 +1,12 @@
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.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:test]
@@ -0,0 +1,24 @@
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-tcp-client"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Bryan Richardson"]
9
+ spec.email = ["bryan@activeshadow.com"]
10
+ spec.description = %q{Fluentd output plugin for persistent TCP connections}
11
+ spec.summary = %q{Fluentd output plugin for persistent TCP connections}
12
+ spec.homepage = "https://github.com/activeshadow/fluent-plugin-tcp-client"
13
+ spec.license = "MIT"
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", ["~> 0.14.0"]
21
+
22
+ spec.add_development_dependency "rake", ["~> 11.0"]
23
+ spec.add_development_dependency "test-unit", ["~> 3.2"]
24
+ end
@@ -0,0 +1,77 @@
1
+ require 'fluent/plugin/output'
2
+
3
+ module Fluent::Plugin
4
+ class TCPClientOutput < Output
5
+ Fluent::Plugin.register_output('tcp_client', self)
6
+
7
+ helpers :formatter, :compat_parameters
8
+
9
+ def initialize
10
+ super
11
+ end
12
+
13
+ config_param :host, :string, default: '127.0.0.1'
14
+ config_param :port, :integer, default: nil
15
+
16
+ config_section :format do
17
+ config_set_default :@type, 'json'
18
+ end
19
+
20
+ attr_reader :formatter # for testing
21
+
22
+ def configure(conf)
23
+ compat_parameters_convert(conf, :formatter)
24
+
25
+ super
26
+
27
+ @formatter = formatter_create
28
+ @sock = nil
29
+ end
30
+
31
+ def start
32
+ super
33
+ connect
34
+ end
35
+
36
+ def shutdown
37
+ super
38
+ disconnect
39
+ end
40
+
41
+ def format(tag, time, record)
42
+ @formatter.format(tag, time, record)
43
+ end
44
+
45
+ def write(chunk)
46
+ connect
47
+ tries ||= 3
48
+
49
+ chunk.write_to(@sock)
50
+ rescue => e
51
+ if (tries -= 1) > 0
52
+ reconnect
53
+ retry
54
+ else
55
+ $log.warn("Failed writing data to socket: #{e}")
56
+ end
57
+ end
58
+
59
+ #######
60
+ private
61
+ #######
62
+
63
+ def connect
64
+ @sock ||= TCPSocket.new(@host, @port)
65
+ end
66
+
67
+ def disconnect
68
+ @sock.close rescue nil
69
+ @sock = nil
70
+ end
71
+
72
+ def reconnect
73
+ disconnect
74
+ connect
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'test/unit'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+
16
+ require 'fluent/test'
17
+ require 'fluent/test/helpers'
18
+
19
+ include Fluent::Test::Helpers
20
+
21
+ unless ENV.has_key?('VERBOSE')
22
+ nulllogger = Object.new
23
+
24
+ nulllogger.instance_eval {|obj|
25
+ def method_missing(method, *args); end
26
+ }
27
+
28
+ $log = nulllogger
29
+ end
30
+
31
+ require 'fluent/plugin/out_tcp_client'
32
+
33
+ class Test::Unit::TestCase; end
@@ -0,0 +1,82 @@
1
+ require 'helper'
2
+ require 'fluent/test/driver/output'
3
+
4
+ class TCPClientOutputTest < Test::Unit::TestCase
5
+ setup do
6
+ Fluent::Test.setup
7
+ @port = rand(20000..30000)
8
+ start_stub_socket(@port)
9
+ end
10
+
11
+ teardown do
12
+ stop_stub_socket
13
+ end
14
+
15
+ def create_driver(conf = '')
16
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::TCPClientOutput).configure(conf)
17
+ end
18
+
19
+ sub_test_case 'configure' do
20
+ test 'check default' do
21
+ assert_nothing_raised do
22
+ d = create_driver
23
+ assert { d.instance.formatter.is_a? Fluent::Plugin::JSONFormatter }
24
+ end
25
+ end
26
+ end
27
+
28
+ sub_test_case "test output" do
29
+ def output(msgs = [''])
30
+ config = %[
31
+ host localhost
32
+ port #{@port}
33
+ <format>
34
+ @type json
35
+ </format>
36
+ <buffer>
37
+ @type memory
38
+ flush_mode immediate
39
+ </buffer>
40
+ ]
41
+
42
+ d = create_driver(config)
43
+ t = event_time("2011-01-02 13:14:15.123")
44
+
45
+ d.run(default_tag: 'test') do
46
+ msgs.each do |m|
47
+ d.feed(t, m)
48
+ end
49
+ end
50
+
51
+ d.formatted
52
+ end
53
+
54
+ test 'typical usage' do
55
+ msgs = [{'a' => 1},{'a' => 2}]
56
+ output(msgs)
57
+ end
58
+ end
59
+
60
+ def start_stub_socket(port)
61
+ @server = TCPServer.new(port)
62
+ @stub_running = true
63
+
64
+ Thread.start do
65
+ while(@stub_running) do
66
+ Thread.start(server.accept) do |client|
67
+ while (b = client.read)
68
+ puts ">> #{b}"
69
+ end
70
+
71
+ client.close
72
+ end
73
+ end
74
+ end
75
+
76
+ server.close rescue nil
77
+ end
78
+
79
+ def stop_stub_socket
80
+ @stub_running = false
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-tcp-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Richardson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-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.14.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.14.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
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.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Fluentd output plugin for persistent TCP connections
56
+ email:
57
+ - bryan@activeshadow.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - LICENSE
65
+ - Rakefile
66
+ - fluent-plugin-tcp-client.gemspec
67
+ - lib/fluent/plugin/out_tcp_client.rb
68
+ - pkg/fluent-plugin-tcp-client-0.1.0.gem
69
+ - test/helper.rb
70
+ - test/plugin/test_out_tcp_client.rb
71
+ homepage: https://github.com/activeshadow/fluent-plugin-tcp-client
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Fluentd output plugin for persistent TCP connections
95
+ test_files:
96
+ - test/helper.rb
97
+ - test/plugin/test_out_tcp_client.rb