rec 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGELOG +3 -0
  2. data/bin/mplex +43 -28
  3. data/lib/rec/state.rb +15 -2
  4. data/rulesets/rules.rb +5 -5
  5. metadata +19 -5
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ === Version 1.1.3
2
+ - Made dependency on xmpp4r explicit
3
+
1
4
  === Version 1.1.2
2
5
  - added mplex.rb to support merging of event streams
3
6
  - added MULTIPLEX documentation
data/bin/mplex CHANGED
@@ -10,6 +10,7 @@ Usage: mplex [OPTION] -i infile [-i infile2...] -o outfile [-o outfile2...]
10
10
  where mplex reads from one or more infiles and writes to one or more outfiles.
11
11
  --input, -i the path to a log file to read from
12
12
  --output, -o the path to a log file to write to
13
+ --name myapp changes the process name to "myapp", default="mplex"
13
14
  --help, -h display usage
14
15
  --version, -v show version
15
16
  --debug, -d display each line on stdout as it is passes through mplex
@@ -27,12 +28,15 @@ options = GetoptLong.new(
27
28
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
28
29
  [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
29
30
  [ '--debug', '-d', GetoptLong::NO_ARGUMENT ],
31
+ [ '--name', '-n', GetoptLong::REQUIRED_ARGUMENT ],
30
32
  [ '--input', '-i', GetoptLong::REQUIRED_ARGUMENT ],
31
33
  [ '--output', '-o', GetoptLong::REQUIRED_ARGUMENT ]
32
34
  )
33
35
 
34
36
  infilenames = []
35
37
  outfilenames = []
38
+ debug = false
39
+ appname = "mplex"
36
40
  options.each { |opt, arg|
37
41
  case opt
38
42
  when "--help"
@@ -47,6 +51,8 @@ options.each { |opt, arg|
47
51
  outfilenames << arg
48
52
  when "--debug"
49
53
  debug = true
54
+ when "--name"
55
+ appname = arg
50
56
  end
51
57
  }
52
58
 
@@ -58,13 +64,6 @@ if ARGV.length > 0
58
64
  exit 1
59
65
  end
60
66
 
61
- # Allow graceful shutdown
62
- ["INT", "TERM", "QUIT"].each { |sig|
63
- Signal.trap(sig) {
64
- exit(0)
65
- }
66
- }
67
-
68
67
  # Check if the infiles exist and are readable
69
68
  failure = false
70
69
  infilenames.each { |f|
@@ -91,27 +90,43 @@ outfiles = outfilenames.collect { |path|
91
90
  File.new(path, File::APPEND|File::CREAT|File::WRONLY)
92
91
  }
93
92
 
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
93
+ # Allow graceful shutdown
94
+ ["INT", "TERM", "QUIT"].each { |sig|
95
+ Signal.trap(sig) {
96
+ # Close all files
97
+ infiles.each { |i|
98
+ i.close unless i.closed?
99
+ }
100
+ outfiles.each { |o|
101
+ o.close unless o.closed?
102
+ }
103
+ exit(0)
107
104
  }
108
- sleep(1) if reads == 0
109
105
  }
110
106
 
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
- }
107
+ # daemonise the process
108
+ $0 = appname
109
+ fork do
110
+ Process.setsid
111
+ exit if fork
112
+ File.umask 0027 # default mode => 0750
113
+ STDIN.reopen "/dev/null"
114
+ STDOUT.reopen "/dev/null"
115
+ STDERR.reopen "/dev/null"
116
+ # Multiplex the IO streams
117
+ loop {
118
+ reads = 0
119
+ infiles.each { |i|
120
+ line = i.gets().chomp() if i.ready?
121
+ reads = reads.succ unless line.nil?
122
+ if line
123
+ outfiles.each { |o|
124
+ o.puts(line)
125
+ o.flush()
126
+ }
127
+ puts(line) if debug and not line.nil?
128
+ end
129
+ }
130
+ sleep(1) if reads == 0
131
+ }
132
+ end
data/lib/rec/state.rb CHANGED
@@ -28,11 +28,24 @@ class State
28
28
  state.release()
29
29
  }
30
30
 
31
- # shortcut action to generate a message on first event only
31
+ # shortcut action to generate a message on first event only, swallow the rest
32
32
  Generate_first_only = Proc.new { |state|
33
- state.generate_first_only()
33
+ state.generate(:alert) if @count == 1
34
34
  }
35
35
 
36
+ # shortcut action to notify the admin immediately (eg. system is down)
37
+ # and wait (eg. for system to come up again)
38
+ Notify_urgently_first_only = Proc.new { |state|
39
+ Notify.urgent(state.generate(:alert)) if @count == 1
40
+ }
41
+
42
+ # shortcut action to notify urgently and release
43
+ # Good for a single event (eg. backup failed) requiring immediate action
44
+ Notify_urgently_and_release = Proc.new { |state|
45
+ Notify.urgent(state.generate(:alert))
46
+ state.release()
47
+ }
48
+
36
49
  # A array of Timeouts. A Timeout struct has two elements:
37
50
  # - timestamp at which to expire
38
51
  # - key of the state to be expired
data/rulesets/rules.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/local/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
@@ -10,10 +10,10 @@ include REC
10
10
 
11
11
  # For better security, move the next few lines into a file readable only by the user
12
12
  # running this script eg. /home/rec/alert.conf and then require that file
13
- Notify.smtp_credentials("rec@gmail.com", "recret", "myfirm.com")
14
- Notify.emailTo = "me@myfirm.com"
15
- Notify.jabber_credentials("rec@gmail.com", "recret")
16
- Notify.jabberTo = "me@myfirm.com"
13
+ #Notify.smtp_credentials("rec@gmail.com", "recret", "myfirm.com")
14
+ #Notify.emailTo = "me@myfirm.com"
15
+ #Notify.jabber_credentials("rec@gmail.com", "recret")
16
+ #Notify.jabberTo = "me@myfirm.com"
17
17
 
18
18
  # load rulesets specified as arguments on the command line
19
19
  while ARGV[0]
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Kernahan
@@ -16,8 +16,22 @@ bindir: bin
16
16
  cert_chain: []
17
17
 
18
18
  date: 2012-09-30 00:00:00 Z
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: xmpp4r
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 1
29
+ segments:
30
+ - 0
31
+ - 5
32
+ version: "0.5"
33
+ type: :runtime
34
+ version_requirements: *id001
21
35
  description: "\t\tSifts through your log files in real time, using stateful intelligence to determine\n\
22
36
  \t\twhat is really important. REC can alert you (by email or IM) or it can simply condense\n\
23
37
  \t\ta large log file into a much shorter and more meaningful log.\n\