syslogstash 2.1.0 → 2.2.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
- SHA1:
3
- metadata.gz: 8dd70d42345ffba77d56d3511d5220e2ab399ce9
4
- data.tar.gz: 98f6175cd0cc98d9ca6a51593657b7e3c09f178c
2
+ SHA256:
3
+ metadata.gz: f27f4b8bc47949fc01e4cfd9bcb596fdea9143516326e8eb4d129bc8e16b9897
4
+ data.tar.gz: 176a5842fcee9deb2acc965f5886ce2c36a71a6b8482d37179e63b12e50bf7b1
5
5
  SHA512:
6
- metadata.gz: 9fe1db70bce8d062dbc84b3c24e5650ed489b9ff89f7502225b2673f848e3c4abde63d6369cd14b3235f1adb9bfb15ceb8b217eaf4392a52badbfdd906ecbf03
7
- data.tar.gz: 1e4163fa6ccd9c6f6402be87d571f1d67e80584935e7a7772084f3c3dc968f321acbdd0f2ecf7065f9b5f295825d2dd9f997189f7866cd0b9847dc03152a3224
6
+ metadata.gz: ad2ebf46bfcc956a0cc88f67bd651856843aed2ca7b4714cc275951a4dd8443d4c674d50dc0b302ed0a50357fdbf4f444acce710b92d02b0cc1b8cec9279d4d1
7
+ data.tar.gz: a154a28707c4120e0ea4ff920f76557beaa103d52d6121db3973f6a52d819ee8a83bb3e396ab68f536424c8182e4842756131dbfe595d2a3260c7ed42b38c749
data/README.md CHANGED
@@ -85,6 +85,13 @@ aspects of runtime operation. They are:
85
85
  * **`SIGURG`** -- toggle whether or not relaying to stdout is enabled or
86
86
  disabled.
87
87
 
88
+ * **`SIGHUP`** -- pretend that the currently in-use logstash server has
89
+ failed, and trigger the random-server-selection logic to (potentially)
90
+ pick a new server. Useful if you want to make sure that syslogstash
91
+ won't drop *any* messages when retiring a logstash server -- just remove
92
+ the logstash server from DNS, then SIGHUP syslogstash to make it switch
93
+ to another server.
94
+
88
95
 
89
96
  ## Use with Docker
90
97
 
data/bin/syslogstash CHANGED
@@ -19,13 +19,16 @@ syslogstash = Syslogstash.new(cfg)
19
19
  sig_r, sig_w = IO.pipe
20
20
 
21
21
  Signal.trap("USR1") do
22
- sig_w.print '1'
22
+ sig_w.print '1'
23
23
  end
24
24
  Signal.trap("USR2") do
25
- sig_w.print '2'
25
+ sig_w.print '2'
26
26
  end
27
27
  Signal.trap("URG") do
28
- sig_w.print 'U'
28
+ sig_w.print 'U'
29
+ end
30
+ Signal.trap("HUP") do
31
+ sig_w.print 'H'
29
32
  end
30
33
 
31
34
  Thread.new do
@@ -41,6 +44,9 @@ Thread.new do
41
44
  elsif c == 'U'
42
45
  cfg.relay_to_stdout = !cfg.relay_to_stdout
43
46
  logger.info("SignalHandler") { "Received SIGURG; Relaying to stdout is now #{cfg.relay_to_stdout ? "enabled" : "disabled"}" }
47
+ elsif c== 'H'
48
+ logger.info("SignalHandler") { "Received SIGHUP" }
49
+ syslogstash.force_disconnect!
44
50
  else
45
51
  logger.error("SignalHandler") { "Got an unrecognised character from signal pipe: #{c.inspect}" }
46
52
  end
data/lib/syslogstash.rb CHANGED
@@ -43,6 +43,10 @@ class Syslogstash
43
43
 
44
44
  exit 1
45
45
  end
46
+
47
+ def force_disconnect!
48
+ @writer.force_disconnect!
49
+ end
46
50
  end
47
51
 
48
52
  require_relative 'syslogstash/config'
@@ -19,6 +19,7 @@ class Syslogstash::LogstashWriter
19
19
 
20
20
  @entries = []
21
21
  @entries_mutex = Mutex.new
22
+ @cs_mutex = Mutex.new
22
23
  end
23
24
 
24
25
  # Add an entry to the list of messages to be sent to logstash. Actual
