Class: LogStash::Outputs::DatadogLogs::DatadogHTTPClient

Inherits:
DatadogClient
  • Object
show all
Defined in:
lib/logstash/outputs/datadog_logs.rb

Instance Method Summary collapse

Methods inherited from DatadogClient

#send_retries

Constructor Details

#initialize(logger, use_ssl, no_ssl_validation, host, port, use_compression, api_key) ⇒ DatadogHTTPClient

Returns a new instance of DatadogHTTPClient.



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/logstash/outputs/datadog_logs.rb', line 182

def initialize(logger, use_ssl, no_ssl_validation, host, port, use_compression, api_key)
  @logger = logger
  protocol = use_ssl ? "https" : "http"
  @url = "#{protocol}://#{host}:#{port.to_s}/v1/input/#{api_key}"
  @headers = {"Content-Type" => "application/json"}
  if use_compression
    @headers["Content-Encoding"] = "gzip"
  end
  logger.info("Starting HTTP connection to #{protocol}://#{host}:#{port.to_s} with compression " + (use_compression ? "enabled" : "disabled"))
  config = {}
  config[:ssl][:verify] = :disable if no_ssl_validation
  @client = Manticore::Client.new(config)
end

Instance Method Details

#closeObject



206
207
208
# File 'lib/logstash/outputs/datadog_logs.rb', line 206

def close
  @client.close
end

#send(payload) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/logstash/outputs/datadog_logs.rb', line 196

def send(payload)
  response = @client.post(@url, :body => payload, :headers => @headers).call
  if response.code >= 500
    raise RetryableError.new "Unable to send payload: #{response.code} #{response.body}"
  end
  if response.code >= 400
    @logger.error("Unable to send payload due to client error: #{response.code} #{response.body}")
  end
end