Class: LogStash::Outputs::Dynatrace
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Dynatrace
- 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
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #headers ⇒ Object
-
#log_failure(message, opts) ⇒ Object
This is split into a separate method mostly to help testing.
-
#multi_receive(events) ⇒ Object
Takes an array of events.
- #register ⇒ Object
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
44 45 46 |
# File 'lib/logstash/outputs/dynatrace.rb', line 44 def uri @uri end |
Instance Method Details
#headers ⇒ Object
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(, opts) @logger.error(, 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 |
#register ⇒ Object
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 |