Class: Fluent::Plugin::GeoipFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::GeoipFilter
- Defined in:
- lib/fluent/plugin/filter_geoip.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter(_tag, _time, record) ⇒ Object
-
#initialize ⇒ GeoipFilter
constructor
A new instance of GeoipFilter.
Constructor Details
#initialize ⇒ GeoipFilter
Returns a new instance of GeoipFilter.
12 13 14 15 |
# File 'lib/fluent/plugin/filter_geoip.rb', line 12 def initialize @geoip_cache = LruRedux::Cache.new(8192) super end |
Instance Method Details
#configure(conf) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/fluent/plugin/filter_geoip.rb', line 22 def configure(conf) super begin @geoip = MaxMindDB.new(@database_path) rescue StandardError => e log.warn 'Failed to configure parser. Use default pattern.', error_class: e.class, error: e. log.warn_backtrace end end |
#filter(_tag, _time, record) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fluent/plugin/filter_geoip.rb', line 32 def filter(_tag, _time, record) ip_addr = record[@key_name] return record if ip_addr.nil? || ip_addr == '-' 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 record end |