rec 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/rulesets/postfix-rules.rb +41 -0
- data/rulesets/rules.rb +22 -0
- data/rulesets/sample-rules.rb +62 -0
- metadata +11 -8
- /data/{lib/EXAMPLES → EXAMPLES} +0 -0
- /data/{lib/README → README} +0 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
# collection rules - pull details out of events sharing an ID
|
3
|
+
Rule.new(10040, {
|
4
|
+
:pattern => /\s\w+\spostfix\/pickup\[\d+\]\: (\w+)\: uid=(\d+) from\=\<(\w+)\>/,
|
5
|
+
:details => ["mailid","uid","from"],
|
6
|
+
:message => "Active mail mailid=%mailid$s",
|
7
|
+
:lifespan => 300
|
8
|
+
})
|
9
|
+
Rule.new(10041, {
|
10
|
+
:pattern => / \w+ postfix\/qmgr\[\d+\]\: (\w+)\: from\=\<(.+?\@.+?)?\>/,
|
11
|
+
:details => ["mailid", "from"],
|
12
|
+
:message => "Active mail mailid=%mailid$s"
|
13
|
+
})
|
14
|
+
Rule.new(10042, {
|
15
|
+
:pattern => / \w+ postfix\/smtp\[\d+\]\: (\w+)\: to\=\<(.+?\@.+?)\>.+status\=(\w+)/,
|
16
|
+
:details => ["mailid", "to", "status"],
|
17
|
+
:message => "Active mail mailid=%mailid$s",
|
18
|
+
:alert => "Mail from=%from$s to=%to$s status=%status$s mailid=%mailid$s"
|
19
|
+
}) { |state|
|
20
|
+
state.generate(:alert)
|
21
|
+
state.release()
|
22
|
+
}
|
23
|
+
Rule.new(10043, {
|
24
|
+
:pattern => / \w+ postfix\/local\[\d+\]\: (\w+)\: to\=\<(.+?\@.+?)\>.+status\=(\w+)/,
|
25
|
+
:details => ["mailid", "to", "status"],
|
26
|
+
:message => "Active mail mailid=%mailid$s",
|
27
|
+
:alert => "Mail from=local to=%to$s status=%status$s mailid=%mailid$s"
|
28
|
+
}) { |state|
|
29
|
+
state.generate(:alert)
|
30
|
+
state.release()
|
31
|
+
}
|
32
|
+
# ignore other postfix messages
|
33
|
+
Rule.new(10044, {
|
34
|
+
:pattern => / \w+ postfix\/master|cleanup|bounce/
|
35
|
+
})
|
36
|
+
Rule.new(10045, {
|
37
|
+
:pattern => / \w+ postfix\/qmgr\[\d+\]\: (\w+)\: removed/
|
38
|
+
})
|
39
|
+
Rule.new(10050, {
|
40
|
+
:pattern => /never match anything/
|
41
|
+
})
|
data/rulesets/rules.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby -Ilib
|
2
|
+
# run with command like:
|
3
|
+
# rulesets/rules.rb < /var/log/mail.log 3>missed.log 2>control.log > newevents.log
|
4
|
+
# takes input from a log file and emits new events to newevents.log
|
5
|
+
# while missed events go to the missed.log and control messages to control.log
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rec'
|
9
|
+
include REC
|
10
|
+
|
11
|
+
# For better security, move the next few lines into a file readable only by the user
|
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"
|
17
|
+
|
18
|
+
# load rulesets
|
19
|
+
require 'rulesets/postfix-rules'
|
20
|
+
require 'rulesets/sample-rules'
|
21
|
+
|
22
|
+
Correlator::start()
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# single threshold rule
|
2
|
+
Rule.new(10034, {
|
3
|
+
:pattern => /^\s+\w+\s+sudo\[\d+\]\:\s+(\w+) \:/,
|
4
|
+
:details => ["userid"],
|
5
|
+
:message => "sudo activity for user %userid$s",
|
6
|
+
:lifespan => 60,
|
7
|
+
:alert => "'Too much sudo activity' userid=%userid$s attempts=%count$d dur=%dur$0.3fs ",
|
8
|
+
:expiry => "'Gave sudo a rest' userid=%userid$s attempts=%count$d dur=%dur$0.3fs ",
|
9
|
+
:threshold => 3,
|
10
|
+
:capture => true,
|
11
|
+
:action => Proc.new { |state|
|
12
|
+
if state.count == state.threshold
|
13
|
+
Notify.urgent(state.generate(:alert))
|
14
|
+
state.release()
|
15
|
+
end
|
16
|
+
},
|
17
|
+
:final => Proc.new { |state|
|
18
|
+
Notify.urgent(state.generate(:expiry))
|
19
|
+
}
|
20
|
+
})
|
21
|
+
|
22
|
+
# suppression rule
|
23
|
+
Rule.new(10035, {
|
24
|
+
:pattern => /^\s\w+\sFirewall\[\d+\]\:\sSkype is listening from 0.0.0.0:(\d+)/,
|
25
|
+
:details => ["port"],
|
26
|
+
:message => "Skype conversation started on port %port$d",
|
27
|
+
:alert => "Skype running on port %port$d",
|
28
|
+
:lifespan => 479,
|
29
|
+
:action => State::Generate_first_only
|
30
|
+
})
|
31
|
+
|
32
|
+
# pair rule
|
33
|
+
Rule.new(10036, {
|
34
|
+
:pattern => /^\s\w+\s\w+\: nfs\: server (\w+) not responding/,
|
35
|
+
:details => ["host"],
|
36
|
+
:message => "Server %host$s is down",
|
37
|
+
:lifespan => 300,
|
38
|
+
:action => State::Generate_first_only
|
39
|
+
})
|
40
|
+
Rule.new(10037, {
|
41
|
+
:pattern => /^\s\w+\s\w+\: nfs\: server (\w+) OK/,
|
42
|
+
:details => ["host"],
|
43
|
+
:message => "Server %host$s is up again",
|
44
|
+
:allstates => ["Server %host$s is down"]
|
45
|
+
}) {|state|
|
46
|
+
# store the duration of the outage and log the message
|
47
|
+
duration = State.find("Server %host$s is down", state).age
|
48
|
+
state.params[:outage] = (duration/60).to_i()
|
49
|
+
state.generate()
|
50
|
+
state.release("Server %host$s is down")
|
51
|
+
state.release()
|
52
|
+
}
|
53
|
+
|
54
|
+
# single rule
|
55
|
+
Rule.new(10040, {
|
56
|
+
:pattern => /Accepted password for (\w+) from (\d+\.\d+\.\d+\.\d+)/,
|
57
|
+
:details => ["user", "ip"],
|
58
|
+
:message => "User %user$s signed in via SSH from %ip$s",
|
59
|
+
:action => State::Generate_and_release
|
60
|
+
})
|
61
|
+
|
62
|
+
# single with suppress
|
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Kernahan
|
@@ -31,8 +31,8 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
|
33
33
|
extra_rdoc_files:
|
34
|
-
-
|
35
|
-
-
|
34
|
+
- README
|
35
|
+
- EXAMPLES
|
36
36
|
files:
|
37
37
|
- lib/rec.rb
|
38
38
|
- lib/rec/rule.rb
|
@@ -41,8 +41,11 @@ files:
|
|
41
41
|
- lib/rec/notify.rb
|
42
42
|
- lib/rec/mock-notify.rb
|
43
43
|
- lib/string.rb
|
44
|
-
-
|
45
|
-
-
|
44
|
+
- rulesets/rules.rb
|
45
|
+
- rulesets/sample-rules.rb
|
46
|
+
- rulesets/postfix-rules.rb
|
47
|
+
- README
|
48
|
+
- EXAMPLES
|
46
49
|
homepage: http://rubygems.org/gems/rec
|
47
50
|
licenses: []
|
48
51
|
|
@@ -50,7 +53,7 @@ post_install_message:
|
|
50
53
|
rdoc_options:
|
51
54
|
- --show-hash
|
52
55
|
- --main
|
53
|
-
-
|
56
|
+
- README
|
54
57
|
- --title
|
55
58
|
- REC -- Ruby Event Correlation
|
56
59
|
require_paths:
|
/data/{lib/EXAMPLES → EXAMPLES}
RENAMED
File without changes
|
/data/{lib/README → README}
RENAMED
File without changes
|