fluent-plugin-tcp_socket_client 0.0.1

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
+ SHA256:
3
+ metadata.gz: a800af4ca816a495d0322f44602e27ea7e56e2bc3f7bc09b9671f66d2b42e8bb
4
+ data.tar.gz: 4ffcb6082136afe3157893e057dbc30a63eaa88d9c65f2a53441f7c9e4d2952c
5
+ SHA512:
6
+ metadata.gz: 3e4a99141d9e1ed82a75286db6274b759a5cda4db8b17bd90f2b7f6cf68ecbc8ac989d5496c4b65a6b77b44adb2b521157bc2a7e1cae6dc9ac2d786769e606d6
7
+ data.tar.gz: b9d2bdaae368631b80d7427d5f8657febca69fac3c122abfc2d133cfb01d54ff532e550592f896a517d1e80351bd5a828e8df103d308e6c8bc7a0946729e708c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 superguillen
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,96 @@
1
+ # fluent-plugin-tcp_socket_client , a plugin for [Fluentd](http://fluentd.org)
2
+ [![Build Status](https://api.travis-ci.org/superguillen/fluent-plugin-tcp_socket_client.svg?branch=master)](https://api.travis-ci.org/superguillen/fluent-plugin-tcp_socket_client)
3
+
4
+ A fluentd input plugin for read TCP socket.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fluent-plugin-tcp_socket_client'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-tcp_socket_client --no-document
19
+
20
+ ## Requirements
21
+
22
+ - Ruby 2.1 or later
23
+ - fluentd v0.12 or later
24
+
25
+ ## Usage
26
+ ### Input plugin (@type 'tcp_socket_client')
27
+
28
+ Read events from TCP sockets.
29
+
30
+ ```
31
+ <source>
32
+ @type tcp_socket_client
33
+ @log_level debug
34
+ server localhost
35
+ port 3000
36
+ tag prueba
37
+ interval 1s
38
+ format text
39
+ </source>
40
+ ```
41
+ ### Common parameters
42
+ ### interval
43
+ Interval for retry connect to socket.
44
+ ```
45
+ interval 5s
46
+ ```
47
+ ### server
48
+ Socket server name or IP address.
49
+ ```
50
+ server localhost
51
+ ```
52
+ ### port
53
+ Socket port.
54
+ ```
55
+ port 3000
56
+ ```
57
+ ### format
58
+ #### Default: json
59
+ Format of the message (json|text|ltsv)
60
+ ```
61
+ format json
62
+ ```
63
+ ### emit_messages
64
+ #### Default: 10
65
+ Batch size for emit messages.
66
+ ```
67
+ emit_messages 10
68
+ ```
69
+ ### Example
70
+ ```
71
+ <system>
72
+ workers 1
73
+ </system>
74
+ <source>
75
+ @type tcp_socket_client
76
+ server localhost
77
+ port 3000
78
+ tag prueba
79
+ interval 1s
80
+ format json
81
+ </source>
82
+ <match prueba>
83
+ @type stdout
84
+ </match>
85
+ ```
86
+ In another terminal run:
87
+ ```
88
+ require 'socket'
89
+ puts "Starting the Server..................."
90
+ server = TCPServer.open(3000) # Server would listen on port 3000
91
+ loop{ # Servers run forever
92
+ client_connection = server.accept # Establish client connect connection
93
+ client_connection.puts('{"key":"val"}')
94
+ client_connection.close # Disconnect from the client
95
+ }
96
+ ```
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
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
@@ -0,0 +1,87 @@
1
+ require 'fluent/input'
2
+ module Fluent
3
+ class TCPSocketClientInput < Input
4
+ Plugin.register_input('tcp_socket_client', self)
5
+
6
+ config_param :format, :string, :default => 'json' # (json|text|ltsv)
7
+ config_param :server, :string, :default => 'localhost'
8
+ config_param :port, :integer, :default => 3000
9
+ config_param :tag, :string, :default => 'tcp_socket'
10
+ config_param :emit_messages, :integer, :default => 10
11
+ config_param :interval, :time, :default => 60
12
+ config_param :add_prefix, :string, :default => nil
13
+ config_param :add_suffix, :string, :default => nil
14
+ config_param :delimiter, :string, :default => "\n"
15
+
16
+ helpers :timer
17
+
18
+ def initialize
19
+ super
20
+ require 'socket'
21
+ end
22
+
23
+ def configure(conf)
24
+ super
25
+
26
+ log.info "server has been set : #{@server}:#{@port}"
27
+
28
+ case @format
29
+ when 'json'
30
+ require 'oj'
31
+ when 'ltsv'
32
+ require 'ltsv'
33
+ when 'msgpack'
34
+ require 'msgpack'
35
+ end
36
+ end
37
+
38
+ def multi_workers_ready?
39
+ true
40
+ end
41
+
42
+ def start
43
+ super
44
+ timer_execute(:read_socket_run, @interval, repeat: true, &method(:read_socket_messages))
45
+ end
46
+
47
+ def read_socket_messages
48
+ es = MultiEventStream.new
49
+ log.trace "Creating socket to #{@server}:#{@port}"
50
+ begin
51
+ socket = TCPSocket.open(@server, @port)
52
+ count=0
53
+ while message = socket.gets(@delimiter)
54
+ es.add(Time.now.to_i, parse_msg(message.chomp(@delimiter)))
55
+ count+=1
56
+ if (count % @emit_messages) == 0
57
+ unless es.empty?
58
+ router.emit_stream(tag, es)
59
+ end
60
+ es = MultiEventStream.new
61
+ end
62
+ end
63
+ rescue Exception => e
64
+ $log.error e
65
+ end
66
+
67
+ unless es.empty?
68
+ router.emit_stream(tag, es)
69
+ end
70
+ end
71
+
72
+ def parse_msg(record)
73
+ parsed_record = {}
74
+ case @format
75
+ when 'json'
76
+ parsed_record = Oj.load(record)
77
+ when 'ltsv'
78
+ parsed_record = LTSV.parse(record)
79
+ when 'msgpack'
80
+ parsed_record = MessagePack.unpack(record)
81
+ when 'text'
82
+ parsed_record["message"] = record
83
+ end
84
+ parsed_record
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-tcp_socket_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - superguillen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-12 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.10.58
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.58
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.2
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: test-unit
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.8
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.8
61
+ description: Input plugin for Fluent, reads from TCP socket
62
+ email: superguillen.public@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - lib/fluent/plugin/in_tcp_socket_client.rb
71
+ homepage: https://github.com/superguillen/fluent-plugin-tcp_socket_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
+ rubygems_version: 3.0.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Input plugin for Fluent, reads from TCP socket
94
+ test_files: []