Created
October 28, 2011 07:03
-
-
Save frsyuki/1321783 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<match xxx.*> | |
type in_exec | |
command cat | |
in_keys host,message | |
out_keys host,message | |
tag filtered.out | |
</match> |
This file contains hidden or 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
module Fluent | |
class InExecOutput < Output | |
Plugin.register_output('in_exec', self) | |
def initialize | |
super | |
end | |
config_param :command, :string | |
config_param :in_keys, :string | |
config_param :out_keys, :string | |
config_param :tag, :string | |
#config_param :time_key, :string | |
def configure | |
super | |
@in_keys = @in_keys.strip(',') | |
@out_keys = @out_keys.strip(',') | |
end | |
def start | |
@io = IO.popen(@command) | |
@thread = Thread.new(&method(:run)) | |
end | |
def run | |
@io.each_line {|line| | |
vals = line.strip("\t") | |
record = Hash[@out_keys.zip(vals)] | |
time = Engine.now # TODO time_key & time_format | |
Engine.emit(@tag, time, record) | |
} | |
end | |
def emit(tag, es, chain) | |
es.each {|time,record| | |
vals = @in_keys.map {|k| record[k].to_s } | |
@io.write vals.join("\t") | |
@io.write "\n" | |
} | |
@io.flush | |
chain.next | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment