Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added the uppercase and lowercase mutations #172

Merged
merged 1 commit into from

2 participants

@growse

A fairly simple feature addition, each mutation will check to see
if the input is a string before calling either .upcase! or .downcase!

@growse growse Added the lowercase and uppercase mutations to the mutate filter.
A fairly simple feature addition, each mutation will check to see
if the input is a string before calling either .upcase! or .downcase!
cff370f
@jordansissel jordansissel merged commit 7f6d69c into from
@jordansissel

Thanks for the patch!

One small note (and nothing super strong to worry about), in future patches, it's worth trying to mirror the spacing/style of the surrounding code so it's a bit easier to maintain. For this patch, I've cleaned it up just now - fa3e023

I also updated the CONTRIBUTORS file and added you. Thanks again :)

@growse

No problem :)

Completely understand about formatting styles, thought I had it right, but evidently not. I'm probably going to blame a combination of myself and vim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 13, 2012
  1. @growse

    Added the lowercase and uppercase mutations to the mutate filter.

    growse authored
    A fairly simple feature addition, each mutation will check to see
    if the input is a string before calling either .upcase! or .downcase!
This page is out of date. Refresh to see the latest.
Showing with 45 additions and 0 deletions.
  1. +45 −0 lib/logstash/filters/mutate.rb
View
45 lib/logstash/filters/mutate.rb
@@ -80,6 +80,26 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
#
config :gsub, :validate => :array
+ # Convert a string to its uppercase equivalent
+ #
+ # Example:
+ #
+ # mutate {
+ # uppercase => [ "fieldname" ]
+ # }
+ #
+ config :uppercase, :validate => :array
+
+ # Convert a string to its lowercase equivalent
+ #
+ # Example:
+ #
+ # mutate {
+ # lowercase => [ "fieldname" ]
+ # }
+ #
+ config :lowercase, :validate => :array
+
public
def register
valid_conversions = %w(string integer float)
@@ -117,6 +137,8 @@ def filter(event)
replace(event) if @replace
convert(event) if @convert
gsub(event) if @gsub
+ uppercase(event) if @uppercase
+ lowercase(event) if @lowercase
filter_matched(event)
end # def filter
@@ -205,4 +227,27 @@ def gsub(event)
end
end # @gsub_parsed.each
end # def gsub
+
+ private
+ def uppercase(event)
+ @uppercase.each do |field|
+ if event[field].is_a?(String)
+ event[field].upcase!
+ else
+ @logger.debug("Can't uppercase something that isn't a string",
+ :field => field, :value => event[field])
+ end
+ end
+ end # def uppercase
+ private
+ def lowercase(event)
+ @lowercase.each do |field|
+ if event[field].is_a?(String)
+ event[field].downcase!
+ else
+ @logger.debug("Can't lowercase something that isn't a string",
+ :field => field, :value => event[field])
+ end
+ end
+ end # def lowercase
end # class LogStash::Filters::Mutate
Something went wrong with that request. Please try again.