fluent-plugin-tagged_udp 0.0.4

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: 073d5978d4281e316196c532dfb6056f44f68c98
4
+ data.tar.gz: cf08790dca1ff47e7281b88fd2951c6255f31c14
5
+ SHA512:
6
+ metadata.gz: 226e17c5c0f246cd82ab51b43b86ca1c3e956d27c86f952917056c3e5ab08bf6492c24443aa75791a0568c6b6e43068e5bc2910d63c2a1c2a3d400723e76ac0e
7
+ data.tar.gz: 61a422392814d53970d189b7a9c84c6b83f53c7a05747bc98412078612b3f5f5f4e9a80f34ed43f3370b541fe7ea12c785a2297a3c5309012b31cd7f683b186a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-mqtt-io.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Toyokazu Akiyama
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.
22
+
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Fluent::Plugin::tagged_udp
2
+
3
+ Fluent plugin for tagged UDP Input/Output.
4
+ This plugin is a special plugin to submit a message as a UDP packet. While fluentd's default UDP Input plugin supports to add a tag to the received message, this plugin support to add tag name separated by a special character.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fluent-plugin-tagged_udp'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-tagged_udp
19
+
20
+
21
+ ## Usage
22
+
23
+ fluent-plugin-tagged_udp provides UDP input/output function for fluentd.
24
+
25
+ Input plugin can be used via source directive.
26
+
27
+ ```
28
+ <source **>
29
+ type tagged_udp
30
+ bind 127.0.0.1
31
+ port 20001
32
+ format json # required
33
+ </source>
34
+
35
+ ```
36
+
37
+ Optional parameters are as follows:
38
+
39
+ - tag_sep: separator of tag name. default is "\t"
40
+
41
+ Output Plugin can be used via match directive.
42
+
43
+ ```
44
+
45
+ <match **>
46
+ type tagged_udp
47
+ host 127.0.0.1
48
+ port 20001
49
+ </match>
50
+
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( http://github.com/toyokazu/fluent-plugin-tagged_udp/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,26 @@
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-tagged_udp"
7
+ spec.version = "0.0.4"
8
+ spec.authors = ["Toyokazu Akiyama"]
9
+ spec.email = ["toyokazu@gmail.com"]
10
+
11
+ spec.summary = %q{fluentd input/output plugin for tagged UDP message}
12
+ spec.description = %q{fluentd input/output plugin for tagged UDP message}
13
+ spec.homepage = "https://github.com/toyokazu/fluent-plugin-tagged_udp"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.gsub(/images\/[\w\.]+\n/, "").split($/)
17
+ spec.bindir = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "fluentd", ">= 0.10.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,70 @@
1
+ module Fluent
2
+ class taggedUdpInput < Input
3
+
4
+ # First, register the plugin. NAME is the name of this plugin
5
+ # and identifies the plugin in the configuration file.
6
+ Fluent::Plugin.register_input('tagged_udp', self)
7
+
8
+ config_param :bind, :string, :default => '127.0.0.1'
9
+ config_param :port, :integer, :default => 1883
10
+ config_param :tag_sep, :string, :default => "\t"
11
+ config_param :format, :string, :default => 'json'
12
+
13
+ require 'socket'
14
+
15
+ # Define `router` method of v0.12 to support v0.10 or earlier
16
+ unless method_defined?(:router)
17
+ define_method("router") { Fluent::Engine }
18
+ end
19
+
20
+ # This method is called before starting.
21
+ # 'conf' is a Hash that includes configuration parameters.
22
+ # If the configuration is invalid, raise Fluent::ConfigError.
23
+ def configure(conf)
24
+ super
25
+
26
+ # You can also refer raw parameter via conf[name].
27
+ @bind ||= conf['bind']
28
+ @port ||= conf['port']
29
+ @tag_sep ||= conf['tag_sep']
30
+ configure_parser(conf)
31
+ end
32
+
33
+ def configure_parser(conf)
34
+ @parser = Plugin.new_parser(conf['format'])
35
+ @parser.configure(conf)
36
+ end
37
+
38
+ def parse(message)
39
+ @parser.parse(message) do |time, record|
40
+ if time.nil?
41
+ $log.debug "Since time_key field is nil, Fluent::Engine.now is used."
42
+ time = Fluent::Engine.now
43
+ end
44
+ return [time, record]
45
+ end
46
+ end
47
+
48
+ def start
49
+ $log.debug "start udp server #{@bind}"
50
+
51
+ @thread = Thread.new(Thread.current) do |parent|
52
+ begin
53
+ Socket.udp_server_loop(@bind, @port) do |msg, msg_src|
54
+ $log.debug("Received #{msg}")
55
+ tag, message = msg.split(@tag_sep)
56
+ time, record = parse(message)
57
+ $log.debug "#{tag}, #{time}, #{record}"
58
+ router.emit(tag, time, record)
59
+ end
60
+ rescue StandardError => e
61
+ parent.raise(e)
62
+ end
63
+ end
64
+ end
65
+
66
+ def shutdown
67
+ @thread.kill
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,68 @@
1
+ module Fluent
2
+ class TaggedUdpOutput < Output
3
+
4
+ # First, register the plugin. NAME is the name of this plugin
5
+ # and identifies the plugin in the configuration file.
6
+ Fluent::Plugin.register_output('tagged_udp', self)
7
+
8
+ config_param :host, :string, :default => '127.0.0.1'
9
+ config_param :port, :integer, :default => 1883
10
+ config_param :tag_sep, :string, :default => "\t"
11
+ config_param :time_key, :string, :default => 'time'
12
+ config_param :time_format, :string, :default => nil
13
+
14
+ require 'socket'
15
+
16
+ # This method is called before starting.
17
+ # 'conf' is a Hash that includes configuration parameters.
18
+ # If the configuration is invalid, raise Fluent::ConfigError.
19
+ def configure(conf)
20
+ super
21
+
22
+ # You can also refer raw parameter via conf[name].
23
+ @host ||= conf['host']
24
+ @port ||= conf['port']
25
+ @tag_sep ||= conf['tag_sep']
26
+ @socket = UDPSocket.new
27
+ end
28
+
29
+ def format_time(time)
30
+ case @time_format
31
+ when nil then
32
+ # default format is integer value
33
+ time
34
+ when "iso8601" then
35
+ # iso8601 format
36
+ Time.at(time).iso8601
37
+ else
38
+ # specified strftime format
39
+ Time.at(time).strftime(@time_format)
40
+ end
41
+ end
42
+
43
+ def timestamp_hash(time)
44
+ if @time_key.nil?
45
+ {}
46
+ else
47
+ {@time_key => format_time(time)}
48
+ end
49
+ end
50
+
51
+ def emit(tag, es, chain)
52
+ begin
53
+ es.each {|time,record|
54
+ $log.debug "#{tag}, #{format_time(time)}, #{record}"
55
+ @socket.send(
56
+ # tag is inserted into the head of the message
57
+ "#{tag}#{@tag_sep}#{record.merge(timestamp_hash(time)).to_json}",
58
+ Socket::MSG_EOR, @host, @port
59
+ )
60
+ }
61
+ $log.flush
62
+ chain.next
63
+ rescue StandardError => e
64
+ $log.debug "#{e.class}: #{e.message}"
65
+ end
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-tagged_udp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Toyokazu Akiyama
8
+ autorequire:
9
+ bindir: []
10
+ cert_chain: []
11
+ date: 2016-01-04 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.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.10.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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: fluentd input/output plugin for tagged UDP message
56
+ email:
57
+ - toyokazu@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - fluent-plugin-tagged_udp.gemspec
67
+ - lib/fluent/plugin/in_tagged_udp.rb
68
+ - lib/fluent/plugin/out_tagged_udp.rb
69
+ homepage: https://github.com/toyokazu/fluent-plugin-tagged_udp
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.4.5
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: fluentd input/output plugin for tagged UDP message
93
+ test_files: []
94
+ has_rdoc: