Skip to content

Instantly share code, notes, and snippets.

@kzk
Created May 1, 2012 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kzk/2565478 to your computer and use it in GitHub Desktop.
Save kzk/2565478 to your computer and use it in GitHub Desktop.
#
# 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