Class: LogStash::Filters::Redis
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::Redis
- Defined in:
- lib/logstash/filters/redis.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#filter(event) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# 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 |
#register ⇒ Object
70 71 72 73 74 |
# File 'lib/logstash/filters/redis.rb', line 70 def register require 'redis' require 'json' @redis = nil end |