fluent-plugin-mqtt 0.0.2

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: b384df168f46e48df47f54da9b54c286a4044834
4
+ data.tar.gz: f4b54348b86aec4045955e45f74285cea598fe0b
5
+ SHA512:
6
+ metadata.gz: e1a175591615e3ea8a589609c5c87e26b9dce99a11856493bf7173b9683a4e9a50bd1ea324eeb2d15479b532e5bb12169a7a37b0ab276f49754f042cf6bd26ae
7
+ data.tar.gz: 9e639c9c02de3a748a9baac0479d1519c5c3e88b410e81ed575c799ee98a2c918c9c01ad40ba1b61600fd49b1d700461df70b0e7a9766a04a91f15e34784f3f7
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-mqtt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Yuuna Kurita
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,40 @@
1
+ # Fluent::Plugin::Mqtt
2
+
3
+ Fluent plugin for MQTT protocol
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-mqtt'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-mqtt
18
+
19
+ ## Usage
20
+
21
+ This client works as ONLY MQTT client.
22
+ MQTT topic is set "#".
23
+
24
+ ```
25
+
26
+ <source>
27
+ type mqtt
28
+ bind 127.0.0.1
29
+ port 1883
30
+ </source>
31
+
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( http://github.com/yuuna/fluent-plugin-mqtt/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
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
@@ -0,0 +1,28 @@
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-mqtt"
7
+ spec.version = "0.0.2"
8
+ spec.authors = ["Yuuna Kurita"]
9
+ spec.email = ["yuuna.m@gmail.com"]
10
+ spec.summary = %q{fluentd input plugin for mqtt server}
11
+ spec.description = %q{fluentd input plugin for mqtt server}
12
+ spec.homepage = "http://github.com/yuuna/fluent-plugin-mqtt"
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_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "mqtt"
23
+ spec.add_development_dependency "fluentd"
24
+ spec.add_runtime_dependency "mqtt"
25
+ spec.add_runtime_dependency "fluentd"
26
+ spec.add_runtime_dependency "yajl-ruby"
27
+
28
+ end
@@ -0,0 +1,57 @@
1
+ module Fluent
2
+ class MqttInput < Input
3
+ Plugin.register_input('mqtt', self)
4
+
5
+ include Fluent::SetTagKeyMixin
6
+ config_set_default :include_tag_key, false
7
+
8
+ include Fluent::SetTimeKeyMixin
9
+ config_set_default :include_time_key, true
10
+
11
+ config_param :port, :integer, :default => 1883
12
+ config_param :bind, :string, :default => '127.0.0.1'
13
+ config_param :topic, :string, :default => '#'
14
+
15
+ require 'mqtt'
16
+
17
+ def configure(conf)
18
+ super
19
+ @bind ||= conf['bind']
20
+ @topic ||= conf['topic']
21
+ @port ||= conf['port']
22
+ end
23
+
24
+ def start
25
+ $log.debug "start mqtt"
26
+ @connect = MQTT::Client.connect({remote_host: @bind, remote_port: @port})
27
+ @connect.subscribe(@topic)
28
+
29
+ @thread = Thread.new do
30
+ @connect.get do |topic,message|
31
+ topic.gsub!("/","\.")
32
+ $log.debug "#{topic}: #{message}"
33
+ emit topic, json_parse(message)
34
+ end
35
+ end
36
+ end
37
+
38
+ def emit topic, message , time = Fluent::Engine.now
39
+ Fluent::Engine.emit(topic, time , message )
40
+ end
41
+
42
+ def json_parse message
43
+ begin
44
+ y = Yajl::Parser.new
45
+ y.parse(message)
46
+ rescue
47
+ $log.error "JSON parse error", :error => $!.to_s, :error_class => $!.class.to_s
48
+ $log.warn_backtrace $!.backtrace
49
+ end
50
+ end
51
+ def shutdown
52
+ @thread.kill
53
+ @connect.disconnect
54
+ end
55
+ end
56
+ end
57
+
data/test/helper.rb ADDED
@@ -0,0 +1,28 @@
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
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/in_mqtt'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ class Fluent::MqttInput
4
+ def emit topic, message, time = Fluent::Engine.now
5
+ Fluent::Engine.emit(topic, message["t"], message)
6
+ end
7
+ end
8
+
9
+ class MqttInputTest < Test::Unit::TestCase
10
+ def setup
11
+ Fluent::Test.setup
12
+ end
13
+
14
+
15
+ CONFIG = %[
16
+ ]
17
+
18
+ def create_driver(conf = CONFIG)
19
+ Fluent::Test::InputTestDriver.new(Fluent::MqttInput).configure(conf)
20
+ end
21
+
22
+ def test_configure
23
+ d = create_driver(
24
+ %[ bind 127.0.0.1
25
+ port 1300 ]
26
+ )
27
+ assert_equal '127.0.0.1', d.instance.bind
28
+ assert_equal 1300, d.instance.port
29
+ end
30
+
31
+
32
+ def sub_client
33
+ connect = MQTT::Client.connect
34
+ connect.subscribe('#')
35
+ return connect
36
+ end
37
+
38
+
39
+ def test_client
40
+ d = create_driver
41
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
42
+ d.expect_emit "tag1", time, {"t" => time, "v" => {"a"=>1}}
43
+ d.expect_emit "tag2", time, {"t" => time, "v" => {"a"=>2}}
44
+ d.run do
45
+ d.expected_emits.each {|tag,time,record|
46
+ send_data tag, time, record
47
+ }
48
+ sleep 0.5
49
+ end
50
+ end
51
+
52
+ def send_data tag, time, record
53
+ sub_client.publish(tag, record.to_json)
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mqtt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Yuuna Kurita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: mqtt
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
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
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: mqtt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: fluentd
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
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: yajl-ruby
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: fluentd input plugin for mqtt server
112
+ email:
113
+ - yuuna.m@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - fluent-plugin-mqtt.gemspec
124
+ - lib/fluent/plugin/in_mqtt.rb
125
+ - test/helper.rb
126
+ - test/plugin/test_in_mqtt.rb
127
+ homepage: http://github.com/yuuna/fluent-plugin-mqtt
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.0.6
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: fluentd input plugin for mqtt server
151
+ test_files:
152
+ - test/helper.rb
153
+ - test/plugin/test_in_mqtt.rb