Created
May 1, 2012 05:56
-
-
Save kzk/2565478 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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