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 +5 -5
- data/README.md +7 -0
- data/bin/syslogstash +9 -3
- data/lib/syslogstash.rb +4 -0
- data/lib/syslogstash/logstash_writer.rb +45 -31
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f27f4b8bc47949fc01e4cfd9bcb596fdea9143516326e8eb4d129bc8e16b9897
|
4
|
+
data.tar.gz: 176a5842fcee9deb2acc965f5886ce2c36a71a6b8482d37179e63b12e50bf7b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
22
|
+
sig_w.print '1'
|
23
23
|
end
|
24
24
|
Signal.trap("USR2") do
|
25
|
-
|
25
|
+
sig_w.print '2'
|
26
26
|
end
|
27
27
|
Signal.trap("URG") do
|
28
|
-
|
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
@@ -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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
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.
|
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-
|
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.
|
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:
|