Class: LogStash::Filters::IP2Proxy

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

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/logstash/filters/ip2proxy.rb', line 49

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

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

#registerObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/logstash/filters/ip2proxy.rb', line 34

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

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

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

  @ip2proxyfilter = org.logstash.filters.IP2ProxyFilter.new(@source, @target, @database, @use_memory_mapped, @hide_unsupported_fields)
end

#tag_iplookup_unsuccessful(event) ⇒ Object



69
70
71
# File 'lib/logstash/filters/ip2proxy.rb', line 69

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