From 1aa46a9218a878ac392314a12ceada1bd6fbb9ce Mon Sep 17 00:00:00 2001 From: Brennen Smith Date: Mon, 8 Jan 2018 09:03:49 -1000 Subject: [PATCH 1/2] Add support for Redis unix sockets --- lib/logstash/outputs/redis.rb | 38 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/logstash/outputs/redis.rb b/lib/logstash/outputs/redis.rb index 81e3c9b..74ea044 100644 --- a/lib/logstash/outputs/redis.rb +++ b/lib/logstash/outputs/redis.rb @@ -31,7 +31,7 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base # For example: # [source,ruby] # "127.0.0.1" - # ["127.0.0.1", "127.0.0.2"] + # ["127.0.0.1", "127.0.0.2", "/var/run/redis/redis.sock"] # ["127.0.0.1:6380", "127.0.0.1"] config :host, :validate => :array, :default => ["127.0.0.1"] @@ -178,31 +178,47 @@ def close private def connect - @current_host, @current_port = @host[@host_idx].split(':') - @host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1 + if @host[@host_idx].start_with?("/") + @current_path = @host[@host_idx] + connectionParams = { + :path => @current_path + } + else + @current_host, @current_port = @host[@host_idx].split(':') + + if not @current_port + @current_port = @port + end - if not @current_port - @current_port = @port + connectionParams = { + :host => @current_host, + :port => @current_port + } end - - params = { - :host => @current_host, - :port => @current_port, + + baseParams = { :timeout => @timeout, :db => @db } - @logger.debug("connection params", params) + + params = connectionParams.merge(baseParams) + + @logger.info("connection params", params) if @password params[:password] = @password.value end + @host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1 + Redis.new(params) + end # def connect # A string used to identify a Redis instance in log messages def identity - "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db} #{@data_type}:#{@key}" + @redis_url = @current_path.nil? ? "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db}" : "#{@password}@#{@pcurrent_path}/#{@db}" + return "#{@redis_url} #{@data_type}:#{@key}" end def send_to_redis(event, payload) From b02d21e6a21acff371c7992814b1494999258ff3 Mon Sep 17 00:00:00 2001 From: Brennen Smith Date: Mon, 8 Jan 2018 09:20:17 -1000 Subject: [PATCH 2/2] move logger back to debug and clean up password logic --- lib/logstash/outputs/redis.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/logstash/outputs/redis.rb b/lib/logstash/outputs/redis.rb index 74ea044..3e9feb5 100644 --- a/lib/logstash/outputs/redis.rb +++ b/lib/logstash/outputs/redis.rb @@ -198,16 +198,13 @@ def connect baseParams = { :timeout => @timeout, - :db => @db + :db => @db, + :password => @password.nil? ? nil : @password.value } params = connectionParams.merge(baseParams) - @logger.info("connection params", params) - - if @password - params[:password] = @password.value - end + @logger.debug("connection params", params) @host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1