Skip to content
This repository was archived by the owner on Mar 22, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions fluent.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<source>
type exec
command echo http://example.com
keys uri
tag example
run_interval 1s
</source>

<match example.**>
type copy
<store>
type ruby_one_liner
require_libs open-uri
command $log.warn "oneline"
run_interval 1
any_config 2
</store>
<store>
type ruby_one_liner
require_libs open-uri
commandfile hoge.rb
run_interval 1
any_config 2
</store>
</match>
1 change: 1 addition & 0 deletions hoge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$log.warn "BaA"
27 changes: 24 additions & 3 deletions lib/fluent/plugin/out_ruby_one_liner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class Fluent::RubyOneLinerOutput < Fluent::Output
Fluent::Plugin.register_output('ruby_one_liner', self)

config_param :require_libs, :string,:default => ''
config_param :command, :string
config_param :command, :string, :default => ''
config_param :commandfile, :string, :default => ''
config_param :run_interval, :integer

def initialize
Expand All @@ -12,12 +13,25 @@ def initialize

def configure(config)
super

libs = @require_libs.split(',')
libs.each {|lib| require lib}

Signal.trap :INT do
$log.warn 'out_ruby_one_liner: reload commandfile start'
reload_commandfile!
$log.warn 'out_ruby_one_liner: reload commandfile end'
end

command = if !@command.empty?
@command
elsif !@commandfile.empty?
open(@commandfile).read
else
raise ConfigError, "out_ruby_one_liner: command or commandfile is required to be set."
end
@config = config
@lambda = eval("lambda {|tag, time, record| #{@command}}")
@lambda = eval("lambda {|tag, time, record| #{command}}")
@q = Queue.new
end

Expand Down Expand Up @@ -50,6 +64,13 @@ def emit(tag, es, chain)

private

def reload_commandfile!
command = open(@commandfile).read
Thread.kill(@thread)
@lambda = eval("lambda {|tag, time, record| #{command}}")
@thread = Thread.new(&method(:run))
end

def run
loop do
param = @q.pop
Expand Down