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.



335
336
337
338
339
340
341
# File 'lib/fluent/plugin/out_datadog.rb', line 335

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



371
372
373
# File 'lib/fluent/plugin/out_datadog.rb', line 371

def close
  @socket.close rescue nil
end

#connectObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/fluent/plugin/out_datadog.rb', line 343

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



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

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