mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-21 07:41:12 +00:00
Ensure that field keys configured in Filters are valid UTF-8
This commit is contained in:
parent
2a9d0f4b74
commit
70f9b1b735
@ -8,6 +8,7 @@
|
|||||||
require 'ipaddr'
|
require 'ipaddr'
|
||||||
|
|
||||||
require 'rackstash/filter'
|
require 'rackstash/filter'
|
||||||
|
require 'rackstash/helpers/utf8'
|
||||||
|
|
||||||
module Rackstash
|
module Rackstash
|
||||||
module Filter
|
module Filter
|
||||||
@ -41,6 +42,8 @@ module Rackstash
|
|||||||
# filter :anonymize_ip_mask, {'source_ip' => 'source_ip'}
|
# filter :anonymize_ip_mask, {'source_ip' => 'source_ip'}
|
||||||
# end
|
# end
|
||||||
class AnonymizeIPMask
|
class AnonymizeIPMask
|
||||||
|
include Rackstash::Helpers::UTF8
|
||||||
|
|
||||||
# @param field_spec [Hash<#to_s => #to_s>] a `Hash` specifying which
|
# @param field_spec [Hash<#to_s => #to_s>] a `Hash` specifying which
|
||||||
# fields should be anonymized and where the result should be stored. The
|
# 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
|
# 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)
|
def initialize(field_spec, ipv4_mask: 8, ipv6_mask: 80)
|
||||||
@fields = {}
|
@fields = {}
|
||||||
Hash(field_spec).each_pair do |key, value|
|
Hash(field_spec).each_pair do |key, value|
|
||||||
@fields[key.to_s] = value.to_s
|
@fields[utf8_encode(key)] = utf8_encode(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ipv4_mask = Integer(ipv4_mask)
|
@ipv4_mask = Integer(ipv4_mask)
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
#
|
#
|
||||||
# Copyright 2017 Holger Just
|
# Copyright 2017 - 2018 Holger Just
|
||||||
#
|
#
|
||||||
# This software may be modified and distributed under the terms
|
# This software may be modified and distributed under the terms
|
||||||
# of the MIT license. See the LICENSE.txt file for details.
|
# of the MIT license. See the LICENSE.txt file for details.
|
||||||
|
|
||||||
require 'rackstash/filter'
|
require 'rackstash/filter'
|
||||||
|
require 'rackstash/helpers/utf8'
|
||||||
|
|
||||||
module Rackstash
|
module Rackstash
|
||||||
module Filter
|
module Filter
|
||||||
@ -17,13 +18,15 @@ module Rackstash
|
|||||||
# filter :rename, "HOST_OR_IP" => "client_ip"
|
# filter :rename, "HOST_OR_IP" => "client_ip"
|
||||||
# end
|
# end
|
||||||
class Rename
|
class Rename
|
||||||
|
include Rackstash::Helpers::UTF8
|
||||||
|
|
||||||
# @param spec [Hash<#to_s => #to_s>] a `Hash` specifying how fields should
|
# @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
|
# be renamed, with the existing field name as a hash key and the new
|
||||||
# field name as the respective value.
|
# field name as the respective value.
|
||||||
def initialize(spec)
|
def initialize(spec)
|
||||||
@rename = {}
|
@rename = {}
|
||||||
Hash(spec).each_pair do |key, value|
|
Hash(spec).each_pair do |key, value|
|
||||||
@rename[key.to_s] = value.to_s
|
@rename[utf8_encode(key)] = utf8_encode(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
#
|
#
|
||||||
# Copyright 2017 Holger Just
|
# Copyright 2017 - 2018 Holger Just
|
||||||
#
|
#
|
||||||
# This software may be modified and distributed under the terms
|
# This software may be modified and distributed under the terms
|
||||||
# of the MIT license. See the LICENSE.txt file for details.
|
# of the MIT license. See the LICENSE.txt file for details.
|
||||||
|
|
||||||
require 'rackstash/filter'
|
require 'rackstash/filter'
|
||||||
|
require 'rackstash/helpers/utf8'
|
||||||
|
|
||||||
module Rackstash
|
module Rackstash
|
||||||
module Filter
|
module Filter
|
||||||
@ -30,6 +31,8 @@ module Rackstash
|
|||||||
# here, namely `String`, `Integer`, `Float`, `Hash`, `Array`, `nil`, `true`,
|
# here, namely `String`, `Integer`, `Float`, `Hash`, `Array`, `nil`, `true`,
|
||||||
# or `false`.
|
# or `false`.
|
||||||
class Replace
|
class Replace
|
||||||
|
include Rackstash::Helpers::UTF8
|
||||||
|
|
||||||
# @param spec [Hash<#to_s => #call,Object>] a `Hash` specifying new field
|
# @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
|
# 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
|
# value or a callable object (e.g. a `Proc`) which accepts the event as
|
||||||
@ -37,7 +40,7 @@ module Rackstash
|
|||||||
def initialize(spec)
|
def initialize(spec)
|
||||||
@replace = {}
|
@replace = {}
|
||||||
Hash(spec).each_pair do |key, value|
|
Hash(spec).each_pair do |key, value|
|
||||||
@replace[key.to_s] = value
|
@replace[utf8_encode(key)] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user