rec 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -13
- data/lib/mplex +117 -0
- data/lib/rec/install.rb +51 -0
- data/rulesets/rules.rb +6 -4
- metadata +8 -5
data/CHANGELOG
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
Version 1.1.
|
2
|
-
|
3
|
-
|
1
|
+
=== Version 1.1.1
|
2
|
+
- added mplex.rb to support merging of event streams
|
3
|
+
- added MULTIPLEX documentation
|
4
|
+
- added optional post-install script to install mplex executable
|
4
5
|
|
5
|
-
Version 1.0.9
|
6
|
-
|
6
|
+
=== Version 1.0.9
|
7
|
+
- Removed mock-notify.rb
|
7
8
|
|
8
|
-
Version 1.0.7
|
9
|
-
|
9
|
+
=== Version 1.0.7
|
10
|
+
- Simplified rdoc markup for the benefit of yard.
|
10
11
|
|
11
|
-
Version 1.0.6
|
12
|
-
|
12
|
+
=== Version 1.0.6
|
13
|
+
- Restructured for better compatibility with gem standards
|
13
14
|
|
14
|
-
Version 1.0.4
|
15
|
-
|
15
|
+
=== Version 1.0.4
|
16
|
+
- Added examples
|
16
17
|
|
17
|
-
Version 1.0.1
|
18
|
-
|
18
|
+
=== Version 1.0.1
|
19
|
+
- Initial version
|
data/lib/mplex
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
require 'getoptlong'
|
3
|
+
require 'io/wait'
|
4
|
+
|
5
|
+
version = "1.0.0"
|
6
|
+
|
7
|
+
usage =<<-EOT
|
8
|
+
mplex - an IO multiplexer
|
9
|
+
Usage: mplex [OPTION] -i infile [-i infile2...] -o outfile [-o outfile2...]
|
10
|
+
where mplex reads from one or more infiles and writes to one or more outfiles.
|
11
|
+
--input, -i the path to a log file to read from
|
12
|
+
--output, -o the path to a log file to write to
|
13
|
+
--help, -h display usage
|
14
|
+
--version, -v show version
|
15
|
+
--debug, -d display each line on stdout as it is passes through mplex
|
16
|
+
Examples:
|
17
|
+
$ mplex -i input1.log -i input2.log -o output3.log
|
18
|
+
combines two input files into a single output stream
|
19
|
+
$ mplex -i in.log -i in2.log -o out3.log -o out4.log -o out5.log
|
20
|
+
combines two input streams and writes to 3 output streams
|
21
|
+
Note:
|
22
|
+
Stdin and Stdout do not participate in the multiplexing, so make sure
|
23
|
+
to prefix any filename with either -i or -o
|
24
|
+
EOT
|
25
|
+
|
26
|
+
options = GetoptLong.new(
|
27
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
28
|
+
[ '--version', '-v', GetoptLong::NO_ARGUMENT ],
|
29
|
+
[ '--debug', '-d', GetoptLong::NO_ARGUMENT ],
|
30
|
+
[ '--input', '-i', GetoptLong::REQUIRED_ARGUMENT ],
|
31
|
+
[ '--output', '-o', GetoptLong::REQUIRED_ARGUMENT ]
|
32
|
+
)
|
33
|
+
|
34
|
+
infilenames = []
|
35
|
+
outfilenames = []
|
36
|
+
options.each { |opt, arg|
|
37
|
+
case opt
|
38
|
+
when "--help"
|
39
|
+
puts(usage)
|
40
|
+
exit 0
|
41
|
+
when "--version"
|
42
|
+
puts("mplex version #{version}")
|
43
|
+
exit 0
|
44
|
+
when "--input"
|
45
|
+
infilenames << arg
|
46
|
+
when "--output"
|
47
|
+
outfilenames << arg
|
48
|
+
when "--debug"
|
49
|
+
debug = true
|
50
|
+
end
|
51
|
+
}
|
52
|
+
|
53
|
+
# No arguments should be provided on the command line
|
54
|
+
# If they were, maybe someone forgot to use the -i or -o options
|
55
|
+
if ARGV.length > 0
|
56
|
+
puts("Warning: every filename must have -i or -o before it. No other arguments are accepted.")
|
57
|
+
puts(usage)
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
# Allow graceful shutdown
|
62
|
+
["INT", "TERM", "QUIT"].each { |sig|
|
63
|
+
Signal.trap(sig) {
|
64
|
+
exit(0)
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
# Check if the infiles exist and are readable
|
69
|
+
failure = false
|
70
|
+
infilenames.each { |f|
|
71
|
+
if File.exists?(f)
|
72
|
+
unless File.readable?(f)
|
73
|
+
puts("File #{f} is not readable")
|
74
|
+
failure = true
|
75
|
+
end
|
76
|
+
else
|
77
|
+
puts("File #{f} does not exist")
|
78
|
+
failure = true
|
79
|
+
end
|
80
|
+
}
|
81
|
+
if failure
|
82
|
+
puts(usage)
|
83
|
+
exit 2
|
84
|
+
end
|
85
|
+
|
86
|
+
# Open all infiles and outfiles
|
87
|
+
infiles = infilenames.collect { |path|
|
88
|
+
File.new(path, File::RDONLY)
|
89
|
+
}
|
90
|
+
outfiles = outfilenames.collect { |path|
|
91
|
+
File.new(path, File::APPEND|File::CREAT|File::WRONLY)
|
92
|
+
}
|
93
|
+
|
94
|
+
# Multiplex the IO streams
|
95
|
+
loop {
|
96
|
+
reads = 0
|
97
|
+
infiles.each { |i|
|
98
|
+
line = i.gets().chomp() if i.ready?
|
99
|
+
reads = reads.succ unless line.nil?
|
100
|
+
if line
|
101
|
+
outfiles.each { |o|
|
102
|
+
o.puts(line)
|
103
|
+
o.flush()
|
104
|
+
}
|
105
|
+
puts(line) if debug and not line.nil?
|
106
|
+
end
|
107
|
+
}
|
108
|
+
sleep(1) if reads == 0
|
109
|
+
}
|
110
|
+
|
111
|
+
# Close all files
|
112
|
+
infiles.each { |i|
|
113
|
+
i.close unless i.closed?
|
114
|
+
}
|
115
|
+
outfiles.each { |o|
|
116
|
+
o.close unless o.closed?
|
117
|
+
}
|
data/lib/rec/install.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
#______________________
|
4
|
+
if Process.euid != 0
|
5
|
+
puts("This script must be run as root")
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
#______________________
|
10
|
+
# Enable graceful exit especially while seeking input
|
11
|
+
["INT", "TERM", "QUIT"].each { |sig|
|
12
|
+
Signal.trap(sig) {
|
13
|
+
puts("")
|
14
|
+
exit(0)
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
#______________________
|
19
|
+
# display intent
|
20
|
+
bindir = File.expand_path("../../bin", File.dirname(__FILE__))
|
21
|
+
|
22
|
+
puts("Installing mplex...")
|
23
|
+
|
24
|
+
#______________________
|
25
|
+
# confirm path to install to
|
26
|
+
sbindir = "/usr/local/sbin"
|
27
|
+
confirmed = false
|
28
|
+
begin
|
29
|
+
print("Install to path [#{sbindir}]: ")
|
30
|
+
answer = gets().chomp()
|
31
|
+
if answer == ""
|
32
|
+
confirmed = true
|
33
|
+
else
|
34
|
+
if File.directory?(answer)
|
35
|
+
confirmed = true
|
36
|
+
sbindir = answer
|
37
|
+
else
|
38
|
+
puts(" Sorry, the directory #{answer} was not found.\n\n")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end until confirmed
|
42
|
+
|
43
|
+
#______________________
|
44
|
+
# install the executable
|
45
|
+
exe = "mplex"
|
46
|
+
targ = "#{sbindir}/#{exe}"
|
47
|
+
FileUtils.cp("#{bindir}/#{exe}", targ)
|
48
|
+
FileUtils.chown("root", "wheel", targ)
|
49
|
+
FileUtils.chmod(0755, targ)
|
50
|
+
puts(" " + `ls -l #{targ}`)
|
51
|
+
puts("Done.")
|
data/rulesets/rules.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
# run with command like:
|
3
3
|
# rulesets/rules.rb < /var/log/mail.log 3>missed.log 2>control.log > newevents.log
|
4
4
|
# takes input from a log file and emits new events to newevents.log
|
@@ -15,8 +15,10 @@ Notify.emailTo = "me@myfirm.com"
|
|
15
15
|
Notify.jabber_credentials("rec@gmail.com", "recret")
|
16
16
|
Notify.jabberTo = "me@myfirm.com"
|
17
17
|
|
18
|
-
# load rulesets
|
19
|
-
|
20
|
-
require
|
18
|
+
# load rulesets specified as arguments on the command line
|
19
|
+
while ARGV[0]
|
20
|
+
require ARGV[0]
|
21
|
+
ARGV.shift() # remove from ARGV so rulesets are *not* treated as STDIN
|
22
|
+
end
|
21
23
|
|
22
24
|
Correlator::start()
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Kernahan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-09-
|
18
|
+
date: 2012-09-30 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: "\t\tSifts through your log files in real time, using stateful intelligence to determine\n\
|
@@ -38,7 +38,9 @@ files:
|
|
38
38
|
- lib/rec/state.rb
|
39
39
|
- lib/rec/correlator.rb
|
40
40
|
- lib/rec/notify.rb
|
41
|
+
- lib/rec/install.rb
|
41
42
|
- lib/string.rb
|
43
|
+
- lib/mplex
|
42
44
|
- rulesets/rules.rb
|
43
45
|
- rulesets/sample-rules.rb
|
44
46
|
- rulesets/postfix-rules.rb
|
@@ -51,7 +53,8 @@ files:
|
|
51
53
|
homepage: http://rubygems.org/gems/rec
|
52
54
|
licenses: []
|
53
55
|
|
54
|
-
post_install_message:
|
56
|
+
post_install_message: "\n\n To install the mplex executable issue the following command:\n\
|
57
|
+
\t$ sudo ruby -rubygems -e \"require 'rec/install'\"\n\n "
|
55
58
|
rdoc_options:
|
56
59
|
- --main
|
57
60
|
- README
|