class LogStash::Filters::Ipinfo
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 .
Public Instance Methods
filter(event)
click to toggle source
# 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
register()
click to toggle source
# File lib/logstash/filters/ipinfo.rb, line 34 def register end