@@ -308,50 +308,19 @@ def register
308
308
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!"
309
309
end
310
310
311
- client_settings = { }
312
- client_settings [ "cluster.name" ] = @cluster if @cluster
313
- client_settings [ "network.host" ] = @network_host if @network_host
314
- client_settings [ "transport.tcp.port" ] = @transport_tcp_port if @transport_tcp_port
315
- client_settings [ "client.transport.sniff" ] = @sniffing
316
-
317
- if @node_name
318
- client_settings [ "node.name" ] = @node_name
319
- else
320
- client_settings [ "node.name" ] = "logstash-#{ Socket . gethostname } -#{ $$} -#{ object_id } "
321
- end
322
-
323
- @@plugins . each do |plugin |
324
- name = plugin . name . split ( '-' ) [ -1 ]
325
- client_settings . merge! ( LogStash ::Outputs ::ElasticSearchJava . const_get ( name . capitalize ) . create_client_config ( self ) )
326
- end
327
-
328
311
if ( @hosts . nil? || @hosts . empty? ) && @protocol != "node" # node can use zen discovery
329
312
@logger . info ( "No 'hosts' set in elasticsearch output. Defaulting to localhost" )
330
313
@hosts = [ "localhost" ]
331
314
end
332
315
333
- common_options = {
334
- :protocol => @protocol ,
335
- :client_settings => client_settings ,
336
- :hosts => @hosts ,
337
- :port => @port
338
- }
339
-
340
- # Update API setup
341
- update_options = {
342
- :upsert => @upsert ,
343
- :doc_as_upsert => @doc_as_upsert
344
- }
345
- common_options . merge! update_options if @action == 'update'
346
-
347
316
client_class = case @protocol
348
317
when "transport"
349
318
LogStash ::Outputs ::ElasticSearchJavaPlugins ::Protocols ::TransportClient
350
319
when "node"
351
320
LogStash ::Outputs ::ElasticSearchJavaPlugins ::Protocols ::NodeClient
352
321
end
353
322
354
- @client = client_class . new ( common_options )
323
+ @client = client_class . new ( client_options )
355
324
356
325
if @manage_template
357
326
begin
@@ -389,6 +358,41 @@ def register
389
358
end
390
359
end # def register
391
360
361
+ def client_options
362
+ client_settings = { }
363
+ client_settings [ "cluster.name" ] = @cluster if @cluster
364
+ client_settings [ "network.host" ] = @network_host if @network_host
365
+ client_settings [ "transport.tcp.port" ] = @transport_tcp_port if @transport_tcp_port
366
+ client_settings [ "client.transport.sniff" ] = @sniffing
367
+
368
+ if @node_name
369
+ client_settings [ "node.name" ] = @node_name
370
+ else
371
+ client_settings [ "node.name" ] = "logstash-#{ Socket . gethostname } -#{ $$} -#{ object_id } "
372
+ end
373
+
374
+ @@plugins . each do |plugin |
375
+ name = plugin . name . split ( '-' ) [ -1 ]
376
+ client_settings . merge! ( LogStash ::Outputs ::ElasticSearchJava . const_get ( name . capitalize ) . create_client_config ( self ) )
377
+ end
378
+
379
+ common_options = {
380
+ :protocol => @protocol ,
381
+ :client_settings => client_settings ,
382
+ :hosts => @hosts ,
383
+ :port => @port
384
+ }
385
+
386
+ # Update API setup
387
+ update_options = {
388
+ :upsert => @upsert ,
389
+ :doc_as_upsert => @doc_as_upsert
390
+ }
391
+ common_options . merge! update_options if @action == 'update'
392
+
393
+ common_options
394
+ end
395
+
392
396
393
397
public
394
398
def get_template
0 commit comments