class Mssql22Output
Public Instance Methods
client()
click to toggle source
# File lib/fluent/plugin/out_mssql22.rb, line 37 def client begin pool = ConnectionPool.new(size: @poolsize) { client = TinyTds::Client.new( username: @username, password: @password, host: @host, port: @port, database: @database, appname: 'fluentd-tinytds', timeout: @timeout, login_timeout: @login_timeout ) unless @session_sets.nil? @session_sets.each do |set| client.execute(set).do end end client } rescue Exception => e raise Fluent::ConfigError, e.message end pool end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mssql22.rb, line 22 def configure(conf) super @keys = @query.scan(/\?\{(.*?)\}/).flatten @format_proc = Proc.new{|tag, time, record| @keys.map{|k| [k,record[k]]}.to_h} unless @session_options.nil? @session_sets = @session_options.split(';') end end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_mssql22.rb, line 33 def format(tag, time, record) [tag, time, @format_proc.call(tag, time, record)].to_msgpack end
query_bind(data)
click to toggle source
# File lib/fluent/plugin/out_mssql22.rb, line 76 def query_bind(data) query = @query data.map do |k,v| query = query.gsub("?{#{k}}",v.to_s.gsub(/'/,"''")) end query end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mssql22.rb, line 67 def start super @cp = client end
stop()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mssql22.rb, line 72 def stop super end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_mssql22.rb, line 85 def write(chunk) begin @cp.with { |c| c.execute('select 1;').do } rescue @cp = client end chunk.msgpack_each do |tag, time, data| @cp.with {|c| c.execute( query_bind(data) ).do} end end