1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

Ensure that field keys configured in Filters are valid UTF-8

This commit is contained in:
Holger Just 2018-01-25 01:14:06 +01:00
parent 2a9d0f4b74
commit 70f9b1b735
3 changed files with 14 additions and 5 deletions

View File

@ -8,6 +8,7 @@
require 'ipaddr'
require 'rackstash/filter'
require 'rackstash/helpers/utf8'
module Rackstash
module Filter
@ -41,6 +42,8 @@ module Rackstash
# filter :anonymize_ip_mask, {'source_ip' => 'source_ip'}
# end
class AnonymizeIPMask
include Rackstash::Helpers::UTF8
# @param field_spec [Hash<#to_s => #to_s>] a `Hash` specifying which
# fields should be anonymized and where the result should be stored. The
# key described the name of the existing source field and the value the
@ -54,7 +57,7 @@ module Rackstash
def initialize(field_spec, ipv4_mask: 8, ipv6_mask: 80)
@fields = {}
Hash(field_spec).each_pair do |key, value|
@fields[key.to_s] = value.to_s
@fields[utf8_encode(key)] = utf8_encode(value)
end
@ipv4_mask = Integer(ipv4_mask)

View File

@ -1,11 +1,12 @@
# frozen_string_literal: true
#
# Copyright 2017 Holger Just
# Copyright 2017 - 2018 Holger Just
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'rackstash/filter'
require 'rackstash/helpers/utf8'
module Rackstash
module Filter
@ -17,13 +18,15 @@ module Rackstash
# filter :rename, "HOST_OR_IP" => "client_ip"
# end
class Rename
include Rackstash::Helpers::UTF8
# @param spec [Hash<#to_s => #to_s>] a `Hash` specifying how fields should
# be renamed, with the existing field name as a hash key and the new
# field name as the respective value.
def initialize(spec)
@rename = {}
Hash(spec).each_pair do |key, value|
@rename[key.to_s] = value.to_s
@rename[utf8_encode(key)] = utf8_encode(value)
end
end

View File

@ -1,11 +1,12 @@
# frozen_string_literal: true
#
# Copyright 2017 Holger Just
# Copyright 2017 - 2018 Holger Just
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'rackstash/filter'
require 'rackstash/helpers/utf8'
module Rackstash
module Filter
@ -30,6 +31,8 @@ module Rackstash
# here, namely `String`, `Integer`, `Float`, `Hash`, `Array`, `nil`, `true`,
# or `false`.
class Replace
include Rackstash::Helpers::UTF8
# @param spec [Hash<#to_s => #call,Object>] a `Hash` specifying new field
# values for the named keys. Values can be given in the form of a fixed
# value or a callable object (e.g. a `Proc`) which accepts the event as
@ -37,7 +40,7 @@ module Rackstash
def initialize(spec)
@replace = {}
Hash(spec).each_pair do |key, value|
@replace[key.to_s] = value
@replace[utf8_encode(key)] = value
end
end