lib/fluent/plugin/out_referer_parser.rb in fluent-plugin-referer-parser-0.0.3 vs lib/fluent/plugin/out_referer_parser.rb in fluent-plugin-referer-parser-0.0.4
- old
+ new
@@ -1,6 +1,6 @@
-require 'ostruct'
+require 'referer-parser'
# referer parser output
class Fluent::RefererParserOutput < Fluent::Output
Fluent::Plugin.register_output('referer_parser', self)
@@ -12,16 +12,15 @@
config_param :out_key_known, :string, default: 'referer_known'
config_param :out_key_referer, :string, default: 'referer_referer'
config_param :out_key_search_term, :string, default: 'referer_search_term'
- PARSE_ERROR_STRUCT = OpenStruct.new(known?: false)
+ REFERERS = RefererParser::Referers.load_referers_from_yaml(RefererParser::Referers.get_yaml_file)
def initialize
super
require 'cgi'
- require 'referer-parser'
end
def configure(conf)
super
@@ -60,14 +59,14 @@
def emit(tag, es, chain)
tag = tag_mangle(tag)
es.each do |time, record|
referer =
begin
- RefererParser::Referer.new(record[@key_name])
+ RefererParser::Referer.new(record[@key_name], nil, REFERERS)
rescue
- PARSE_ERROR_STRUCT
+ nil
end
- if referer.known?
+ if referer && referer.known?
search_term = referer.search_term
parameters = CGI.parse(referer.uri.query)
input_encoding = parameters['ie'][0] || parameters['ei'][0]
begin
search_term = search_term.force_encoding(input_encoding).encode('utf-8') if input_encoding && /\Autf-?8\z/i !~ input_encoding