Class: LogStash::Filters::IP2Location

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/filters/ip2location.rb

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/logstash/filters/ip2location.rb', line 46

def filter(event)
  ip = event.get(@source)

  return unless filter?(event)
  if value = Cache.find(event, ip, @ip2locationfilter, @cache_size).get('ip2location')
    event.set('ip2location', value)
    filter_matched(event)
  else
    tag_iplookup_unsuccessful(event)
  end
end

#registerObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/logstash/filters/ip2location.rb', line 31

def register
  if @database.nil?
    @database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"IP2LOCATION-LITE-DB3.IPV6.BIN")).first

    if @database.nil? || !File.exists?(@database)
      raise "You must specify 'database => ...' in your ip2location filter (I looked for '#{@database}')"
    end
  end

  @logger.info("Using ip2location database", :path => @database)

  @ip2locationfilter = org.logstash.filters.IP2LocationFilter.new(@source, @target, @database, @use_memory_mapped)
end

#tag_iplookup_unsuccessful(event) ⇒ Object



58
59
60
# File 'lib/logstash/filters/ip2location.rb', line 58

def tag_iplookup_unsuccessful(event)
  @logger.debug? && @logger.debug("IP #{event.get(@source)} was not found in the database", :event => event)
end