class Mssql2Output

require ‘pp’ require ‘logger’

Public Instance Methods

client() click to toggle source
# File lib/fluent/plugin/out_mssql2.rb, line 27
def client
  begin
    db = Sequel.tinytds(username: @username, password: @password, host: @host, database: @database)
    # db.loggers << Logger.new($stdout)
  rescue
    raise Fluent::ConfigError, "Cannot open database, check user or password"
  end  
  db
end
configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mssql2.rb, line 18
def configure(conf)
  super
  @format_proc = Proc.new{|tag, time, record| record.to_json}
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_mssql2.rb, line 23
def format(tag, time, record)
  [tag, time, @format_proc.call(tag, time, record)].to_msgpack
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_mssql2.rb, line 37
def write(chunk)    
  a = []
  c = client

  chunk.msgpack_each{|tag, time, data|
    a << JSON.parse(data)
  }

  # pp a
  begin
    c[@table.gsub('.', '__').to_sym].multi_insert(a)    
  ensure
    c.disconnect
  end
end