Class: Fluent::Plugin::MssqlLookupFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_mssql_lookup.rb

Instance Method Summary collapse

Constructor Details

#initializeMssqlLookupFilter

Returns a new instance of MssqlLookupFilter.



36
37
38
39
40
# File 'lib/fluent/plugin/filter_mssql_lookup.rb', line 36

def initialize
  super

  @lookup = Hash.new
end

Instance Method Details

#filter(tag, time, record) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/filter_mssql_lookup.rb', line 60

def filter(tag, time, record)
  id = record[@key]

  return record if id.nil?

  upid = id.upcase
  match = @lookup[upid]
  return record if match.nil?

  match.each do |key,val| 
    next if key == @lookup_key
    name = key.downcase
    record[name] = val
  end

  return record
end

#lookup_refreshObject



51
52
53
54
55
56
57
58
# File 'lib/fluent/plugin/filter_mssql_lookup.rb', line 51

def lookup_refresh
  client = TinyTds::Client.new username: @db_user, password: @db_password, host: @db_host, port: @db_port, database: @db_name
  results = client.execute(@lookup_sql)
  results.each do |row|
    id = row[@lookup_key]
    @lookup[id] = row
  end
end

#startObject



42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/filter_mssql_lookup.rb', line 42

def start
  super

  lookup_refresh
  timer_execute(:refresh_timer, @lookup_interval) do
    lookup_refresh
  end
end