fluent-plugin-nats 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/COPYING ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (C) 2012 Eduardo Aceituno <achied@gmail.com> All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-nats (0.0.1)
5
+ fluentd (>= 0.10.7)
6
+ nats (>= 0.4.22)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ cool.io (1.1.0)
12
+ iobuffer (>= 1.0.0)
13
+ daemons (1.1.9)
14
+ eventmachine (0.12.10)
15
+ fluentd (0.10.25)
16
+ cool.io (~> 1.1.0)
17
+ http_parser.rb (~> 0.5.1)
18
+ json (>= 1.4.3)
19
+ msgpack (~> 0.4.4)
20
+ yajl-ruby (~> 1.0)
21
+ http_parser.rb (0.5.3)
22
+ iobuffer (1.1.2)
23
+ json (1.7.5)
24
+ json_pure (1.7.5)
25
+ msgpack (0.4.7)
26
+ nats (0.4.26)
27
+ daemons (>= 1.1.5)
28
+ eventmachine (>= 0.12.10)
29
+ json_pure (>= 1.7.3)
30
+ thin (>= 1.4.1)
31
+ rack (1.4.1)
32
+ rake (0.9.2.2)
33
+ rr (1.0.4)
34
+ thin (1.4.1)
35
+ daemons (>= 1.0.9)
36
+ eventmachine (>= 0.12.6)
37
+ rack (>= 1.0.0)
38
+ yajl-ruby (1.1.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ fluent-plugin-nats!
45
+ rake (>= 0.9.2)
46
+ rr (>= 1.0.0)
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ fluent-plugin-nats
2
+ ==================
3
+
4
+ NATS plugin for fluent Event Collector
5
+
6
+ # Getting Started
7
+ Setup the NATS input:
8
+
9
+ ~~~~~
10
+ <source>
11
+ type nats
12
+ host localhost
13
+ port 4222
14
+ user nats
15
+ password nats
16
+ queue fluent.>
17
+ </source>
18
+ ~~~~~
data/Rakefile ADDED
@@ -0,0 +1,14 @@
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.test_files = Dir['test/plugin/*.rb']
9
+ test.ruby_opts = ['-rubygems'] if defined? Gem
10
+ test.ruby_opts << '-I.'
11
+ test.verbose = true
12
+ end
13
+
14
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-nats"
6
+ gem.version = File.read("VERSION").strip
7
+ gem.authors = ["Eduardo Aceituno"]
8
+ gem.email = ["achied@gmail.com"]
9
+ gem.homepage = "https://github.com/achied/fluent-plugin-nats"
10
+ gem.summary = %q{nats plugin for fluent, an event collector}
11
+ gem.description = %q{nats plugin for fluent, an event collector}
12
+
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ["lib"]
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.7"
19
+ gem.add_dependency "nats", ">= 0.4.22"
20
+
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ gem.add_development_dependency "rr", ">= 1.0.0"
23
+ end
@@ -0,0 +1,47 @@
1
+ module Fluent
2
+ class NATSInput < Input
3
+ Fluent::Plugin.register_input("nats", self)
4
+
5
+ config_param :host, :string, :default => "localhost"
6
+ config_param :user, :string, :default => "nats"
7
+ config_param :password, :string, :default => "nats"
8
+ config_param :port, :integer, :default => 4222
9
+ config_param :queue, :string, :default => "fluent.>"
10
+
11
+ def initialize
12
+ require "nats/client"
13
+
14
+ #["TERM", "INT"].each { |sig| trap(sig) { NATS.stop } }
15
+ NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
16
+ super
17
+ end
18
+
19
+ def configure(conf)
20
+ super
21
+ @conf = conf
22
+ unless @host && @queue
23
+ raise ConfigError, "'host' and 'queue' must be all specified."
24
+ end
25
+ end
26
+
27
+ def start
28
+ super
29
+ $log.info "listening nats on nats://#{host}:#{port}/#{queue}"
30
+ @thread = Thread.new(&method(:run))
31
+ end
32
+
33
+ def shutdown
34
+ super
35
+ NATS.stop
36
+ @thread.join
37
+ end
38
+
39
+ def run
40
+ NATS.start {
41
+ NATS.subscribe(@queue) do |msg, reply, sub|
42
+ Engine.emit(sub, 0, msg)
43
+ end
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,57 @@
1
+ require 'test/unit'
2
+ require 'fluent/test'
3
+ require 'lib/fluent/plugin/in_nats'
4
+ require 'nats/client'
5
+
6
+ class NATSInputTest < Test::Unit::TestCase
7
+
8
+ CONFIG = %[
9
+ port 4222
10
+ host localhost
11
+ user nats
12
+ password nats
13
+ queue fluent.>
14
+ ]
15
+
16
+ def create_driver(conf=CONFIG)
17
+ Fluent::Test::InputTestDriver.new(Fluent::NATSInput).configure(conf)
18
+ end
19
+
20
+ def test_configure
21
+ d = create_driver
22
+ assert_equal 4222, d.instance.port
23
+ assert_equal 'localhost', d.instance.host
24
+ assert_equal 'nats', d.instance.user
25
+ assert_equal 'nats', d.instance.password
26
+ assert_equal 'fluent.>', d.instance.queue
27
+ end
28
+
29
+ def test_emit
30
+ d = create_driver
31
+
32
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
33
+ Fluent::Engine.now = time
34
+
35
+ d.expect_emit "fluent.test1", 0, {"message"=>'nats'}.to_json
36
+ d.expect_emit "fluent.test2", 0, {"message"=>'nats'}.to_json
37
+
38
+ d.run do
39
+ d.expected_emits.each { |tag, time, record|
40
+ send(tag, record)
41
+ sleep 0.5
42
+ }
43
+ end
44
+ end
45
+
46
+ def setup
47
+ Fluent::Test.setup
48
+ end
49
+
50
+ def send(tag, msg)
51
+ EM.run {
52
+ n = NATS.connect
53
+ n.publish(tag,msg)
54
+ n.close
55
+ }
56
+ end
57
+ end
@@ -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_nats'
26
+
27
+ class Test::Unit::TestCase
28
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-nats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eduardo Aceituno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: nats
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.22
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.22
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ description: nats plugin for fluent, an event collector
79
+ email:
80
+ - achied@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - COPYING
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - README.md
90
+ - Rakefile
91
+ - VERSION
92
+ - fluent-plugin-nats.gemspec
93
+ - lib/fluent/plugin/in_nats.rb
94
+ - test/plugin/in_nats.rb
95
+ - test/test_helper.rb
96
+ homepage: https://github.com/achied/fluent-plugin-nats
97
+ licenses: []
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.24
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: nats plugin for fluent, an event collector
120
+ test_files: []