Class: LogStash::Filters::Mutate
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::Mutate
- Defined in:
- lib/logstash/filters/mutate.rb
Overview
The mutate filter allows you to perform general mutations on fields. You can rename, replace, and modify fields in your events.
Constant Summary collapse
- TRUE_REGEX =
(/^(true|t|yes|y|1|1.0)$/i).freeze
- FALSE_REGEX =
(/^(false|f|no|n|0|0.0)$/i).freeze
- CONVERT_PREFIX =
"convert_".freeze
Instance Method Summary collapse
Instance Method Details
#filter(event) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/logstash/filters/mutate.rb', line 250 def filter(event) coerce(event) if @coerce rename(event) if @rename update(event) if @update replace(event) if @replace convert(event) if @convert gsub(event) if @gsub uppercase(event) if @uppercase capitalize(event) if @capitalize lowercase(event) if @lowercase strip(event) if @strip split(event) if @split join(event) if @join merge(event) if @merge copy(event) if @copy filter_matched(event) rescue => ex = { :exception => ex. } [:backtrace] = ex.backtrace if logger.debug? logger.warn('Exception caught while applying mutate filter', ) event.tag(@tag_on_failure) end |
#register ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/logstash/filters/mutate.rb', line 217 def register valid_conversions = %w(string integer float boolean integer_eu float_eu ) # TODO(sissel): Validate conversion requests if provided. @convert.nil? or @convert.each do |field, type| if !valid_conversions.include?(type) raise LogStash::ConfigurationError, I18n.t( "logstash.runner.configuration.invalid_plugin_register", :plugin => "filter", :type => "mutate", :error => "Invalid conversion type '#{type}', expected 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 LogStash::ConfigurationError, I18n.t( "logstash.runner.configuration.invalid_plugin_register", :plugin => "filter", :type => "mutate", :error => "Invalid gsub configuration #{[field, needle, replacement]}. gsub requires 3 non-nil elements per config entry" ) end @gsub_parsed << { :field => field, :needle => (needle.index("%{").nil?? Regexp.new(needle): needle), :replacement => replacement } end end |