remote_syslog 1.6.8 → 1.6.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -5
- data/examples/remote_syslog.init.d +2 -2
- data/lib/remote_syslog.rb +1 -1
- data/lib/remote_syslog/agent.rb +19 -0
- data/lib/remote_syslog/cli.rb +5 -2
- data/lib/remote_syslog/tcp_endpoint.rb +87 -0
- data/remote_syslog.gemspec +3 -2
- metadata +4 -3
data/README.md
CHANGED
@@ -48,6 +48,7 @@ specified as command-line arguments (below).
|
|
48
48
|
-s, --severity SEVERITY Severity (notice)
|
49
49
|
--strip-color Strip color codes
|
50
50
|
--tls Connect via TCP with TLS
|
51
|
+
--tcp Connect via TCP (no TLS)
|
51
52
|
--new-file-check-interval INTERVAL
|
52
53
|
Time between checks for new files
|
53
54
|
|
@@ -78,9 +79,9 @@ well as the file `/var/log/mysqld.log`. Send to port `logs.papertrailapp.com:123
|
|
78
79
|
|
79
80
|
Stay attached to the terminal, look for and use `/etc/log_files.yml` if it
|
80
81
|
exists, write PID to `/tmp/remote_syslog.pid`, and send with facility local0
|
81
|
-
to `a.
|
82
|
+
to `a.example.com:514`:
|
82
83
|
|
83
|
-
$ remote_syslog -D -d a.
|
84
|
+
$ remote_syslog -D -d a.example.com -f local0 --pid-file /tmp/remote_syslog.pid /var/log/mysqld.log
|
84
85
|
|
85
86
|
### Windows
|
86
87
|
|
@@ -190,10 +191,10 @@ matched.
|
|
190
191
|
Run multiple instances to support more than one message-specific file format
|
191
192
|
or to specify unique syslog hostnames.
|
192
193
|
|
193
|
-
To do that, provide an alternate PID
|
194
|
-
|
194
|
+
To do that, provide an alternate PID path as a command-line option to the
|
195
|
+
additional instance(s). For example:
|
195
196
|
|
196
|
-
--pid-file remote_syslog_2.pid
|
197
|
+
--pid-file /var/run/remote_syslog_2.pid
|
197
198
|
|
198
199
|
|
199
200
|
### Parse fields from log messages
|
@@ -13,7 +13,7 @@ prog="remote_syslog"
|
|
13
13
|
config="/etc/log_files.yml"
|
14
14
|
pid_dir="/var/run"
|
15
15
|
|
16
|
-
EXTRAOPTIONS=""
|
16
|
+
EXTRAOPTIONS="--tls"
|
17
17
|
|
18
18
|
pid_file="$pid_dir/$prog.pid"
|
19
19
|
|
@@ -29,7 +29,7 @@ start(){
|
|
29
29
|
echo -n $"Starting $prog: "
|
30
30
|
|
31
31
|
unset HOME MAIL USER USERNAME
|
32
|
-
$prog -c $config -
|
32
|
+
$prog -c $config --pid-file $pid_file "$EXTRAOPTIONS"
|
33
33
|
RETVAL=$?
|
34
34
|
echo
|
35
35
|
return $RETVAL
|
data/lib/remote_syslog.rb
CHANGED
data/lib/remote_syslog/agent.rb
CHANGED
@@ -7,12 +7,16 @@ require 'remote_syslog/glob_watch'
|
|
7
7
|
require 'remote_syslog/message_generator'
|
8
8
|
require 'remote_syslog/udp_endpoint'
|
9
9
|
require 'remote_syslog/tls_endpoint'
|
10
|
+
require 'remote_syslog/tcp_endpoint'
|
10
11
|
|
11
12
|
module RemoteSyslog
|
12
13
|
class Agent < Servolux::Server
|
13
14
|
# Who should we connect to?
|
14
15
|
attr_accessor :destination_host, :destination_port
|
15
16
|
|
17
|
+
# Should use TCP?
|
18
|
+
attr_accessor :tcp
|
19
|
+
|
16
20
|
# Should use TLS?
|
17
21
|
attr_accessor :tls
|
18
22
|
|
@@ -99,6 +103,11 @@ module RemoteSyslog
|
|
99
103
|
:client_private_key => @client_private_key,
|
100
104
|
:server_cert => @server_cert,
|
101
105
|
:logger => logger)
|
106
|
+
elsif @tcp
|
107
|
+
max_message_size = 20480
|
108
|
+
|
109
|
+
connection = TcpEndpoint.new(@destination_host, @destination_port,
|
110
|
+
:logger => logger)
|
102
111
|
else
|
103
112
|
max_message_size = 1024
|
104
113
|
connection = UdpEndpoint.new(@destination_host, @destination_port,
|
@@ -118,6 +127,16 @@ module RemoteSyslog
|
|
118
127
|
end
|
119
128
|
end
|
120
129
|
|
130
|
+
def endpoint_mode
|
131
|
+
@endpoint_mode ||= if @tls
|
132
|
+
'TCP/TLS'
|
133
|
+
elsif @tcp
|
134
|
+
'TCP'
|
135
|
+
else
|
136
|
+
'UDP'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
121
140
|
def before_stopping
|
122
141
|
EM.stop
|
123
142
|
end
|
data/lib/remote_syslog/cli.rb
CHANGED
@@ -101,6 +101,9 @@ module RemoteSyslog
|
|
101
101
|
opts.on("--strip-color", "Strip color codes") do
|
102
102
|
@agent.strip_color = true
|
103
103
|
end
|
104
|
+
opts.on("--tcp", "Connect via TCP (no TLS)") do
|
105
|
+
@agent.tcp = true
|
106
|
+
end
|
104
107
|
opts.on("--tls", "Connect via TCP with TLS") do
|
105
108
|
@agent.tls = true
|
106
109
|
end
|
@@ -246,7 +249,7 @@ module RemoteSyslog
|
|
246
249
|
end
|
247
250
|
|
248
251
|
if @no_detach
|
249
|
-
puts "Watching #{@agent.files.length} files/globs. Sending to #{@agent.destination_host}:#{@agent.destination_port} (#{@agent.
|
252
|
+
puts "Watching #{@agent.files.length} files/globs. Sending to #{@agent.destination_host}:#{@agent.destination_port} (#{@agent.endpoint_mode})."
|
250
253
|
@agent.run
|
251
254
|
else
|
252
255
|
daemon = Servolux::Daemon.new(:server => @agent, :after_fork => method(:redirect_io))
|
@@ -255,7 +258,7 @@ module RemoteSyslog
|
|
255
258
|
error "Already running at #{@agent.pid_file}. To run another instance, specify a different `--pid-file`.", true
|
256
259
|
end
|
257
260
|
|
258
|
-
puts "Watching #{@agent.files.length} files/globs. Sending to #{@agent.destination_host}:#{@agent.destination_port} (#{@agent.
|
261
|
+
puts "Watching #{@agent.files.length} files/globs. Sending to #{@agent.destination_host}:#{@agent.destination_port} (#{@agent.endpoint_mode})."
|
259
262
|
daemon.startup
|
260
263
|
end
|
261
264
|
rescue Servolux::Daemon::StartupError => e
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module RemoteSyslog
|
4
|
+
# Additional class that uses TCP but no TLS. Has the benefit of a greater max packet size
|
5
|
+
class TcpEndpoint
|
6
|
+
class Handler < EventMachine::Connection
|
7
|
+
def initialize(endpoint)
|
8
|
+
@endpoint = endpoint
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def connection_completed
|
13
|
+
@endpoint.connection = self
|
14
|
+
end
|
15
|
+
|
16
|
+
def unbind
|
17
|
+
@endpoint.unbind
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :connection
|
22
|
+
|
23
|
+
attr_reader :logger
|
24
|
+
|
25
|
+
def initialize(address, port, options = {})
|
26
|
+
@address = address
|
27
|
+
@port = port.to_i
|
28
|
+
@queue_limit = options[:queue_limit] || 10_000
|
29
|
+
@logger = options[:logger] || Logger.new(STDERR)
|
30
|
+
|
31
|
+
# Try to resolve the address
|
32
|
+
resolve_address
|
33
|
+
|
34
|
+
# Every 60 seconds we'll see if the address has changed
|
35
|
+
EventMachine.add_periodic_timer(60) do
|
36
|
+
resolve_address
|
37
|
+
end
|
38
|
+
|
39
|
+
connect
|
40
|
+
end
|
41
|
+
|
42
|
+
def connection=(conn)
|
43
|
+
port, ip = Socket.unpack_sockaddr_in(conn.get_peername)
|
44
|
+
logger.debug "Connected to #{ip}:#{port}"
|
45
|
+
@connection = conn
|
46
|
+
end
|
47
|
+
|
48
|
+
def resolve_address
|
49
|
+
request = EventMachine::DnsResolver.resolve(@address)
|
50
|
+
request.callback do |addrs|
|
51
|
+
@cached_ip = addrs.first
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def address
|
56
|
+
@cached_ip || @address
|
57
|
+
end
|
58
|
+
|
59
|
+
def connect
|
60
|
+
logger.debug "Connecting to #{address}:#{@port}"
|
61
|
+
EventMachine.connect(address, @port, TcpEndpoint::Handler, self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def unbind
|
65
|
+
@connection = nil
|
66
|
+
|
67
|
+
EventMachine.add_timer(1) do
|
68
|
+
connect
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def write(value)
|
73
|
+
if @connection
|
74
|
+
if @queue
|
75
|
+
@connection.send_data(@queue.join("\n") + "\n")
|
76
|
+
@queue = nil
|
77
|
+
end
|
78
|
+
@connection.send_data(value + "\n")
|
79
|
+
else
|
80
|
+
(@queue ||= []) << value
|
81
|
+
|
82
|
+
# Make sure our queue does not get to be too big
|
83
|
+
@queue.shift if @queue.length > @queue_limit
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/remote_syslog.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
## If your rubyforge_project name is different, then edit it and comment out
|
9
9
|
## the sub! line in the Rakefile
|
10
10
|
s.name = 'remote_syslog'
|
11
|
-
s.version = '1.6.
|
12
|
-
s.date = '2012-
|
11
|
+
s.version = '1.6.9'
|
12
|
+
s.date = '2012-11-08'
|
13
13
|
s.rubyforge_project = 'remote_syslog'
|
14
14
|
|
15
15
|
## Make sure your summary is short. The description may be as long
|
@@ -74,6 +74,7 @@ Gem::Specification.new do |s|
|
|
74
74
|
lib/remote_syslog/file_tail_reader.rb
|
75
75
|
lib/remote_syslog/glob_watch.rb
|
76
76
|
lib/remote_syslog/message_generator.rb
|
77
|
+
lib/remote_syslog/tcp_endpoint.rb
|
77
78
|
lib/remote_syslog/tls_endpoint.rb
|
78
79
|
lib/remote_syslog/udp_endpoint.rb
|
79
80
|
remote_syslog.gemspec
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 1.6.
|
8
|
+
- 9
|
9
|
+
version: 1.6.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Troy Davis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-11-08 00:00:00 -08:00
|
19
19
|
default_executable: remote_syslog
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/remote_syslog/file_tail_reader.rb
|
133
133
|
- lib/remote_syslog/glob_watch.rb
|
134
134
|
- lib/remote_syslog/message_generator.rb
|
135
|
+
- lib/remote_syslog/tcp_endpoint.rb
|
135
136
|
- lib/remote_syslog/tls_endpoint.rb
|
136
137
|
- lib/remote_syslog/udp_endpoint.rb
|
137
138
|
- remote_syslog.gemspec
|