loghandler 0.0.6 → 0.0.7
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/lib/loghandler.rb +14 -0
- data/lib/loghandler/rules/abstract_rule.rb +2 -1
- data/lib/loghandler/rules/generic_error_log_rule.rb +26 -0
- data/lib/loghandler/rules/generic_log_rule.rb +0 -5
- data/lib/loghandler/rules/thin_access_log_rule.rb +9 -8
- data/lib/loghandler/server.rb +11 -9
- data/lib/loghandler/version.rb +1 -1
- metadata +2 -1
data/lib/loghandler.rb
CHANGED
@@ -14,6 +14,20 @@ require "loghandler/rules/abstract_rule"
|
|
14
14
|
require "loghandler/rules/thin_access_log_rule"
|
15
15
|
require "loghandler/rules/on_radio_log_rule"
|
16
16
|
require "loghandler/rules/generic_log_rule"
|
17
|
+
require "loghandler/rules/generic_error_log_rule"
|
17
18
|
|
18
19
|
module Loghandler
|
19
20
|
end
|
21
|
+
|
22
|
+
# monkey patch
|
23
|
+
class String
|
24
|
+
def underscore
|
25
|
+
word = self.dup
|
26
|
+
word.gsub!(/::/, '/')
|
27
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
28
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
29
|
+
word.tr!("-", "_")
|
30
|
+
word.downcase!
|
31
|
+
word
|
32
|
+
end
|
33
|
+
end
|
@@ -5,7 +5,8 @@ module Loghandler
|
|
5
5
|
raise "initialize is abstract. Provide an implementation"
|
6
6
|
end
|
7
7
|
def match?
|
8
|
-
|
8
|
+
return true if self.class.name.underscore == ["loghandler/rules/",@log_detail[:log_type], "_rule"].join
|
9
|
+
return false
|
9
10
|
end
|
10
11
|
def apply!
|
11
12
|
raise "convert is abstract. Provide an implementation"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Loghandler
|
2
|
+
module Rules
|
3
|
+
|
4
|
+
class GenericErrorLogRule < AbstractRule
|
5
|
+
def initialize(log_detail)
|
6
|
+
@log_detail=log_detail
|
7
|
+
end
|
8
|
+
def apply!
|
9
|
+
@log_detail[:severity]="error"
|
10
|
+
end
|
11
|
+
def log
|
12
|
+
@log_detail.to_json
|
13
|
+
end
|
14
|
+
def loggable?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
def persist?
|
18
|
+
false
|
19
|
+
end
|
20
|
+
def showable?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -5,11 +5,6 @@ module Loghandler
|
|
5
5
|
def initialize(log_detail)
|
6
6
|
@log_detail=log_detail
|
7
7
|
end
|
8
|
-
def match?
|
9
|
-
return true if "generic_log" == @log_detail[:log_type]
|
10
|
-
# return true if (@log_detail[:content].match(/RTL2/))
|
11
|
-
return false
|
12
|
-
end
|
13
8
|
def apply!
|
14
9
|
end
|
15
10
|
def log
|
@@ -5,11 +5,6 @@ module Loghandler
|
|
5
5
|
def initialize(log_detail)
|
6
6
|
@log_detail=log_detail
|
7
7
|
end
|
8
|
-
def match?
|
9
|
-
return true if "thin_access_log"==@log_detail[:log_type]
|
10
|
-
# return true if (@log_detail[:content].match(/RTL2/))
|
11
|
-
return false
|
12
|
-
end
|
13
8
|
def apply!
|
14
9
|
log_detail = {}
|
15
10
|
tmp = CSV.parse(@log_detail[:content],col_sep:" ")
|
@@ -17,13 +12,19 @@ module Loghandler
|
|
17
12
|
log_detail[:ip] = tmp[0]
|
18
13
|
log_detail[:date] = tmp[3]+tmp[4]
|
19
14
|
log_detail[:url]=tmp[5]
|
20
|
-
log_detail[:status]=tmp[6]
|
21
|
-
log_detail[:length]=tmp[7]
|
15
|
+
log_detail[:status]=tmp[6].to_i
|
16
|
+
log_detail[:length]=tmp[7].to_i
|
22
17
|
log_detail[:referer]=tmp[8]
|
23
18
|
log_detail[:user_agent]=tmp[9]
|
24
19
|
#p [log_detail[:url],log_detail[:status]]
|
25
|
-
|
26
20
|
@log_detail.merge!(log_detail)
|
21
|
+
if @log_detail[:status]>=500
|
22
|
+
@log_detail[:severity]="error"
|
23
|
+
elsif @log_detail[:status]>=400
|
24
|
+
@log_detail[:severity]="warning"
|
25
|
+
else
|
26
|
+
@log_detail[:severity]="none"
|
27
|
+
end
|
27
28
|
end
|
28
29
|
def log
|
29
30
|
@log_detail.to_json
|
data/lib/loghandler/server.rb
CHANGED
@@ -5,6 +5,10 @@ class Loghandler::Server < EM::Connection
|
|
5
5
|
|
6
6
|
include MongoMapper
|
7
7
|
|
8
|
+
def initialize(ws_channel)
|
9
|
+
@ws_channel = ws_channel
|
10
|
+
super
|
11
|
+
end
|
8
12
|
|
9
13
|
def post_init
|
10
14
|
@rules=Loghandler::Rules.constants.select {|c| Class === Loghandler::Rules.const_get(c)}
|
@@ -28,7 +32,7 @@ class Loghandler::Server < EM::Connection
|
|
28
32
|
detect_matching_rules(log_detail).each do |rule|
|
29
33
|
rule.apply!
|
30
34
|
# puts "logging: #{rule.log}" if !rule.loggable?
|
31
|
-
|
35
|
+
@ws_channel.push(rule.log) if rule.loggable?
|
32
36
|
end
|
33
37
|
|
34
38
|
end
|
@@ -59,20 +63,18 @@ class Loghandler::Server < EM::Connection
|
|
59
63
|
MongoMapper.database = "loghandler"
|
60
64
|
|
61
65
|
EM.run do
|
62
|
-
|
63
|
-
|
66
|
+
ws_channel = EventMachine::Channel.new
|
64
67
|
Signal.trap("INT") do
|
65
68
|
EM.stop
|
66
69
|
end
|
67
|
-
EventMachine.start_server options[:url], options[:port], Loghandler::Server
|
70
|
+
EventMachine.start_server options[:url], options[:port], Loghandler::Server, ws_channel
|
68
71
|
|
69
72
|
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
|
70
|
-
|
71
|
-
|
73
|
+
ws.onopen do
|
74
|
+
ws_channel.subscribe do |msg|
|
75
|
+
ws.send msg
|
76
|
+
end
|
72
77
|
end
|
73
|
-
# ws.onopen {
|
74
|
-
# puts "WebSocket connection open"
|
75
|
-
# }
|
76
78
|
# ws.onclose { puts "Connection closed" }
|
77
79
|
# ws.onmessage { |msg|
|
78
80
|
# puts "Recieved message: #{msg}"
|
data/lib/loghandler/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loghandler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/loghandler/client.rb
|
128
128
|
- lib/loghandler/log_detail.rb
|
129
129
|
- lib/loghandler/rules/abstract_rule.rb
|
130
|
+
- lib/loghandler/rules/generic_error_log_rule.rb
|
130
131
|
- lib/loghandler/rules/generic_log_rule.rb
|
131
132
|
- lib/loghandler/rules/on_radio_log_rule.rb
|
132
133
|
- lib/loghandler/rules/thin_access_log_rule.rb
|