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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/logstash/filters/ip2location.rb', line 52

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

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

#registerObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/logstash/filters/ip2location.rb', line 37

def register
  if @database.nil?
    @database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"IP2LOCATION-LITE-DB1.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, @hide_unsupported_fields)
end

#tag_iplookup_unsuccessful(event) ⇒ Object



72
73
74
# File 'lib/logstash/filters/ip2location.rb', line 72

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