Skip to content

Repository files navigation

fluent-plugin-script

Fluent filter plugin to external ruby script.

Build StatusGem

install

gem install fluent-plugin-script

Requirements

fluent-plugin-scriptfluentd
>= 0.1.0>= v0.14.0
< 0.0.4< v0.14.0

Configuration

fluent.conf

<filter foo.bar.*>
type script
path /etc/fluentd/example.rb
</filter>

external ruby script

def start
super
# This is the first method to be called when it starts running
# Use it to allocate resources, etc.
end
def shutdown
super
# This method is called when Fluentd is shutting down.
# Use it to free up resources, etc.
end
def filter(tag, time, record)
# This method implements the filtering logic for individual filters
record
end

ref. http://docs.fluentd.org/articles/plugin-development#filter-plugins

Setting default directory

By setting the FLUENT_PLUGIN_SCRIPT_DIR environment variable, you can specify the default directory where scripts are located and access them without specifying the full path.

FLUENT_PLUGIN_SCRIPT_DIR="/etc/fluentd/"
<filter foo.bar.*>
type script
path example.rb
</filter>

Example

example.rb

deffilter(tag,time,record)casetagwhen/.+\.code$/code(record)when/.+\.msg$/message(record)endenddefcode(record)ifrecord.has_key?("key1")record["code"]=record["key1"].to_irecord.delete("key1")endrecordenddefmessage(record)caserecord["key2"].to_iwhen100..200level="INFO"when201..300level="WARN"elselevel="ERROR"endrecord.delete("key2")record["message"]=level + ":" + record["key3"]record.delete("key3")recordend

Example 1

input
foo.bar.code: {"key1": "200"}
output
foo.bar.code: {"code":200}

Example 2

input
foo.bar.msg: {"key2":280,"key3":"Something happend."}
output
foo.bar.msg: {"message":"WARN:Something happend."}

About

Fluentd filter plugin to external ruby script

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages