Fluent filter plugin to external ruby script.
gem install fluent-plugin-script
| fluent-plugin-script | fluentd |
|---|---|
| >= 0.1.0 | >= v0.14.0 |
| < 0.0.4 | < v0.14.0 |
<filter foo.bar.*>
type script
path /etc/fluentd/example.rb
</filter>
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
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>
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")recordendfoo.bar.code: {"key1": "200"}
foo.bar.code: {"code":200}
foo.bar.msg: {"key2":280,"key3":"Something happend."}
foo.bar.msg: {"message":"WARN:Something happend."}