Class: Fluent::Plugin::ParseCookieOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_parse_cookie.rb

Instance Method Summary collapse

Constructor Details

#initializeParseCookieOutput

Returns a new instance of ParseCookieOutput.



15
16
17
18
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 15

def initialize
  super
  require 'cgi'
end

Instance Method Details

#configure(conf) ⇒ Object



23
24
25
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 23

def configure(conf)
  super
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 35

def multi_workers_ready?
  true
end


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 52

def parse_cookie(record, tag)
  if record[key]
    parsed_cookie = CGI::Cookie.parse(record[key])
    hash = {}
    parsed_cookie.each do |k, array|
      hash.merge!(k => array.select { |v| v.class == String })
    end

    hash = hash.reject { |_k, v| v == [] } if remove_empty_array == true

    if single_value_to_string == true
      hash.each do |k, v|
        hash[k] = v[0] if v.count == 1
      end
    end

    target = sub_key ? (record[sub_key] ||= {}) : record

    target.merge!(hash)

    record.delete(key) if remove_cookie
  end
  record
rescue StandardError => e
  log.warn("out_parse_cookie: error_class:#{e.class} error_message:#{e.message} tag:#{tag} record:#{record} bactrace:#{e.backtrace.first}")
end

#process(tag, es) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 39

def process(tag, es)
  es.each do |time, record|
    t = tag.dup
    new_record = parse_cookie(record, tag)

    t = @tag_prefix + t unless @tag_prefix.nil?

    router.emit(t, time, new_record)
  end
rescue StandardError => e
  log.warn("out_parse_cookie: error_class:#{e.class} error_message:#{e.message} tag:#{tag} es:#{es} bactrace:#{e.backtrace.first}")
end

#shutdownObject



31
32
33
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 31

def shutdown
  super
end

#startObject



27
28
29
# File 'lib/fluent/plugin/out_parse_cookie.rb', line 27

def start
  super
end