syslogstash 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85063132d60f932f245cee23fe386113bd2a470b
4
- data.tar.gz: c4316c6c14830d325ee405dd30dabd26cd022071
3
+ metadata.gz: 0e2eed91a10f0ce2e5adede3c8639b37fc4becf3
4
+ data.tar.gz: b673ee85fcb7bfb6504aadf1941f27f1293dc1af
5
5
  SHA512:
6
- metadata.gz: 726a84230a8d06d8fd1889a4e3d915aa9b1e662657b1d7f460f969aae34a1c3e74bba0e80eb962793547ff2ca0b0930926cdad7528a010b42eb5d9581b191f45
7
- data.tar.gz: f4bbc3b3abfd71c74c05f5ba449081b8cff1c393f4862f94dcf00f156ac74ac5ba1cd4f8998aa4ea42d9bafdf3bf576e61d956e7eb1c15fbc6152e0cd00ac85a
6
+ metadata.gz: d02d4b1013baebd1aaccc6b11e1fcaf5f1afb4735e8fa272aef9246ec58c39e13ee963911795696264d5e3deaa5f2d5f0d80c9189f1275ba5bebbc6d2cc04fa1
7
+ data.tar.gz: b5f8d87359e5cf32a564db2d0966392deadb2038bbdc8bc55dc93921ab595b834947a114ba1390288ce7847c506af70b7ecd66ec47e396fc686bf1867d5de85c
data/lib/syslogstash.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'uri'
2
2
  require 'socket'
3
3
  require 'json'
4
+ require 'thwait'
4
5
 
5
6
  # Read syslog messages from one or more sockets, and send it to a logstash
6
7
  # server.
@@ -16,8 +17,27 @@ class Syslogstash
16
17
  @writer.run
17
18
  @readers.each { |w| w.run }
18
19
 
19
- @writer.wait
20
- @readers.each { |w| w.wait }
20
+ tw = ThreadsWait.new(@writer.thread, *(@readers.map { |r| r.thread }))
21
+
22
+ dead_thread = tw.next_wait
23
+
24
+ if dead_thread == @writer.thread
25
+ $stderr.puts "Writer thread crashed."
26
+ exit 1
27
+ else
28
+ reader = @readers.find { |r| r.thread == dead_thread }
29
+
30
+ $stderr.puts "Reader thread for #{reader.file} crashed."
31
+ end
32
+
33
+ begin
34
+ dead_thread.join
35
+ rescue Exception => ex
36
+ $stderr.puts "Exception in worker thread was: #{ex.message} (#{ex.class})"
37
+ $stderr.puts ex.backtrace.map { |l| " #{l}" }.join("\n")
38
+ end
39
+
40
+ exit 1
21
41
  end
22
42
  end
23
43
 
@@ -11,7 +11,7 @@ class Syslogstash::LogstashWriter
11
11
  # No messages will actually be *delivered*, though, until you call #run.
12
12
  #
13
13
  def initialize(servers, backlog)
14
- @servers, @backlog = servers.map { |s| URI(s) }, @backlog
14
+ @servers, @backlog = servers.map { |s| URI(s) }, backlog
15
15
 
16
16
  unless @servers.all? { |url| url.scheme == 'tcp' }
17
17
  raise ArgumentError,
@@ -5,8 +5,12 @@ require_relative 'worker'
5
5
  class Syslogstash::SyslogReader
6
6
  include Syslogstash::Worker
7
7
 
8
+ attr_reader :file
9
+
8
10
  def initialize(file, tags, logstash)
9
11
  @file, @tags, @logstash = file, tags, logstash
12
+
13
+ log { "initializing syslog socket #{file} with tags #{tags.inspect}" }
10
14
  end
11
15
 
12
16
  # Start reading from the socket file, parsing entries, and flinging
@@ -10,6 +10,10 @@ module Syslogstash::Worker
10
10
  end
11
11
  end
12
12
 
13
+ def thread
14
+ @worker
15
+ end
16
+
13
17
  # If you want to wait for a reader to die, here's how.
14
18
  #
15
19
  def wait
@@ -19,12 +23,12 @@ module Syslogstash::Worker
19
23
  private
20
24
 
21
25
  def log
22
- puts "#{Time.now.strftime("%F %T.%L")} #{self.class} #{yield.to_s}"
26
+ $stderr.puts "#{Time.now.strftime("%F %T.%L")} #{self.class} #{yield.to_s}"
23
27
  end
24
28
 
25
29
  def debug
26
30
  if ENV['DEBUG_SYSLOGSTASH']
27
- puts "#{Time.now.strftime("%F %T.%L")} #{self.class} #{yield.to_s}"
31
+ $stderr.puts "#{Time.now.strftime("%F %T.%L")} #{self.class} #{yield.to_s}"
28
32
  end
29
33
  end
30
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syslogstash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler