forked from logstash-plugins/logstash-input-lumberjack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lumberjack.rb
60 lines (47 loc) · 1.85 KB
/
lumberjack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# encoding: utf-8
require "logstash/inputs/base"
require "logstash/namespace"
# Receive events using the lumberjack protocol.
#
# This is mainly to receive events shipped with lumberjack[http://github.com/jordansissel/lumberjack],
# now represented primarily via the
# https://github.com/elasticsearch/logstash-forwarder[Logstash-forwarder].
#
class LogStash::Inputs::Lumberjack < LogStash::Inputs::Base
config_name "lumberjack"
default :codec, "plain"
# The IP address to listen on.
config :host, :validate => :string, :default => "0.0.0.0"
# The port to listen on.
config :port, :validate => :number, :required => true
# SSL certificate to use.
config :ssl_certificate, :validate => :path, :required => true
# SSL key to use.
config :ssl_key, :validate => :path, :required => true
# SSL key passphrase to use.
config :ssl_key_passphrase, :validate => :password
# The field name where the client IP address should be stored in each message
config :client_address_field, :validate => :string, :default => nil
# TODO(sissel): Add CA to authenticate clients with.
public
def register
require "lumberjack/server"
@logger.info("Starting lumberjack input listener", :address => "#{@host}:#{@port}")
@lumberjack = Lumberjack::Server.new(:address => @host, :port => @port,
:ssl_certificate => @ssl_certificate, :ssl_key => @ssl_key,
:ssl_key_passphrase => @ssl_key_passphrase)
end # def register
public
def run(output_queue)
@lumberjack.run do |l, client_address|
@codec.decode(l.delete("line")) do |event|
decorate(event)
if !@client_address_field.nil?
event[@client_address_field] = client_address
end
l.each { |k,v| event[k] = v; v.force_encoding(Encoding::UTF_8) }
output_queue << event
end
end
end # def run
end # class LogStash::Inputs::Lumberjack