Class: Fluent::Plugin::GeoipFilter

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

Instance Method Summary collapse

Constructor Details

#initializeGeoipFilter

Returns a new instance of GeoipFilter.



9
10
11
12
# File 'lib/fluent/plugin/filter_geoip.rb', line 9

def initialize
  @geoip_cache = LruRedux::Cache.new(8192)
  super
end

Instance Method Details

#configure(conf) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/fluent/plugin/filter_geoip.rb', line 19

def configure(conf)
  super
  begin
    @geoip = GeoIP.new(@database_path)
  rescue => e
    @geoip = GeoIP.new
    log.warn "Failed to configure parser. Use default pattern.", :error_class => e.class, :error => e.message
    log.warn_backtrace
  end
end

#filter(tag, time, record) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fluent/plugin/filter_geoip.rb', line 30

def filter(tag, time, record)
  ip_addr = record[@key_name]
  unless ip_addr.nil?
    geo_ip = @geoip_cache.getset(ip_addr) { get_geoip(ip_addr) }
    if flatten
      record.merge! hash_flatten(geo_ip, [@out_key])
    else
      record[@out_key] = geo_ip
    end
  end
  record
end