tomcat_log_parser 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +8 -0
- data/lib/tomcat_log_parser.rb +85 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0762cd3e8fcffff6f20b2bd2556279ac0475c3f4
|
4
|
+
data.tar.gz: 2d9f8def6f81e9e8e1139bb9da68ee221fcf5b34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c92b4a3c72c0e6466d68ba990d4c88cc2ad4f8fd1223dff99586fc3be4dbab465165bb3eeabf40d3c604376f6316f9274a971da63ab4aba4a878c500b09bcd91
|
7
|
+
data.tar.gz: ee9718f014ac306984dcb4a88ba0d0d282e77f9e7c4cee538322273abdf1af9776bf92d6350bf567d4678ad484c7a0e3ef651d245015dc21bbebfaae0d4b4e72
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
class Tomcat_log_parser
|
6
|
+
attr_reader :catalinalogarray , :finalcatalinalogarray, :accesslogarray, :filelocation
|
7
|
+
|
8
|
+
def initialize (filelocation)
|
9
|
+
@filelocation = filelocation
|
10
|
+
@catalinalogarray = Array.new
|
11
|
+
@finalcatalinalogarray = Array.new
|
12
|
+
@accesslogarray = Array.new
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def splitCatalinaout
|
18
|
+
#initLogVariables
|
19
|
+
temHash = Hash.new
|
20
|
+
temHash['firstline'] = ''
|
21
|
+
temHash['secondline'] = ''
|
22
|
+
|
23
|
+
File.open(@filelocation) do |file|
|
24
|
+
file.each do |line|
|
25
|
+
logtime = /^(\AJan|\AFeb|\AMar|\AApr|\AMay|\AJun|\AJul|\AAug|\ASep|\AOct|\ANov|\ADec) [0-9]{1,2}, 20[0-9]{2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2} (PM|AM)/.match("#{line}")
|
26
|
+
|
27
|
+
if logtime
|
28
|
+
temHash = Hash.new
|
29
|
+
temHash['firstline'] = line
|
30
|
+
@catalinalogarray.push(temHash)
|
31
|
+
temHash['secondline'] = ''
|
32
|
+
else
|
33
|
+
temHash['secondline'] = temHash['secondline'] + line
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
return @catalinalogarray
|
39
|
+
rescue Exception
|
40
|
+
on_exception
|
41
|
+
end
|
42
|
+
|
43
|
+
public
|
44
|
+
|
45
|
+
def parseCatalineout
|
46
|
+
#print 'process file ...'
|
47
|
+
@la = splitCatalinaout
|
48
|
+
@la.each do |log|
|
49
|
+
temHash = Hash.new
|
50
|
+
temp = log['firstline'].split(' ').last(2)
|
51
|
+
temHash['logclass'] = temp[0]
|
52
|
+
temHash['logaction'] = temp[1]
|
53
|
+
temHash['logtime'] = /^(\AJan|\AFeb|\AMar|\AApr|\AMay|\AJun|\AJul|\AAug|\ASep|\AOct|\ANov|\ADec) [0-9]{1,2}, 20[0-9]{2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2} (PM|AM)/.match("#{log['firstline']}")
|
54
|
+
temHash['logseverity'] = log['secondline'].split(':').first
|
55
|
+
temHash['logdetails'] = log['secondline']
|
56
|
+
@finalcatalinalogarray.push(temHash)
|
57
|
+
end
|
58
|
+
|
59
|
+
return @finalcatalinalogarray
|
60
|
+
rescue Exception
|
61
|
+
on_exception
|
62
|
+
end
|
63
|
+
|
64
|
+
def parseAccesslog
|
65
|
+
File.open(@filelocation) do |file|
|
66
|
+
file.each do |line|
|
67
|
+
temHash = Hash.new
|
68
|
+
temHash['ipaddress'] = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/.match("#{line}")
|
69
|
+
temHash['time'] = /\[.*\]/.match("#{line}").to_s.gsub(/\[|\]/,'')
|
70
|
+
temHash['url'] = /\".*\"/.match("#{line}").to_s.gsub(/\"/,'') #.sub('"','')
|
71
|
+
temHash['code'] = line.split(' ')[-3]
|
72
|
+
temHash['size'] = line.split(' ')[-2]
|
73
|
+
temHash['responsetime'] = line.split(' ')[-1]
|
74
|
+
|
75
|
+
@accesslogarray.push(temHash)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
return @accesslogarray
|
80
|
+
rescue Exception
|
81
|
+
on_exception
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tomcat_log_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chang Dong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Parser for Tomcat catalina.out and access log
|
14
|
+
email: gdsdong@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- Rakefile
|
20
|
+
- lib/tomcat_log_parser.rb
|
21
|
+
homepage: http://3wtemplates.com/
|
22
|
+
licenses:
|
23
|
+
- Apache 2.0
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Tomcat Parser
|
45
|
+
test_files: []
|