@@ -45,6 +46,16 @@ class Syslogstash::LogstashWriter
45
46
  @thread = Thread.new { send_messages }
46
47
  end
47
48
 
49
+ # Cause the writer to disconnect from the currently-active server.
50
+ #
51
+ def force_disconnect!
52
+ @cs_mutex.synchronize do
53
+ @logger.info("writer") { "Forced disconnect from #{server_id(@current_server) }" }
54
+ @current_server.close if @current_server
55
+ @current_server = nil
56
+ end
57
+ end
58
+
48
59
  private
49
60
 
50
61
  def send_messages
@@ -87,38 +98,41 @@ class Syslogstash::LogstashWriter
87
98
  done = false
88
99
 
89
100
  until done
90
- if @current_server
91
- begin
92
- @logger.debug("writer") { "Using current server #{server_id(@current_server)}" }
93
- yield @current_server
94
- done = true
95
- rescue SystemCallError => ex
96
- # Something went wrong during the send; disconnect from this
97
- # server and recycle
98
- @logger.debug("writer") { "Error while writing to current server: #{ex.message} (#{ex.class})" }
99
- @current_server.close
100
- @current_server = nil
101
- sleep 0.1
102
- end
103
- else
104
- candidates = resolve_server_name
105
-
106
- begin
107
- next_server = candidates.shift
108
-
109
- if next_server
110
- @logger.debug("writer") { "Trying to connect to #{next_server.to_s}" }
111
- @current_server = TCPSocket.new(next_server.hostname, next_server.port)
112
- else
113
- @logger.debug("writer") { "Could not connect to any server; pausing before trying again" }
101
+ @cs_mutex.synchronize do
102
+ if @current_server
103
+ begin
104
+ @logger.debug("writer") { "Using current server #{server_id(@current_server)}" }
105
+ yield @current_server
106
+ done = true
107
+ rescue SystemCallError => ex
108
+ # Something went wrong during the send; disconnect from this
109
+ # server and recycle
110
+ @logger.debug("writer") { "Error while writing to current server: #{ex.message} (#{ex.class})" }
111
+ @current_server.close
114
112
  @current_server = nil
115
- sleep 5
113
+ sleep 0.1
114
+ end
115
+ else
116
+ candidates = resolve_server_name
117
+ @logger.debug("writer") { "Server candidates: #{candidates.inspect}" }
118
+
119
+ begin
120
+ next_server = candidates.shift
121
+
122
+ if next_server
123
+ @logger.debug("writer") { "Trying to connect to #{next_server.to_s}" }
124
+ @current_server = TCPSocket.new(next_server.hostname, next_server.port)
125
+ else
126
+ @logger.debug("writer") { "Could not connect to any server; pausing before trying again" }
127
+ @current_server = nil
128
+ sleep 5
129
+ end
130
+ rescue SystemCallError => ex
131
+ # Connection failed for any number of reasons; try the next one in the list
132
+ @logger.warn("writer") { "Failed to connect to #{next_server.to_s}: #{ex.message} (#{ex.class})" }
133
+ sleep 0.1
134
+ retry
116
135
  end
117
- rescue SystemCallError => ex
118
- # Connection failed for any number of reasons; try the next one in the list
119
- @logger.warn("writer") { "Failed to connect to #{next_server.to_s}: #{ex.message} (#{ex.class})" }
120
- sleep 0.1
121
- retry
122
136
  end
123
137
  end
124
138
  end
@@ -145,7 +159,7 @@ class Syslogstash::LogstashWriter
145
159
  if addrs.empty?
146
160
  @logger.warn("writer") { "No addresses resolved for server_name #{host.inspect}" }
147
161
  end
148
- addrs.map { |a| Target.new(a.to_s, port.to_i) }
162
+ addrs.sort_by { rand }.map { |a| Target.new(a.to_s, port.to_i) }
149
163
  else
150
164
  # SRV records ftw
151
165
  [].tap do |list|
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: 2.1.0
4
+ version: 2.2.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: 2018-04-21 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: frankenstein
@@ -223,9 +223,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  version: '0'
224
224
  requirements: []
225
225
  rubyforge_project:
226
- rubygems_version: 2.6.13
226
+ rubygems_version: 2.7.7
227
227
  signing_key:
228
228
  specification_version: 4
229
229
  summary: Send messages from syslog UNIX sockets to logstash
230
230
  test_files: []
231
- has_rdoc: