syslog-shipper 1.0.20111121124359 → 1.0.20120102102042
Sign up to get free protection for your applications and to get access to all the features.
- data/README +9 -0
- data/bin/syslog-shipper +17 -37
- data/lib/syslog_shipper.rb +6 -0
- data/lib/syslog_shipper/client.rb +37 -0
- data/lib/syslog_shipper/tls_wrapper.rb +25 -0
- data/spec/client_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -0
- metadata +10 -4
data/README
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Ship logs to a syslog server
|
2
|
+
----------------------------
|
3
|
+
|
4
|
+
Usage: bin/syslog-shipper [options] -s HOST:PORT <path_or_glob> [path_or_glob2] [...]
|
5
|
+
If a path begins with '+' each line is sent unmodified to the syslog server.
|
6
|
+
Otherwise, this tool will prefix each line read from the file with a syslog
|
7
|
+
header.
|
8
|
+
|
9
|
+
For example: syslog-shipper -s somehost:514 +/var/log/messages /var/log/apache2/access.log
|
data/bin/syslog-shipper
CHANGED
@@ -1,41 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
2
3
|
require "rubygems"
|
3
|
-
require "eventmachine"
|
4
|
-
require "eventmachine-tail"
|
5
|
-
require "socket"
|
6
4
|
require "optparse"
|
7
|
-
|
8
|
-
class Shipper < EventMachine::FileTail
|
9
|
-
def initialize(path, startpos=-1, connection=nil, raw=false, verbose=false)
|
10
|
-
super(path, startpos)
|
11
|
-
@buffer = BufferedTokenizer.new
|
12
|
-
@hostname = Socket.gethostname
|
13
|
-
@connection = connection
|
14
|
-
@raw = raw
|
15
|
-
@verbose = verbose
|
16
|
-
end
|
17
|
-
|
18
|
-
def receive_data(data)
|
19
|
-
@buffer.extract(data).each do |line|
|
20
|
-
if @raw
|
21
|
-
@connection.send_data("#{line}\n")
|
22
|
-
puts line if @verbose
|
23
|
-
else
|
24
|
-
timestamp = Time.now.strftime("%b %d %H:%M:%S")
|
25
|
-
syslogline = "#{timestamp} #{@hostname} #{path}: #{line}\n"
|
26
|
-
print syslogline if @verbose
|
27
|
-
@connection.send_data(syslogline)
|
28
|
-
end
|
29
|
-
end # buffer extract
|
30
|
-
end # def receive_data
|
31
|
-
end # class Shipper
|
32
|
-
|
33
|
-
def pattern_to_regexp(pattern)
|
34
|
-
pattern.gsub!(".", "\\.") # fix literal .
|
35
|
-
pattern.gsub!("*", ".+") # * becomes .+
|
36
|
-
pattern.gsub!("?", ".") # ? becomes .
|
37
|
-
return Regexp.new(pattern)
|
38
|
-
end # def pattern_to_regexp
|
5
|
+
require File.expand_path('../../lib/syslog_shipper', __FILE__)
|
39
6
|
|
40
7
|
def main(args)
|
41
8
|
globcheck_interval = 5
|
@@ -73,6 +40,10 @@ def main(args)
|
|
73
40
|
opts.on("-v", "--verbose", "verbose (outputs each log line as seen)") do |arg|
|
74
41
|
verbose = true
|
75
42
|
end
|
43
|
+
|
44
|
+
opts.on("-c CERT_PATH", "--ca-cert CERT_PATH", "Certificate authority PEM file to use") do |arg|
|
45
|
+
SyslogShipper::Client.ca_cert = arg
|
46
|
+
end
|
76
47
|
end # OptionParser
|
77
48
|
|
78
49
|
opts.parse!(args)
|
@@ -93,7 +64,7 @@ def main(args)
|
|
93
64
|
host, port = hostarg.split(":")
|
94
65
|
port = 514 if port == nil
|
95
66
|
|
96
|
-
connection = EventMachine
|
67
|
+
connection = EventMachine::connect(host, port, SyslogShipper::TlsWrapper)
|
97
68
|
|
98
69
|
args.each do |path|
|
99
70
|
if path.start_with?("+")
|
@@ -102,7 +73,7 @@ def main(args)
|
|
102
73
|
else
|
103
74
|
raw = false
|
104
75
|
end
|
105
|
-
EventMachine::FileGlobWatchTail.new(path,
|
76
|
+
EventMachine::FileGlobWatchTail.new(path, SyslogShipper::Client,
|
106
77
|
interval = globcheck_interval,
|
107
78
|
exclude = exclude_patterns,
|
108
79
|
start_pos = -1,
|
@@ -115,3 +86,12 @@ def main(args)
|
|
115
86
|
end # def main
|
116
87
|
|
117
88
|
exit(main(ARGV))
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def pattern_to_regexp(pattern)
|
93
|
+
pattern.gsub!(".", "\\.") # fix literal .
|
94
|
+
pattern.gsub!("*", ".+") # * becomes .+
|
95
|
+
pattern.gsub!("?", ".") # ? becomes .
|
96
|
+
return Regexp.new(pattern)
|
97
|
+
end # def pattern_to_regexp
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "socket"
|
2
|
+
|
3
|
+
module SyslogShipper
|
4
|
+
class Client < EventMachine::FileTail
|
5
|
+
class << self
|
6
|
+
attr_accessor :ca_cert
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(path, startpos=-1, connection=nil, raw=false, verbose=false)
|
10
|
+
super(path, startpos)
|
11
|
+
@buffer = BufferedTokenizer.new
|
12
|
+
@hostname = Socket.gethostname
|
13
|
+
@connection = connection
|
14
|
+
@raw = raw
|
15
|
+
@verbose = verbose
|
16
|
+
end
|
17
|
+
|
18
|
+
def receive_data(data)
|
19
|
+
@buffer.extract(data).each do |line|
|
20
|
+
line = if @raw
|
21
|
+
"#{line}\n"
|
22
|
+
else
|
23
|
+
"#{Time.now.strftime("%b %d %H:%M:%S")} #{@hostname} #{path}: #{line}\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
print line if @verbose
|
27
|
+
send_data(line)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def send_data line
|
34
|
+
@connection.send_data line
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module SyslogShipper::TlsWrapper
|
4
|
+
def post_init
|
5
|
+
start_tls(:verify_peer => true)
|
6
|
+
end
|
7
|
+
|
8
|
+
def connection_completed
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
def ssl_verify_peer cert
|
13
|
+
ca_cert = OpenSSL::X509::Certificate.new File.read(SyslogShipper::Client.ca_cert)
|
14
|
+
server_cert = OpenSSL::X509::Certificate.new cert
|
15
|
+
server_cert.verify ca_cert.public_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def ssl_handshake_completed
|
19
|
+
$server_handshake_completed = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def unbind
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/spec/client_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'syslog_shipper'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 20120102102042
|
9
|
+
version: 1.0.20120102102042
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jordan Sissel
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-01-02 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
description: Ship logs from files to a remote syslog server over TCP
|
34
|
-
email:
|
34
|
+
email: jls@semicomplete.com
|
35
35
|
executables:
|
36
36
|
- syslog-shipper
|
37
37
|
extensions: []
|
@@ -39,7 +39,13 @@ extensions: []
|
|
39
39
|
extra_rdoc_files: []
|
40
40
|
|
41
41
|
files:
|
42
|
+
- README
|
43
|
+
- lib/syslog_shipper/tls_wrapper.rb
|
44
|
+
- lib/syslog_shipper/client.rb
|
45
|
+
- lib/syslog_shipper.rb
|
42
46
|
- bin/syslog-shipper
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
- spec/client_spec.rb
|
43
49
|
has_rdoc: true
|
44
50
|
homepage: https://github.com/jordansissel/syslog-shipper
|
45
51
|
licenses: []
|