Sha256: 87775e9acb5ff781fd4a123a50da01678c975fccc14a1a173b337df04c934e8e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'fluent/plugin/filter'
require 'fluent/plugin/geoip'

module Fluent::Plugin
  class GeoipFilter < Fluent::Plugin::Filter
    Fluent::Plugin.register_filter('geoip', self)

    helpers :compat_parameters, :inject

    config_param :geoip_database, :string, default: File.expand_path('../../../data/GeoLiteCity.dat', __dir__)
    config_param :geoip2_database, :string, default: File.expand_path('../../../data/GeoLite2-City.mmdb', __dir__)
    config_param :geoip_lookup_key, :string, default: 'host'
    config_param :skip_adding_null_record, :bool, default: false

    config_set_default :@log_level, "warn"

    config_param :backend_library, :enum, list: Fluent::GeoIP::BACKEND_LIBRARIES, default: :geoip2_c

    def configure(conf)
      compat_parameters_convert(conf, :inject)
      super
      @geoip = Fluent::GeoIP.new(self, conf)
    end

    def filter(tag, time, record)
      filtered_record = @geoip.add_geoip_field(record)
      if filtered_record
        record = filtered_record
      end
      record = inject_values_to_record(tag, time, record)
      record
    end

    def multi_workers_ready?
      true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-geoip-1.1.0 lib/fluent/plugin/filter_geoip.rb