Class: LogStash::Outputs::LogmaticHttpBatch

Inherits:
Base
  • Object
show all
Includes:
Stud::Buffer
Defined in:
lib/logstash/outputs/logmatic_https.rb

Overview

Ship log from logstash straight to Logmatic

To use this you will need a valid Logmatic API Key

Instance Method Summary collapse

Instance Method Details

#flush(events, final = false) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/logstash/outputs/logmatic_https.rb', line 53

def flush(events, final=false)
  # Send the event over http.
  request = Net::HTTP::Post.new(@uri.path)
  request.body = events.inspect
  request.add_field("Content-Type", 'application/json')
  response = @client.request(request)
  if response.is_a?(Net::HTTPSuccess)
    @logger.debug("Event sent to Logmatic OK!")
  else
    @logger.warn("HTTP error", :error => response.error!)
  end
end

#receive(event) ⇒ Object



47
48
49
50
# File 'lib/logstash/outputs/logmatic_https.rb', line 47

def receive(event)
  return unless output?(event)
  buffer_receive(event.to_json)
end

#registerObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/logstash/outputs/logmatic_https.rb', line 29

def register
  require "net/https"
  require "uri"
  @url = "https://api.logmatic.io/v1/input/#{@key}"
  @uri = URI.parse(@url)
  @client = Net::HTTP.new(@uri.host, @uri.port)
  @client.use_ssl = true
  @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
  @logger.debug("Logmatic URL", :url => @url)

  buffer_initialize(
    :max_items => @queue_size,
    :max_interval => @timeframe,
    :logger => @logger
  )
end