Skip to content

Commit

Permalink
update to new shutdown semantics
Browse files Browse the repository at this point in the history
Fixes #20.
  • Loading branch information
talevy committed Sep 17, 2015
1 parent 0ea3c8e commit 57ba2c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 11 additions & 6 deletions lib/logstash/inputs/syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class LogStash::Inputs::Syslog < LogStash::Inputs::Base
public
def initialize(params)
super
@shutdown_requested = Concurrent::AtomicBoolean.new(false)
BasicSocket.do_not_reverse_lookup = true
end # def initialize

Expand Down Expand Up @@ -116,7 +115,7 @@ def run(output_queue)
def server(protocol, output_queue)
self.send("#{protocol}_listener", output_queue)
rescue => e
if @shutdown_requested.false?
if !stop?
@logger.warn("syslog listener died", :protocol => protocol, :address => "#{@host}:#{@port}", :exception => e, :backtrace => e.backtrace)
sleep(5)
retry
Expand Down Expand Up @@ -155,7 +154,7 @@ def tcp_listener(output_queue)
socket = @tcp.accept
@tcp_sockets << socket

break if @shutdown_requested.true?
break if stop?

Thread.new(output_queue, socket) do |output_queue, socket|
tcp_receiver(output_queue, socket)
Expand Down Expand Up @@ -194,11 +193,17 @@ def decode(host, output_queue, data)
end

public
def teardown
@shutdown_requested.make_true
def close
super
close_udp
close_tcp
end

public
def stop
super
close_udp
close_tcp
finished
end

private
Expand Down
9 changes: 6 additions & 3 deletions spec/inputs/syslog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require "stud/try"
require "socket"

describe "inputs/syslog" do
describe LogStash::Inputs::Syslog do
SYSLOG_LINE = "<164>Oct 26 15:19:25 1.2.3.4 %ASA-4-106023: Deny udp src DRAC:10.1.2.3/43434 dst outside:192.168.0.1/53 by access-group \"acl_drac\" [0x0, 0x0]"

it "should properly handle priority, severity and facilities" do
Expand Down Expand Up @@ -139,7 +139,7 @@
input.syslog_relay(syslog_event)
insist { syslog_event["@timestamp"].to_iso8601 } == "#{Time.now.year}-10-26T20:19:25.000Z"

input.teardown
input.close
end

it "should add unique tag when grok parsing fails" do
Expand All @@ -157,7 +157,10 @@
insist { syslog_event["severity"] } == 4
insist { syslog_event["tags"] } == nil

input.teardown
input.close
end

it_behaves_like 'an interruptible input plugin' do
let(:config) { { "port" => 5511 } }
end
end

0 comments on commit 57ba2c3

Please sign in to comment.