fluent-plugin-out_rawtcp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjhmYWYzYTY1NzlmMTVhM2UwYmFjMzExMmZhOTgyZGQ4YThjN2M5Zg==
5
+ data.tar.gz: !binary |-
6
+ NjU5YmFlMGU4MDZhZjNlYTAwNmUzY2MwMDhmN2M5ZDgwOTk0ZDRjNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTE3MDI4ZWE2NTQzZjI4NTgxNDE3MjBkMjgyMmIxODM1MGEwMGJjZjRiMmU2
10
+ MzM0MDkwNmQ3ZjcyZjgzZGRlZTExNWVlNjMwYTdlYjEyYjk0ODY3NDIyZjg2
11
+ NjE2YTJlZmI4YTIxMjg1MTUyZTU3NjdjOGJmNTU1Zjc2ZTAxNTQ=
12
+ data.tar.gz: !binary |-
13
+ MDE4YjM3NjU2ZDFhMjVkZGZmZjFkNjVhZjRlOWVmMzk3NzJlYzQ5NzYwYjA2
14
+ NTU5YmZhNTY0OGFmOWRiMjI5ZWM2YTgzYTFlMzYwODEwZWQ2ZDgyYjU4OTBj
15
+ YjhkMDNiMDNlMTc3YzYzMDc5YmJjNmUxZjViMDg2OTY0NzgwODE=
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ /Gemfile.lock
3
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "fluent-plugin-out_rawtcp"
5
+ s.version = `cat VERSION`
6
+ s.authors = ["lxfontes"]
7
+ s.email = ["lxfontes+rawtcp@gmail.com"]
8
+ s.description = %q{Raw tcp output plugin for Fluentd}
9
+ s.summary = %q{output plugin for fluentd}
10
+ s.homepage = "https://github.com/lxfontes/fluent-plugin-out_rawtcp"
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files`.split($/)
14
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_runtime_dependency "fluentd"
19
+
20
+ s.add_development_dependency "rake"
21
+ s.add_development_dependency "webmock"
22
+ end
@@ -0,0 +1,125 @@
1
+ # coding: utf-8
2
+ module Fluent
3
+ class RawTcpOutput < BufferedOutput
4
+ Plugin.register_output('rawtcp', self)
5
+
6
+ def initialize
7
+ super
8
+ require 'socket'
9
+ require 'timeout'
10
+ require 'fileutils'
11
+ @nodes = [] #=> [Node]
12
+ end
13
+
14
+ config_param :send_timeout, :time, :default => 60
15
+ config_param :connect_timeout, :time, :default => 5
16
+ attr_reader :nodes
17
+
18
+ def configure(conf)
19
+ super
20
+
21
+ conf.elements.each do |e|
22
+ next if e.name != "server"
23
+
24
+ host = e['host']
25
+ port = e['port']
26
+ port = port ? port.to_i : DEFAULT_LISTEN_PORT
27
+
28
+ name = e['name']
29
+ unless name
30
+ name = "#{host}:#{port}"
31
+ end
32
+
33
+ node_conf = RawNodeConfig.new(name, host, port)
34
+ @nodes << Node.new(log, node_conf)
35
+ log.info "adding forwarding server '#{name}'", :host=>host, :port=>port
36
+ end
37
+ end
38
+
39
+ def start
40
+ super
41
+ end
42
+
43
+ def shutdown
44
+ super
45
+ end
46
+
47
+ def format(tag, time, record)
48
+ [tag, time, record].to_msgpack
49
+ end
50
+
51
+ def write(chunk)
52
+ return if chunk.empty?
53
+
54
+ error = nil
55
+
56
+ @nodes.each do |node|
57
+ begin
58
+ send_data(node, chunk)
59
+ return
60
+ rescue
61
+ error = $!
62
+ end
63
+ end
64
+
65
+ raise error if error
66
+ raise "No nodes available"
67
+ end
68
+
69
+ private
70
+ def send_data(node, chunk)
71
+ sock = connect(node)
72
+ begin
73
+ opt = [1, @send_timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; }
74
+ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
75
+
76
+ opt = [@send_timeout.to_i, 0].pack('L!L!') # struct timeval
77
+ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, opt)
78
+
79
+ chunk.msgpack_each do |tag, time, record|
80
+ next unless record.is_a? Hash
81
+ sock.write([tag, time, record].to_msgpack)
82
+ end
83
+ ensure
84
+ sock.close
85
+ end
86
+ end
87
+
88
+ def connect(node)
89
+ Timeout.timeout(@connect_timeout) do
90
+ return TCPSocket.new(node.resolved_host, node.port)
91
+ end
92
+ end
93
+
94
+ RawNodeConfig = Struct.new("RawNodeConfig", :name, :host, :port)
95
+
96
+ class Node
97
+ def initialize(log, conf)
98
+ @log = log
99
+ @conf = conf
100
+ @name = @conf.name
101
+ @host = @conf.host
102
+ @port = @conf.port
103
+ resolved_host # check dns
104
+ end
105
+
106
+ attr_reader :conf
107
+ attr_reader :name, :host, :port
108
+ attr_accessor :failure, :available
109
+
110
+ def available?
111
+ @available
112
+ end
113
+
114
+ def standby?
115
+ @conf.standby
116
+ end
117
+
118
+ def resolved_host
119
+ @sockaddr = Socket.pack_sockaddr_in(@port, @host)
120
+ port, rhost = Socket.unpack_sockaddr_in(@sockaddr)
121
+ return rhost
122
+ end
123
+ end
124
+ end
125
+ end
data/test/helper.rb ADDED
@@ -0,0 +1 @@
1
+ require 'minitest/pride'
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+
3
+ require 'fluent/test'
4
+ require 'fluent/plugin/out_rawtcp'
5
+
6
+ require 'webmock/test_unit'
7
+ require 'date'
8
+
9
+ require 'helper'
10
+
11
+ $:.push File.expand_path("../lib", __FILE__)
12
+ $:.push File.dirname(__FILE__)
13
+
14
+ WebMock.disable_net_connect!
15
+
16
+ class TestRawTcpOutput < Test::Unit::TestCase
17
+ attr_accessor :index_cmds, :index_command_counts
18
+
19
+ def setup
20
+ Fluent::Test.setup
21
+ @driver = driver('test', "<server>
22
+ host 127.0.0.1
23
+ port 24225
24
+ </server>")
25
+ end
26
+
27
+ def driver(tag='test', conf='')
28
+ @driver ||= Fluent::Test::BufferedOutputTestDriver.new(Fluent::RawTcpOutput, tag).configure(conf)
29
+ end
30
+
31
+ def sample_record
32
+ {'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'sub' => {'field'=>{'pos'=>15}}}
33
+ end
34
+
35
+ def test_writes_to_default_index
36
+ 100.times.each do |t|
37
+ @driver.emit(sample_record)
38
+ end
39
+ @driver.run
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-out_rawtcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - lxfontes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-28 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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: webmock
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
+ description: Raw tcp output plugin for Fluentd
56
+ email:
57
+ - lxfontes+rawtcp@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - VERSION
67
+ - fluent-plugin-out_rawtcp.gemspec
68
+ - lib/fluent/plugin/out_rawtcp.rb
69
+ - test/helper.rb
70
+ - test/plugin/test_out_rawtcp.rb
71
+ homepage: https://github.com/lxfontes/fluent-plugin-out_rawtcp
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.3.0
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: output plugin for fluentd
95
+ test_files:
96
+ - test/helper.rb
97
+ - test/plugin/test_out_rawtcp.rb