Class: LogStash::Outputs::Loggly

Inherits:
Base show all
Defined in:
lib/logstash/outputs/loggly.rb

Overview

Got a loggly account? Use logstash to ship logs to Loggly!

This is most useful so you can use logstash to parse and structure your logs and ship structured, json events to your account at Loggly.

To use this, you’ll need to use a Loggly input with type ‘http’ and ‘json logging’ enabled.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#receive(event) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/logstash/outputs/loggly.rb', line 68

def receive(event)
  return unless output?(event)

  if event == LogStash::SHUTDOWN
    finished
    return
  end

  # Send the event over http.
  url = URI.parse("#{@proto}://#{@host}/inputs/#{event.sprintf(@key)}")
  @logger.info("Loggly URL", :url => url)
  http = Net::HTTP::Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_password.value).new(url.host, url.port)
  if url.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  request = Net::HTTP::Post.new(url.path)
  request.body = event.to_json
  response = http.request(request)
  if response.is_a?(Net::HTTPSuccess)
    @logger.info("Event send to Loggly OK!")
  else
    @logger.warn("HTTP error", :error => response.error!)
  end
end

#registerObject



63
64
65
# File 'lib/logstash/outputs/loggly.rb', line 63

def register
  # nothing to do
end