@@ -4,6 +4,11 @@ module Fluent
44 class Plugin ::RecordModifierFilter < Plugin ::Filter
55 Fluent ::Plugin . register_filter ( 'record_modifier' , self )
66
7+ config_param :prepare_value , :string , default : nil ,
8+ desc : <<-DESC
9+ Prepare values for filtering in configure phase. Prepared values can be used in <record>.
10+ You can write any ruby code.
11+ DESC
712 config_param :char_encoding , :string , default : nil ,
813 desc : <<-DESC
914Fluentd including some plugins treats the logs as a BINARY by default to forward.
@@ -26,7 +31,7 @@ class Plugin::RecordModifierFilter < Plugin::Filter
2631This option is exclusive with `remove_keys`.
2732DESC
2833
29- BUILTIN_CONFIGURATIONS = %W( type @type log_level @log_level id @id char_encoding remove_keys whitelist_keys )
34+ BUILTIN_CONFIGURATIONS = %W( type @type log_level @log_level id @id char_encoding remove_keys whitelist_keys prepare_value )
3035
3136 def configure ( conf )
3237 super
@@ -68,7 +73,7 @@ def configure(conf)
6873 check_config_placeholders ( k , v )
6974 element . has_key? ( k ) # to suppress unread configuration warning
7075 @has_tag_parts = true if v . include? ( 'tag_parts' )
71- @map [ k ] = DynamicExpander . new ( k , v )
76+ @map [ k ] = DynamicExpander . new ( k , v , @prepare_value )
7277 end
7378 end
7479
@@ -157,7 +162,7 @@ def check_config_placeholders(k, v)
157162 end
158163
159164 class DynamicExpander
160- def initialize ( param_key , param_value )
165+ def initialize ( param_key , param_value , prepare_value )
161166 if param_value . include? ( '${' )
162167 __str_eval_code__ = parse_parameter ( param_value )
163168
@@ -173,6 +178,12 @@ def expand(tag, time, record, tag_parts)
173178 @param_value = param_value
174179 end
175180
181+ begin
182+ eval prepare_value if prepare_value
183+ rescue SyntaxError
184+ raise ConfigError , "Pass invalid syntax parameter : key = prepare_value, value = #{ prepare_value } "
185+ end
186+
176187 begin
177188 # check eval genarates wrong code or not
178189 expand ( nil , nil , nil , nil )
0 commit comments