diff --git a/lib/logstash/inputs/syslog.rb b/lib/logstash/inputs/syslog.rb index c689755..6f49dc3 100644 --- a/lib/logstash/inputs/syslog.rb +++ b/lib/logstash/inputs/syslog.rb @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/spec/inputs/syslog_spec.rb b/spec/inputs/syslog_spec.rb index 1c24191..3c9e69b 100644 --- a/spec/inputs/syslog_spec.rb +++ b/spec/inputs/syslog_spec.rb @@ -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 @@ -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 @@ -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