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.



363
364
365
366
367
368
369
# File 'lib/fluent/plugin/out_datadog.rb', line 363

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



399
400
401
# File 'lib/fluent/plugin/out_datadog.rb', line 399

def close
  @socket.close rescue nil
end

#connectObject



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/fluent/plugin/out_datadog.rb', line 371

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



388
389
390
391
392
393
394
395
396
397
# File 'lib/fluent/plugin/out_datadog.rb', line 388

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