class Charrington::TransformPostgres

Constants

ColumnBlacklist
Error
EventNil
KEY_FILTER_BLACKLIST
KEY_RAISE_BLACKLIST
TableNameNil

Attributes

event[RW]
top_level_keys[R]

Public Class Methods

new(event) click to toggle source
# File lib/logstash/outputs/charrington/transform_postgres.rb, line 17
def initialize(event)
  raise EventNil, "Event is nil" if event.nil?
  event = event.to_hash
  @event = drop_keys(event)
  @top_level_keys = @event.keys
  check_blacklist
end

Public Instance Methods

call() click to toggle source
# File lib/logstash/outputs/charrington/transform_postgres.rb, line 25
def call
  flattened = flatten_hash(event)
  top_level_keys.each { |k| event.delete(k) }
  flattened.each_pair { |key, val| event[key] = val }
  event
end

Private Instance Methods

check_blacklist() click to toggle source
# File lib/logstash/outputs/charrington/transform_postgres.rb, line 34
def check_blacklist
  arr = []
  KEY_RAISE_BLACKLIST.each { |k| arr << k if event.keys.include?(k) }
  raise ColumnBlacklist, "Event contains these blacklisted keys: #{arr.join(",")}" unless arr.empty?
end
drop_keys(event) click to toggle source
# File lib/logstash/outputs/charrington/transform_postgres.rb, line 40
def drop_keys(event)
  event.delete_if {|k, _v| k.start_with?("@") || KEY_FILTER_BLACKLIST.include?(k) }
end
flatten_hash(hash) click to toggle source
# File lib/logstash/outputs/charrington/transform_postgres.rb, line 44
def flatten_hash(hash)
  hash.each_with_object({}) do |(k, v), acc|
    if v.is_a? Hash
      flatten_hash(v).map do |h_k, h_v|
        acc["#{k}_#{h_k}"] = h_v
      end
    else
      acc[k] = v
    end
  end
end