Skip to content

Add support for Redis unix sockets #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
| <<plugins-{type}s-{plugin}-data_type>> |<<string,string>>, one of `["list", "channel", "pattern_channel"]`|Yes
| <<plugins-{type}s-{plugin}-db>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-host>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-path>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-key>> |<<string,string>>|Yes
| <<plugins-{type}s-{plugin}-password>> |<<password,password>>|No
| <<plugins-{type}s-{plugin}-port>> |<<number,number>>|No
Expand All @@ -58,15 +59,15 @@ input plugins.
&nbsp;

[id="plugins-{type}s-{plugin}-batch_count"]
===== `batch_count`
===== `batch_count`

* Value type is <<number,number>>
* Default value is `125`

The number of events to return from Redis using EVAL.

[id="plugins-{type}s-{plugin}-data_type"]
===== `data_type`
===== `data_type`

* This is a required setting.
* Value can be any of: `list`, `channel`, `pattern_channel`
Expand All @@ -77,23 +78,32 @@ key. If `redis\_type` is `channel`, then we will SUBSCRIBE to the key.
If `redis\_type` is `pattern_channel`, then we will PSUBSCRIBE to the key.

[id="plugins-{type}s-{plugin}-db"]
===== `db`
===== `db`

* Value type is <<number,number>>
* Default value is `0`

The Redis database number.

[id="plugins-{type}s-{plugin}-host"]
===== `host`
===== `host`

* Value type is <<string,string>>
* Default value is `"127.0.0.1"`

The hostname of your Redis server.

id="plugins-{type}s-{plugin}-path"]
===== `path`

* Value type is <<string,string>>
* There is no default value for this setting.
* Path will override Host configuration if both specified.

The unix socket path of your Redis server.

[id="plugins-{type}s-{plugin}-key"]
===== `key`
===== `key`

* This is a required setting.
* Value type is <<string,string>>
Expand All @@ -102,31 +112,31 @@ The hostname of your Redis server.
The name of a Redis list or channel.

[id="plugins-{type}s-{plugin}-password"]
===== `password`
===== `password`

* Value type is <<password,password>>
* There is no default value for this setting.

Password to authenticate with. There is no authentication by default.

[id="plugins-{type}s-{plugin}-port"]
===== `port`
===== `port`

* Value type is <<number,number>>
* Default value is `6379`

The port to connect on.

[id="plugins-{type}s-{plugin}-threads"]
===== `threads`
===== `threads`

* Value type is <<number,number>>
* Default value is `1`



[id="plugins-{type}s-{plugin}-timeout"]
===== `timeout`
===== `timeout`

* Value type is <<number,number>>
* Default value is `5`
Expand All @@ -136,4 +146,4 @@ Initial connection timeout in seconds.


[id="plugins-{type}s-{plugin}-common-options"]
include::{include_path}/{type}.asciidoc[]
include::{include_path}/{type}.asciidoc[]
24 changes: 20 additions & 4 deletions lib/logstash/inputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
# The port to connect on.
config :port, :validate => :number, :default => 6379

# The unix socket path to connect on. Will override host and port if defined.
# There is no unix socket path by default.
config :path, :validate => :string

# The Redis database number.
config :db, :validate => :number, :default => 0

Expand Down Expand Up @@ -68,7 +72,7 @@ def new_redis_instance
end

def register
@redis_url = "redis://#{@password}@#{@host}:#{@port}/#{@db}"
@redis_url = @path.nil? ? "redis://#{@password}@#{@host}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}"

@redis_builder ||= method(:internal_redis_builder)

Expand Down Expand Up @@ -114,13 +118,25 @@ def is_list_type?

# private
def redis_params
{
:host => @host,
:port => @port,
if @path.nil?
connectionParams = {
:host => @host,
:port => @port
}
else
@logger.warn("Parameter 'path' is set, ignoring parameters: 'host' and 'port'")
connectionParams = {
:path => @path
}
end

baseParams = {
:timeout => @timeout,
:db => @db,
:password => @password.nil? ? nil : @password.value
}

return connectionParams.merge(baseParams)
end

# private
Expand Down