Class: LogStash::Filters::Tld

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

Overview

This example filter will replace the contents of the default message field with whatever you specify in the configuration.

It is only intended to be used as an example.

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/logstash/filters/tld.rb', line 37

def filter(event)

  if @source and PublicSuffix.valid?(event.get(@source), default_rule: nil)
    domain = PublicSuffix.parse(event.get(@source))
    # Replace the event message with our message as configured in the
    # config file.
    h = Hash.new
    h['tld'] = domain.tld
    h['sld'] = domain.sld
    h['trd'] = domain.trd
    h['domain'] = domain.domain
    h['subdomain'] = domain.subdomain
    h['top_level_domain'] = domain.tld
    event.set(@target, h)

    # filter_matched should go in the last line of our successful code
    filter_matched(event)

  end
end

#registerObject



29
30
31
32
33
34
# File 'lib/logstash/filters/tld.rb', line 29

def register
  # Add instance variables 
  require 'public_suffix'
  # force the list to be initialised.
  PublicSuffix::List.default
end