syslog-shipper 1.0.20111121124359
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/syslog-shipper +117 -0
- metadata +76 -0
data/bin/syslog-shipper
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
require "eventmachine"
|
4
|
+
require "eventmachine-tail"
|
5
|
+
require "socket"
|
6
|
+
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
|
39
|
+
|
40
|
+
def main(args)
|
41
|
+
globcheck_interval = 5
|
42
|
+
exclude_patterns = []
|
43
|
+
hostarg = nil
|
44
|
+
verbose = false
|
45
|
+
|
46
|
+
opts = OptionParser.new do |opts|
|
47
|
+
opts.banner = [
|
48
|
+
"Usage: #{$0} [options] -s HOST:PORT <path_or_glob> [path_or_glob2] [...]",
|
49
|
+
" If a path begins with '+' each line is sent unmodified to the syslog server.",
|
50
|
+
" Otherwise, this tool will prefix each line read from the file with a syslog",
|
51
|
+
" header. ",
|
52
|
+
"",
|
53
|
+
" For example: #{$0} -s somehost:514 +/var/log/messages /var/log/apache2/access.log",
|
54
|
+
].join("\n")
|
55
|
+
|
56
|
+
opts.on("-i SECONDS", "--check-interval SECONDS",
|
57
|
+
"How frequently, in seconds, to check the glob patterns" \
|
58
|
+
"for new files") do |x|
|
59
|
+
globcheck_interval = x.to_f
|
60
|
+
end # -i SECONDS
|
61
|
+
|
62
|
+
opts.on("-x EXCLUDE", "--exclude EXCLUDE",
|
63
|
+
"A pattern to ignore. Wildcard/globs accepted." \
|
64
|
+
" Can be specified multiple times") do |pattern|
|
65
|
+
exclude_patterns << pattern_to_regexp(pattern)
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on("-s HOST:PORT", "--server HOST:PORT",
|
69
|
+
"What syslog server to ship to (uses TCP)") do |arg|
|
70
|
+
hostarg = arg
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on("-v", "--verbose", "verbose (outputs each log line as seen)") do |arg|
|
74
|
+
verbose = true
|
75
|
+
end
|
76
|
+
end # OptionParser
|
77
|
+
|
78
|
+
opts.parse!(args)
|
79
|
+
|
80
|
+
if args.length == 0 or hostarg == nil
|
81
|
+
puts opts.banner
|
82
|
+
return 1
|
83
|
+
end
|
84
|
+
|
85
|
+
EventMachine.run do
|
86
|
+
Signal.trap("INT") do
|
87
|
+
EventMachine.schedule do
|
88
|
+
$stderr.puts "Got SIGINT"
|
89
|
+
exit 128 + (Signal.list["INT"])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
host, port = hostarg.split(":")
|
94
|
+
port = 514 if port == nil
|
95
|
+
|
96
|
+
connection = EventMachine.connect(host, port.to_i)
|
97
|
+
|
98
|
+
args.each do |path|
|
99
|
+
if path.start_with?("+")
|
100
|
+
raw = true
|
101
|
+
path = path[1..-1]
|
102
|
+
else
|
103
|
+
raw = false
|
104
|
+
end
|
105
|
+
EventMachine::FileGlobWatchTail.new(path, Shipper,
|
106
|
+
interval = globcheck_interval,
|
107
|
+
exclude = exclude_patterns,
|
108
|
+
start_pos = -1,
|
109
|
+
connection = connection,
|
110
|
+
raw = raw,
|
111
|
+
verbose = verbose
|
112
|
+
)
|
113
|
+
end # args.each
|
114
|
+
end # EventMachine.run
|
115
|
+
end # def main
|
116
|
+
|
117
|
+
exit(main(ARGV))
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syslog-shipper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 20111121124359
|
9
|
+
version: 1.0.20111121124359
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jordan Sissel
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-11-21 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: eventmachine-tail
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description: Ship logs from files to a remote syslog server over TCP
|
34
|
+
email: jordan@loggly.com
|
35
|
+
executables:
|
36
|
+
- syslog-shipper
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- bin/syslog-shipper
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: https://github.com/jordansissel/syslog-shipper
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: syslog-shipper - a tool for streaming logs from files to a remote syslog server
|
75
|
+
test_files: []
|
76
|
+
|