Class: LogStash::Outputs::Dynatrace

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/dynatrace.rb

Overview

An output which sends logs to the Dynatrace log ingest v2 endpoint formatted as JSON

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



44
45
46
# File 'lib/logstash/outputs/dynatrace.rb', line 44

def uri
  @uri
end

Instance Method Details

#headersObject



64
65
66
67
68
69
70
# File 'lib/logstash/outputs/dynatrace.rb', line 64

def headers
  {
    'User-Agent' => "logstash-output-dynatrace v#{@plugin_version}",
    'Content-Type' => 'application/json; charset=utf-8',
    'Authorization' => "Api-Token #{@api_key}"
  }
end

#log_failure(message, opts) ⇒ Object

This is split into a separate method mostly to help testing



60
61
62
# File 'lib/logstash/outputs/dynatrace.rb', line 60

def log_failure(message, opts)
  @logger.error(message, opts)
end

#multi_receive(events) ⇒ Object

Takes an array of events



73
74
75
76
77
78
79
80
81
82
# File 'lib/logstash/outputs/dynatrace.rb', line 73

def multi_receive(events)
  return if events.length.zero?

  request = Net::HTTP::Post.new(uri, headers)
  request.body = "#{LogStash::Json.dump(events.map(&:to_hash)).chomp}\n"
  response = @client.request(request)
  return if response.is_a? Net::HTTPSuccess

  log_failure('Bad Response', request: request.inspect, response: response.inspect)
end

#registerObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/logstash/outputs/dynatrace.rb', line 46

def register
  require 'net/https'
  require 'uri'
  @uri = URI.parse(@ingest_endpoint_url.uri.to_s)
  @client = Net::HTTP.new(@uri.host, @uri.port)

  if uri.scheme == 'https'
    @client.use_ssl = true
    @client.verify_mode = OpenSSL::SSL::VERIFY_NONE if @ssl_verify_none
  end
  @logger.info('Client', client: @client.inspect)
end