Skip to content

Commit

Permalink
add ssl/auth options
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
jsvd authored and jordansissel committed Nov 7, 2014
1 parent f02ff62 commit d1d084e
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lib/logstash/filters/elasticsearch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "logstash/filters/base"
require "logstash/namespace"
require "logstash/util/fieldreference"
require "base64"


# Search elasticsearch for a previous log event and copy some fields from it
Expand Down Expand Up @@ -44,12 +45,42 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
# Hash of fields to copy from old event (found via elasticsearch) into new event
config :fields, :validate => :hash, :default => {}

# Basic Auth - username
config :user, :validate => :string

# Basic Auth - password
config :password, :validate => :password

# SSL
config :ssl, :validate => :boolean, :default => false

# SSL Certificate Authority file
config :ca_file, :validate => :path


public
def register
require "elasticsearch"

@logger.info("New ElasticSearch filter", :hosts => @hosts)
@client = Elasticsearch::Client.new hosts: @hosts
transport_options = {}

if @user && @password
token = Base64.strict_encode64("#{@user}:#{@password.value}")
transport_options[:headers] = { Authorization: "Basic #{token}" }
end

hosts = if @ssl then
@hosts.map {|h| { host: h, scheme: 'https' } }
else
@hosts
end

if @ssl && @ca_file
transport_options[:ssl] = { ca_file: @ca_file }
end

@logger.info("New ElasticSearch filter", :hosts => hosts)
@client = Elasticsearch::Client.new hosts: hosts, transport_options: transport_options
end # def register

public
Expand Down

0 comments on commit d1d084e

Please sign in to comment.