Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#
# Example Input
#
# time=1335851771&a=b&c=d&d=e
#
# Example Conf:
#
# <source>
# type tail_kv
# path /path/to/the/file1
# tag filter
# time_key time
# pos_file /var/log/td-agent/file1.pos
# </source>
#
class TailKVInput < Fluent::TailInput
Fluent::Plugin.register_input('tail_kv', self)
# Override 'configure_parser(conf)' method that initializes the parser.
def configure_parser(conf)
require 'cgi'
@time_key = conf['time_key']
end
# Override 'parse_line(line)' method that returns time and record.
def parse_line(line)
s = line.force_encoding('UTF-8')
h = Hash[ s.split('&').map { |kv|
k,v = kv.split('=', 2);
[CGI.unescape(k), CGI.unescape(v)]
}
]
return (h[@time_key] || Time.now.to_i), h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.