fluent-plugin-mssql 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
+ SHA1:
3
+ metadata.gz: 5bf5aafae778b21d6e48df745f0ab035884e116a
4
+ data.tar.gz: da3f9b20f24751cfe4792c1d4a64778494720491
5
+ SHA512:
6
+ metadata.gz: 83278b3ccecb7d0494d419d8a7478d90089955f80792823f95273189cca5479a78fdf6ddc53f5ece2edf61683d8e6f36d87f0ef68acad1d9252b31ccd108db96
7
+ data.tar.gz: 8949d867938c8c98bc1334d1a3f14056c2754213010b45613fe97237076b7f8b959f83fab4089fd34cbf87f88adc2ae090343539cae4165a19ea8c42bbe48c7c
@@ -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-mssql.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ # Fluent::Plugin::Mssql
2
+
3
+ Fluentd plugin to insert into Microsoft SQL Server.
4
+
5
+ ## Requirement
6
+
7
+ You should install and setup following packages;
8
+
9
+ - unixODBC [http://www.unixodbc.org/]
10
+ - freeTDS [http://www.freetds.org/]
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'fluent-plugin-mssql'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install fluent-plugin-mssql
25
+
26
+ ## Usage
27
+
28
+ ```
29
+ <match insert.into.mssql>
30
+ type mssql
31
+ odbc_label <OdbcLabel>
32
+ username <username>
33
+ password <password>
34
+ key_names status,bytes,vhost,path,rhost,agent,referer
35
+ sql INSERT INTO access_log (status,bytes,vhost,path,rhost,agent,referer) VALUES (?,?,?,?,?,?,?)
36
+ flush_interval 5s
37
+ </match>
38
+ ```
39
+
40
+ ## LISENCE
41
+
42
+ - Apache License, Version 2.0
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( http://github.com/htgc/fluent-plugin-mssql/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
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-mssql"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Hidemasa Togashi"]
9
+ spec.email = ["togachiro@gmail.com"]
10
+ spec.summary = %q{Fluentd plugin to insert into Microsoft SQL Server.}
11
+ spec.description = %q{Fluentd plugin to insert into Microsoft SQL Server.}
12
+ spec.homepage = "http://github.com/htgc/fluent-plugin-mssql/fork"
13
+ spec.license = "Apache Lisence version 2.0"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency "dbi"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,97 @@
1
+ class MssqlOutput < Fluent::BufferedOutput
2
+ Fluent::Plugin.register_output('mssql', self)
3
+
4
+ include Fluent::SetTimeKeyMixin
5
+ include Fluent::SetTagKeyMixin
6
+
7
+ config_param :odbc_label, :string, :default => nil
8
+ config_param :username, :string
9
+ config_param :password, :string
10
+
11
+ config_param :key_names, :string, :default => nil # nil allowed for json format
12
+ config_param :sql, :string, :default => nil
13
+ config_param :table, :string, :default => nil
14
+ config_param :columns, :string, :default => nil
15
+
16
+ config_param :format, :string, :default => 'raw' # raw or json
17
+
18
+ attr_accessor :handler
19
+
20
+ def initialize
21
+ super
22
+ require 'dbi'
23
+ end
24
+
25
+ def configure(conf)
26
+ super
27
+
28
+ if @format == 'json'
29
+ @format_proc = Proc.new{|tag, time, record| record.to_json}
30
+ else
31
+ @key_names = @key_names.split(',')
32
+ @format_proc = Proc.new{|tag, time, record| @key_names.map{|k| record[k]}}
33
+ end
34
+
35
+ if @columns.nil? and @sql.nil?
36
+ raise Fluent::ConfigError, "columns or sql MUST be specified, but missing"
37
+ end
38
+
39
+ if @sql.nil?
40
+ raise Fluent::ConfigError, "table missing" unless @table
41
+
42
+ @columns = @columns.split(',')
43
+ cols = @columns.join(',')
44
+ placeholders = if @format == 'json'
45
+ '?'
46
+ else
47
+ @key_names.map{|k| '?'}.join(',')
48
+ end
49
+ @sql = "INSERT INTO #{@table} (#{cols}) VALUES (#{placeholders})"
50
+ end
51
+ end
52
+
53
+ def start
54
+ super
55
+ end
56
+
57
+ def shutdown
58
+ super
59
+ end
60
+
61
+ def format(tag, time, record)
62
+ tmp = [tag, time, @format_proc.call(tag, time, record)]
63
+ mp = tmp.to_msgpack
64
+ mp
65
+ end
66
+
67
+ def client
68
+ if @odbc_label.nil?
69
+ raise Fluent::ConfigError, "odbc_label MUST be specified, but missing"
70
+ else
71
+ begin
72
+ dbh = DBI.connect("dbi:ODBC:#{@odbc_label}", @username, @password)
73
+ rescue
74
+ raise Fluent::ConfigError, "Cannot open database, check user or password"
75
+ end
76
+ end
77
+ dbh
78
+ end
79
+
80
+ def write(chunk)
81
+ handler = self.client
82
+ chunk.msgpack_each { |tag, time, data|
83
+ begin
84
+ query = handler.prepare(@sql)
85
+ num = 1
86
+ data.each { |d|
87
+ query.bind_param(num, d)
88
+ num += 1
89
+ }
90
+ query.execute
91
+ rescue
92
+ raise Fluent::ConfigError, "SQL Execute Error #{@sql} - #{data}"
93
+ end
94
+ }
95
+ handler.disconnect
96
+ end
97
+ end
File without changes
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mssql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hidemasa Togashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dbi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ description: Fluentd plugin to insert into Microsoft SQL Server.
56
+ email:
57
+ - togachiro@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - fluent-plugin-mssql.gemspec
67
+ - lib/fluent/plugin/out_mssql.rb
68
+ - test/plugin/test_out_mssql.rb
69
+ homepage: http://github.com/htgc/fluent-plugin-mssql/fork
70
+ licenses:
71
+ - Apache Lisence version 2.0
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.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Fluentd plugin to insert into Microsoft SQL Server.
93
+ test_files:
94
+ - test/plugin/test_out_mssql.rb