Class: LogStash::Outputs::Status
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Status
- Defined in:
- lib/logstash/outputs/status.rb
Constant Summary collapse
- REJECTED_HEADERS =
useless headers puma adds to the requests mostly due to rack compliance
['puma.socket', 'rack.hijack?', 'rack.hijack', 'rack.url_scheme', 'rack.after_reply', 'rack.version', 'rack.errors', 'rack.multithread', 'rack.multiprocess', 'rack.run_once', 'SCRIPT_NAME', 'QUERY_STRING', 'SERVER_PROTOCOL', 'SERVER_SOFTWARE', 'GATEWAY_INTERFACE']
- RESPONSE_HEADERS =
{ 'Content-Type' => 'application/json' }
Instance Attribute Summary collapse
-
#lastbeat ⇒ Object
Returns the value of attribute lastbeat.
Instance Method Summary collapse
Instance Attribute Details
#lastbeat ⇒ Object
Returns the value of attribute lastbeat.
14 15 16 |
# File 'lib/logstash/outputs/status.rb', line 14 def lastbeat @lastbeat end |
Instance Method Details
#close ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/logstash/outputs/status.rb', line 112 def close return unless @server @server.stop(true) @server.binder.close if @server.binder rescue IOError # do nothing end |
#receive(_event) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/logstash/outputs/status.rb', line 103 def receive(_event) 'Event received' @mutex.synchronize do @lastbeat = _event end end |
#register ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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 93 94 95 96 97 98 99 |
# File 'lib/logstash/outputs/status.rb', line 52 def register @mutex = Mutex.new @lastbeat = {} @server = ::Puma::Server.new(nil) # we'll set the rack handler later if @user && @password token = Base64.strict_encode64("#{@user}:#{@password.value}") @auth_token = "Basic #{token}" end if @ssl if @keystore.nil? || @keystore_password.nil? fail(LogStash::ConfigurationError, 'Settings :keystore and :keystore_password are required because :ssl is enabled.') end ctx = Puma::MiniSSL::Context.new ctx.keystore = @keystore ctx.keystore_pass = @keystore_password.value @server.add_ssl_listener(@host, @port, ctx) else @server.add_tcp_listener(@host, @port) end @server.min_threads = 0 @server.max_threads = @threads # proc needs to be defined at this context # to capture @codecs, @logger and lowercase_keys p = proc do |req| begin remote_host = req['puma.socket'].peeraddr[3] REJECTED_HEADERS.each { |k| req.delete(k) } body = req.delete('rack.input') last = @lastbeat.clone last['@delta'] = Time.new - last['@timestamp'].time ['200', RESPONSE_HEADERS, [last.to_json]] rescue => e @logger.error("unable to process event #{req.inspect}. exception => #{e.inspect}") ['500', RESPONSE_HEADERS, ['internal error']] end end auth = proc do |username, password| username == @user && password == @password.value end if @user && @password @server.app = Rack::Builder.new do use(Rack::Auth::Basic, &auth) if auth run(p) end @server.run end |