Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to new shutdown semantics #21

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions lib/logstash/inputs/syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "logstash/filters/date"
require "logstash/inputs/base"
require "logstash/namespace"
require "stud/interval"

# Read syslog messages as events over the network.
#
Expand Down Expand Up @@ -65,7 +66,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,9 +116,9 @@ 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)
Stud.stoppable_sleep(5) { stop? }
retry
end
end
Expand All @@ -134,7 +134,7 @@ def udp_listener(output_queue)
@udp = UDPSocket.new(Socket::AF_INET)
@udp.bind(@host, @port)

while true
while !stop?
payload, client = @udp.recvfrom(9000)
decode(client[3], output_queue, payload)
end
Expand All @@ -151,12 +151,10 @@ def tcp_listener(output_queue)
@logger.info("Starting syslog tcp listener", :address => "#{@host}:#{@port}")
@tcp = TCPServer.new(@host, @port)

loop do
while !stop?
socket = @tcp.accept
@tcp_sockets << socket

break if @shutdown_requested.true?

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

public
def teardown
@shutdown_requested.make_true
def stop
close_udp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if close_udp and close_tcp are necessary here if they are in the close method? does it makes sense? why do we need them in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. will remove close entirely

close_tcp
finished
end

private
Expand Down
1 change: 1 addition & 0 deletions logstash-input-syslog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'concurrent-ruby'
s.add_runtime_dependency 'thread_safe'
s.add_runtime_dependency 'stud', '>= 0.0.22', '< 0.1.0'

s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'logstash-filter-grok'
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