Class: Fluent::MutateFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::MutateFilter
- Defined in:
- lib/fluent/plugin/filter_mutate.rb
Constant Summary collapse
- MUTATE_ACTIONS =
List of all possible mutate actions, in the order that we will apply them. As it stands, this is the order in which Logstash would apply them.
%w( rename update replace convert gsub uppercase lowercase strip remove split join merge )
- VALID_CONVERSIONS =
Convert valid types
%w(string integer float boolean datetime)
- CONVERT_PREFIX =
Convert helper method prefix
"convert_".freeze
- TRUE_REGEX =
Convert boolean regex
(/^(true|t|yes|y|1)$/i).freeze
- FALSE_REGEX =
(/^(false|f|no|n|0)$/i).freeze
- ENVIRONMENT_TAG_REGEXP =
Placeholder regex
/%e\{[^}]+\}/- TEMPLATE_TAG_REGEXP =
Placeholder regex
/%\{[^}]+\}/
Instance Method Summary collapse
-
#configure(conf) ⇒ NilClass
Initialize attributes and parameters.
-
#filter(tag, time, record) ⇒ Hash
Filter action which will manipulate records.
Instance Method Details
#configure(conf) ⇒ NilClass
Initialize attributes and parameters
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/fluent/plugin/filter_mutate.rb', line 151 def configure(conf) super @convert.nil? or @convert.each do |field, type| if !VALID_CONVERSIONS.include?(type) raise ConfigError, "convert #{type} is not one of #{VALID_CONVERSIONS.join(',')}." end end @gsub_parsed = [] @gsub.nil? or @gsub.each_slice(3) do |field, needle, replacement| if [field, needle, replacement].any? {|n| n.nil?} raise ConfigError, "gsub #{[field,needle,replacement]} requires 3 elements." end @gsub_parsed << { field: field, needle: (needle.index("%{").nil?? Regexp.new(needle): needle), replacement: replacement } end end |
#filter(tag, time, record) ⇒ Hash
Filter action which will manipulate records
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/fluent/plugin/filter_mutate.rb', line 180 def filter(tag, time, record) # In order to more easily navigate the record, we wrap the record in a # delegator. We additionally pass the `expand_nesting` option which # determines whether we should treat periods as field separators. result = Fluent::PluginMixin::MutateEvent. new(record, expand_nesting: @expand_nesting) result.event_time = time.to_i result.event_tag = tag MUTATE_ACTIONS.each do |action| begin send(action.to_sym, result) if instance_variable_get("@#{action}") rescue => e log.warn "failed to mutate #{action} action", error: e log.warn_backtrace end end result.prune if @prune_empty result.to_record end |