Class: Fluent::DatadogOutput::DatadogTCPClient

Inherits:
DatadogClient show all
Defined in:
lib/fluent/plugin/out_datadog.rb

Overview

TCP Datadog client

Instance Method Summary collapse

Methods inherited from DatadogClient

#send_retries

Constructor Details

#initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port) ⇒ DatadogTCPClient

Returns a new instance of DatadogTCPClient.



350
351
352
353
354
355
356
# File 'lib/fluent/plugin/out_datadog.rb', line 350

def initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port)
  @logger = logger
  @use_ssl = use_ssl
  @no_ssl_validation = no_ssl_validation
  @host = host
  @port = use_ssl ? ssl_port : port
end

Instance Method Details

#closeObject



386
387
388
# File 'lib/fluent/plugin/out_datadog.rb', line 386

def close
  @socket.close rescue nil
end

#connectObject



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/fluent/plugin/out_datadog.rb', line 358

def connect
  if @use_ssl
    @logger.info("Starting SSL connection #{@host} #{@port}")
    socket = TCPSocket.new @host, @port
    ssl_context = OpenSSL::SSL::SSLContext.new
    if @no_ssl_validation
      ssl_context.set_params({:verify_mode => OpenSSL::SSL::VERIFY_NONE})
    end
    ssl_context = OpenSSL::SSL::SSLSocket.new socket, ssl_context
    ssl_context.connect
    ssl_context
  else
    @logger.info("Starting plaintext connection #{@host} #{@port}")
    TCPSocket.new @host, @port
  end
end

#send(payload) ⇒ Object



375
376
377
378
379
380
381
382
383
384
# File 'lib/fluent/plugin/out_datadog.rb', line 375

def send(payload)
  begin
    @socket ||= connect
    @socket.puts(payload)
  rescue => e
    @socket.close rescue nil
    @socket = nil
    raise RetryableError.new "Unable to send payload: #{e.message}."
  end
end