Class: LogStash::Filters::Ipinfo

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

Overview

This 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 .

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



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

def filter(event)

  # check if api token exists and has len of 10 or more to prevent forbidden response
  if @token.length >= 10
    url = "https://ipinfo.io/" + event.sprintf(ip) + "/json?token=" + event.sprintf(token)
    uri = URI.parse(URI.encode(url.strip))
    response = Faraday.get(uri, nil, 'User-Agent' => 'logstash-filter-ipinfo')
  # if no token then use free api
  else
    url = "https://ipinfo.io/" + event.sprintf(ip) + "/json"
    uri = URI.parse(URI.encode(url.strip))
    response = Faraday.get(uri, nil, 'User-Agent' => 'logstash-filter-ipinfo')

  end

  result = JSON.parse(response.body)

  event.set(@target, result)
  # filter_matched should go in the last line of our successful code
  filter_matched(event)

end

#registerObject



34
35
# File 'lib/logstash/filters/ipinfo.rb', line 34

def register
end