fluent-plugin-filter-record-map
Filter Plugin to create a new record containing the values converted by Ruby script.
Installation
Add this line to your application's Gemfile:
gem 'fluent-plugin-filter-record-map'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fluent-plugin-filter-record-map
Configuration
<filter>
type record_map
# map1: required
map1 new_record["new_foo"] = record["foo"]
map2 new_record["new_bar"] = record["bar"]
</filter>
Usage
Example1
<filter>
type record_map
map1 new_record["new_foo"] = record["foo"].upcase
map2 new_record["new_bar"] = record["bar"].upcase
</filter>
$ echo '{"foo":"bar", "bar":"zoo"})' | fluentd test.data
#=> 2015-01-01 23:34:45 +0900 test.data: {"new_foo":"BAR","new_bar":"ZOO"}
Example2
<filter>
type record_map
map1 record.each {|k, v| new_record[k] = k + "." + v }
</filter>
$ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
#=> 2015-01-01 23:34:45 +0900 test.data: {"foo":"foo.bar","bar":"bar.zoo"}
Example3
<filter>
type record_map
map1 new_record = {"new_foo" => record["foo"]}
</filter>
$ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
#=> 2015-01-01 23:34:45 +0900 test.data: {"new_foo":"bar"}
Use tag
, tag_parts
<filter>
type record_map
map1 new_record["tag"] = tag
map2 new_record["new_foo"] = tag_parts[1] + "." + record["foo"]
</filter>
$ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
#=> 2015-01-01 23:34:45 +0900 test.data: {"tag":"test.data","new_foo":"data.foo"}
Use hostname
<filter>
type record_map
map1 new_record["hostname"] = hostname
</filter>
Use time
<filter>
type record_map
map1 new_record["time"] = time.strftime("%Y-%m-%d")
</filter>
$ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
#=> 2015-01-01 23:34:45 +0900 test.data: {"hostname":"my-host"}