fluent-plugin-mssql22 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db112bed0df522b3fa7c7e7d04f8582ed49f0c22
4
+ data.tar.gz: 23f07c8c468f352fcdcd0f716d27b649b263f9b7
5
+ SHA512:
6
+ metadata.gz: e5fa1e58c446d0f89df2cedb7d86c1c58f03fc470a03f315a85535918decb54f63c94a39431b0d33f92649c82fa9768869c36079c6e6e99b314184c7fffd1867
7
+ data.tar.gz: 1fe898f3ba4f9a8eba8159d7394fec02a88d8120eeeb6b6b7827a2922287c359343ddfc0fe84910adbb866e43fd3bdab7093e58df9ee227af4166e9c5f0e30a5
@@ -0,0 +1,91 @@
1
+ require 'fluent/plugin/output'
2
+ require 'tiny_tds'
3
+ require 'connection_pool'
4
+
5
+ class Mssql22Output < Fluent::BufferedOutput
6
+ Fluent::Plugin.register_output('mssql22', self)
7
+
8
+ include Fluent::SetTimeKeyMixin
9
+ include Fluent::SetTagKeyMixin
10
+
11
+ config_param :username, :string
12
+ config_param :password, :string
13
+ config_param :host, :string
14
+ config_param :port, :string
15
+ config_param :database, :string
16
+ config_param :sql, :string
17
+
18
+ def configure(conf)
19
+ super
20
+ @keys = @sql.scan(/\?\{(.*?)\}/).flatten
21
+ @format_proc = Proc.new{|tag, time, record| @keys.map{|k| [k,record[k]]}.to_h}
22
+ end
23
+
24
+ def format(tag, time, record)
25
+ [tag, time, @format_proc.call(tag, time, record)].to_msgpack
26
+ end
27
+
28
+ def client
29
+ begin
30
+ pool = ConnectionPool.new(size: 100) {
31
+ TinyTds::Client.new(
32
+ username: @username,
33
+ password: @password,
34
+ host: @host,
35
+ port: @port,
36
+ database: @database,
37
+ appname: 'fluentd - tinytds',
38
+ timeout: 60
39
+ )
40
+ }
41
+
42
+ rescue
43
+ raise Fluent::ConfigError, "Cannot open database, check user or password"
44
+ end
45
+
46
+ pool
47
+ end
48
+
49
+ def start
50
+ super
51
+ @cp = client
52
+ end
53
+
54
+ def stop
55
+ super
56
+ end
57
+
58
+ def sql_bind(data)
59
+ sql = @sql
60
+ data.map do |k,v|
61
+ sql = sql.gsub("?{#{k}}",v.to_s.gsub(/'/,"''"))
62
+
63
+ end
64
+ sql
65
+ end
66
+
67
+ def write(chunk)
68
+ begin
69
+ @cp.with { |c| c.execute('SELECT 1;').do }
70
+ rescue
71
+ @cp = client
72
+ ensure
73
+ @cp.with do |c|
74
+ c.execute('SET ANSI_NULLS ON;').do
75
+ c.execute('SET ANSI_PADDING ON;').do
76
+ c.execute('SET ANSI_WARNINGS ON;').do
77
+ c.execute('SET ARITHABORT ON;').do
78
+ c.execute('SET CONCAT_NULL_YIELDS_NULL ON;').do
79
+ c.execute('SET NUMERIC_ROUNDABORT ON;').do
80
+ c.execute('SET QUOTED_IDENTIFIER ON;').do
81
+ c.execute('SET NUMERIC_ROUNDABORT OFF;').do
82
+ end
83
+ end
84
+
85
+ chunk.msgpack_each do |tag, time, data|
86
+ #p sql_bind(data)
87
+ @cp.with {|c| c.execute( sql_bind(data) ).do}
88
+ end
89
+ end
90
+
91
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mssql22
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - zle0
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-24 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.14.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.14.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: connection_pool
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tiny_tds
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ description: fluent plugin to write to Microsoft SQL Server
56
+ email:
57
+ - zle0572
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/fluent/plugin/out_mssql22.rb
63
+ homepage: http://github.com/zle0/fluent-plugin-mssql22
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: fluent plugin to write to Microsoft SQL Server
87
+ test_files: []