fluent-plugin-dbi 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,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-dbi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TERAOKA Yoshinori
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,39 @@
1
+ # Fluent::Plugin::Dbi
2
+
3
+ Fluentd Output plugin using DBI
4
+
5
+ DBI を使って PostgreSQL や MySQL へ INSERT とかを行う Fluentd の Output Plugin
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fluent-plugin-dbi'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-dbi
20
+
21
+ ## Usage
22
+
23
+ <match dbi.*>
24
+ type dbi
25
+ #dsn DBI:Pg:dbname:dbhost
26
+ dsn DBI:Mysql:dbname:dbhost
27
+ db_user username
28
+ db_pass password
29
+ keys host,time_m,method,uri,protocol,status
30
+ query insert into access_log (host, time, method, uri, protocol, status) values (?, ?, ?, ?, ?, ?)
31
+ </match>
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
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,26 @@
1
+ # -*- encoding: 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 |gem|
6
+ gem.name = "fluent-plugin-dbi"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["TERAOKA Yoshinori"]
9
+ gem.email = ["yteraoka@me.com"]
10
+ gem.description = %q{fluentd output plugin using dbi. PostgreSQL and MySQL are tested}
11
+ gem.summary = %q{fluentd output plugin using dbi}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.rubyforge_project = "fluent-plugin-dbi"
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "fluentd"
23
+ gem.add_development_dependency "dbi"
24
+ gem.add_runtime_dependency "fluentd"
25
+ gem.add_runtime_dependency "dbi"
26
+ end
@@ -0,0 +1,53 @@
1
+ module Fluent
2
+
3
+ class DbiOutput < BufferedOutput
4
+ Plugin.register_output('dbi', self)
5
+
6
+ config_param :dsn, :string
7
+ config_param :keys, :string
8
+ config_param :db_user, :string
9
+ config_param :db_pass, :string
10
+ config_param :query, :string
11
+
12
+ def initialize
13
+ super
14
+
15
+ require 'dbi'
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+
21
+ @keys = @keys.split(",")
22
+ end
23
+
24
+ def format(tag, time, record)
25
+ [tag, time, record].to_msgpack
26
+ end
27
+
28
+ def write(chunk)
29
+ begin
30
+ dbh = DBI.connect(@dsn, @db_user, @db_pass)
31
+ sth = dbh.prepare(@query)
32
+ chunk.msgpack_each { |tag, time, record|
33
+ record.key?('time') || record['time'] = time
34
+ record.key('tag') || record['tag'] = tag
35
+ values = []
36
+ @keys.each { |key|
37
+ values.push(record[key])
38
+ }
39
+ rows = sth.execute(*values)
40
+ }
41
+ rescue
42
+ dbh.rollback if dbh
43
+ raise
44
+ else
45
+ sth.finish
46
+ dbh.commit
47
+ ensure
48
+ dbh.disconnect if dbh
49
+ end
50
+ end
51
+ end
52
+
53
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,29 @@
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 'dbi'
26
+ require 'fluent/plugin/out_dbi'
27
+
28
+ class Test::Unit::TestCase
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ class DbiOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ dsn = DBI:drv:dbname:hostname
10
+ db_user username
11
+ db_pass password
12
+ keys aaa,bbb,ccc
13
+ query insert into logs (aaa, bbb, ccc) values (?, ?, ?)
14
+ ]
15
+
16
+ def create_driver(conf=CONFIG)
17
+ Fluent::Test::OutputTestDriver.new(Fluent::DbiOutput) do
18
+ end.configure(conf)
19
+ end
20
+
21
+ def test_configure
22
+ d = create_driver
23
+ keys = ["aaa", "bbb", "ccc"]
24
+ assert_equal "username", d.instance.db_user
25
+ assert_equal "password", d.instance.db_pass
26
+ assert_equal "insert into logs (aaa, bbb, ccc) values (?, ?, ?)", d.instance.query
27
+ assert_equal keys, d.instance.keys
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-dbi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TERAOKA Yoshinori
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: dbi
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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'
62
+ - !ruby/object:Gem::Dependency
63
+ name: fluentd
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: dbi
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: fluentd output plugin using dbi. PostgreSQL and MySQL are tested
95
+ email:
96
+ - yteraoka@me.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - fluent-plugin-dbi.gemspec
107
+ - lib/fluent/plugin/out_dbi.rb
108
+ - test/helper.rb
109
+ - test/plugin/test_out_dbi.rb
110
+ homepage: ''
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: 3465291673268292960
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
132
+ - 0
133
+ hash: 3465291673268292960
134
+ requirements: []
135
+ rubyforge_project: fluent-plugin-dbi
136
+ rubygems_version: 1.8.25
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: fluentd output plugin using dbi
140
+ test_files:
141
+ - test/helper.rb
142
+ - test/plugin/test_out_dbi.rb