Sha256: 67af411f5bcf7c3afc560b8c429305474322c1599750d5fd0a30e1dd2f21d555

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'uri'
require 'socket'
require 'json'
require 'thwait'

# Read syslog messages from one or more sockets, and send it to a logstash
# server.
#
class Syslogstash
	def initialize(sockets, servers, backlog)
		@writer = LogstashWriter.new(servers, backlog)

		@readers = sockets.map { |f, tags| SyslogReader.new(f, tags, @writer) }
	end

	def run
		@writer.run
		@readers.each { |w| w.run }

		tw = ThreadsWait.new(@writer.thread, *(@readers.map { |r| r.thread }))

		dead_thread = tw.next_wait

		if dead_thread == @writer.thread
			$stderr.puts "Writer thread crashed."
			exit 1
		else
			reader = @readers.find { |r| r.thread == dead_thread }

			$stderr.puts "Reader thread for #{reader.file} crashed."
		end

		begin
			dead_thread.join
		rescue Exception => ex
			$stderr.puts "Exception in worker thread was: #{ex.message} (#{ex.class})"
			$stderr.puts ex.backtrace.map { |l| "  #{l}" }.join("\n")
		end

		exit 1
	end
end

require_relative 'syslogstash/syslog_reader'
require_relative 'syslogstash/logstash_writer'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
syslogstash-0.3.0 lib/syslogstash.rb