class LogStash::Filters::Redis
A general search and replace tool which queries replacement values from a redis instance.
This is actually a redis version of a translate plugin. <www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html>
Operationally, if the event field specified in the “field” configuration matches the EXACT contents of a redis key, the field's value will be substituted with the matched key's value from the redis GET <key> command.
By default, the redis filter will replace the contents of the matching event field (in-place). However, by using the “destination” configuration item, you may also specify a target event field to populate with the new translated value.
Alternatively, for simple string search and replacements for just a few values you might consider using the gsub function of the mutate filter.
Public Instance Methods
# File lib/logstash/filters/redis.rb, line 77 def filter(event) return unless event.include?(@field) return if event.include?(@destination) and not @override source = event.get(@field).is_a?(Array) ? event.get(@field).first.to_s : event.get(@field).to_s @redis ||= connect val = @redis.get(source) if val begin event.set(@destination, JSON.parse(val)) rescue JSON::ParserError => e event.set(@destination, val) #event.set("redis-error", "Cannot parse JSON: " + e.to_s) end elsif @fallback event.set(@destination, @fallback) end # filter_matched should go in the last line of our successful code filter_matched(event) end
# File lib/logstash/filters/redis.rb, line 70 def register require 'redis' require 'json' @redis = nil end
Private Instance Methods
# File lib/logstash/filters/redis.rb, line 100 def connect Redis.new( :host => @host, :port => @port, :timeout => @timeout, :db => @db, :password => @password.nil? ? nil : @password.value ) end