Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.

This cleans up the structure of protocol instance settings methods #13

Closed
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
68 changes: 36 additions & 32 deletions lib/logstash/outputs/elasticsearch_java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,50 +308,19 @@ def register
raise LogStash::ConfigurationError, "network_host MUST be set if the 'node' protocol is in use! If this is set incorrectly Logstash will hang attempting to connect!"
end

client_settings = {}
client_settings["cluster.name"] = @cluster if @cluster
client_settings["network.host"] = @network_host if @network_host
client_settings["transport.tcp.port"] = @transport_tcp_port if @transport_tcp_port
client_settings["client.transport.sniff"] = @sniffing

if @node_name
client_settings["node.name"] = @node_name
else
client_settings["node.name"] = "logstash-#{Socket.gethostname}-#{$$}-#{object_id}"
end

@@plugins.each do |plugin|
name = plugin.name.split('-')[-1]
client_settings.merge!(LogStash::Outputs::ElasticSearchJava.const_get(name.capitalize).create_client_config(self))
end

if (@hosts.nil? || @hosts.empty?) && @protocol != "node" # node can use zen discovery
@logger.info("No 'hosts' set in elasticsearch output. Defaulting to localhost")
@hosts = ["localhost"]
end

common_options = {
:protocol => @protocol,
:client_settings => client_settings,
:hosts => @hosts,
:port => @port
}

# Update API setup
update_options = {
:upsert => @upsert,
:doc_as_upsert => @doc_as_upsert
}
common_options.merge! update_options if @action == 'update'

client_class = case @protocol
when "transport"
LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::TransportClient
when "node"
LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient
end

@client = client_class.new(common_options)
@client = client_class.new(client_options)

if @manage_template
begin
Expand Down Expand Up @@ -389,6 +358,41 @@ def register
end
end # def register

def client_options
client_settings = {}
client_settings["cluster.name"] = @cluster if @cluster
client_settings["network.host"] = @network_host if @network_host
client_settings["transport.tcp.port"] = @transport_tcp_port if @transport_tcp_port
client_settings["client.transport.sniff"] = @sniffing

if @node_name
client_settings["node.name"] = @node_name
else
client_settings["node.name"] = "logstash-#{Socket.gethostname}-#{$$}-#{object_id}"
end

@@plugins.each do |plugin|
name = plugin.name.split('-')[-1]
client_settings.merge!(LogStash::Outputs::ElasticSearchJava.const_get(name.capitalize).create_client_config(self))
end

common_options = {
:protocol => @protocol,
:client_settings => client_settings,
:hosts => @hosts,
:port => @port
}

# Update API setup
update_options = {
:upsert => @upsert,
:doc_as_upsert => @doc_as_upsert
}
common_options.merge! update_options if @action == 'update'

common_options
end


public
def get_template
Expand Down
2 changes: 1 addition & 1 deletion logstash-output-elasticsearch_java.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-output-elasticsearch_java'
s.version = '2.0.0.beta7'
s.version = '2.0.0.beta8'
s.licenses = ['apache-2.0']
s.summary = "Logstash Output to Elasticsearch using Java node/transport client"
s.description = "Output events to elasticsearch using the java client"
Expand Down