server_log_parser 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/server_log_parser/parser.rb +4 -9
- data/lib/server_log_parser/version.rb +1 -1
- data/test/fixtures/{line-with-slash-quote-in-referer.log → line_with_slash_quote_in_referer.log} +0 -0
- data/test/fixtures/{line-with-slash-quote-in-request.log → line_with_slash_quote_in_request.log} +0 -0
- data/test/fixtures/line_with_slash_quote_in_user-agent.log +1 -0
- data/test/{parser_test.rb → server_log_parser/parser_test.rb} +23 -7
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3822fbfb155d2237d6637152c03a9447a426f6c
|
4
|
+
data.tar.gz: 80160b6064711a43c94bfe5a367dcabf03f8d533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 746b9986ac7183eb3397aff0b28e90a1c82cbb387c3116d3937219acdc1c5b030af62384a13407e19f0f7bad48c5e6480ecd48f34544e99ba2d0abd74dde894f
|
7
|
+
data.tar.gz: 1a8a50ebb3ed4750d1580bf604f12af65a2871e3b577b159d10912d046f40ed259cc66a1b141bf4e166b6ba1413c6f51b0c6a595769d8e4493d0ec2eb547a85b
|
data/Rakefile
CHANGED
@@ -91,25 +91,20 @@ module ServerLogParser
|
|
91
91
|
format.strip! # remove leading and trailing space
|
92
92
|
format.gsub!(/[ \t]+/, ' ') # replace tabulations or spaces with a space
|
93
93
|
|
94
|
-
strip_quotes = proc { |string| string.gsub(/^\\"/, '').gsub(/\\"$/, '') }
|
95
|
-
find_quotes = proc { |string| string =~ /^\\"/ }
|
96
|
-
find_percent = proc { |string| string =~ /^%.*t$/ }
|
97
|
-
find_referrer_or_useragent = proc { |string| string =~ /Referer|User-Agent/ }
|
98
|
-
|
99
94
|
pattern = format.split(' ').map do |element|
|
100
|
-
has_quotes =
|
101
|
-
element =
|
95
|
+
has_quotes = element =~ /^\\"/
|
96
|
+
element = element.gsub(/^\\"/, '').gsub(/\\"$/, '') if has_quotes
|
102
97
|
|
103
98
|
self.names << rename_this_name(element)
|
104
99
|
|
105
100
|
case
|
106
101
|
when has_quotes
|
107
|
-
if element == '%r'
|
102
|
+
if element == '%r' || element =~ /^%{Referer}/ || element =~ /^%{User-agent}/
|
108
103
|
/"([^"\\]*(?:\\.[^"\\]*)*)"/
|
109
104
|
else
|
110
105
|
'\"([^\"]*)\"'
|
111
106
|
end
|
112
|
-
when
|
107
|
+
when element =~ /^%.*t$/
|
113
108
|
'(\[[^\]]+\])'
|
114
109
|
when element == '%U'
|
115
110
|
'(.+?)'
|
data/test/fixtures/{line-with-slash-quote-in-referer.log → line_with_slash_quote_in_referer.log}
RENAMED
File without changes
|
data/test/fixtures/{line-with-slash-quote-in-request.log → line_with_slash_quote_in_request.log}
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
212.74.15.68 - - [23/Jan/2004:11:36:20 +0000] "GET /images/previous.png HTTP/1.1" 200 2607 "http://peterhi.dyndns.org/bandwidth/index.html" "Mozilla/5.0 (X11; U; Linux \"Superman\\Superwoman\" i686; en-US; rv:1.2) Gecko/20021202"
|
@@ -13,7 +13,7 @@ describe ServerLogParser::Parser do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
before do
|
16
|
-
@format = '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-
|
16
|
+
@format = '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"'
|
17
17
|
@parser = ServerLogParser::Parser.new(@format)
|
18
18
|
end
|
19
19
|
|
@@ -28,7 +28,7 @@ describe ServerLogParser::Parser do
|
|
28
28
|
'%>s' => '200',
|
29
29
|
'%b' => '2607',
|
30
30
|
'%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
|
31
|
-
'%{User-
|
31
|
+
'%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
|
32
32
|
results = @parser.parse(read_testcase('line.log'))
|
33
33
|
|
34
34
|
assert_kind_of(Hash, results)
|
@@ -44,8 +44,24 @@ describe ServerLogParser::Parser do
|
|
44
44
|
'%>s' => '200',
|
45
45
|
'%b' => '2607',
|
46
46
|
'%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
|
47
|
-
'%{User-
|
48
|
-
results = @parser.parse(read_testcase('
|
47
|
+
'%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
|
48
|
+
results = @parser.parse(read_testcase('line_with_slash_quote_in_request.log'))
|
49
|
+
|
50
|
+
assert_kind_of(Hash, results)
|
51
|
+
assert_match_expected_hash(expected, results)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should parse line with slash quote in user agent" do
|
55
|
+
expected = { '%h' => '212.74.15.68',
|
56
|
+
'%l' => '-',
|
57
|
+
'%u' => '-',
|
58
|
+
'%t' => '[23/Jan/2004:11:36:20 +0000]',
|
59
|
+
'%r' => 'GET /images/previous.png HTTP/1.1',
|
60
|
+
'%>s' => '200',
|
61
|
+
'%b' => '2607',
|
62
|
+
'%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
|
63
|
+
'%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux \\"Superman\\\\Superwoman\\" i686; en-US; rv:1.2) Gecko/20021202' }
|
64
|
+
results = @parser.parse(read_testcase('line_with_slash_quote_in_user-agent.log'))
|
49
65
|
|
50
66
|
assert_kind_of(Hash, results)
|
51
67
|
assert_match_expected_hash(expected, results)
|
@@ -60,8 +76,8 @@ describe ServerLogParser::Parser do
|
|
60
76
|
'%>s' => '200',
|
61
77
|
'%b' => '2888',
|
62
78
|
'%{Referer}i' => 'http://search.yahoo.com/bin/search?p=\"grady%20white%20306%20bimini\"',
|
63
|
-
'%{User-
|
64
|
-
results = @parser.parse(read_testcase('
|
79
|
+
'%{User-agent}i' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; YPC 3.0.3; yplus 4.0.00d)' }
|
80
|
+
results = @parser.parse(read_testcase('line_with_slash_quote_in_referer.log'))
|
65
81
|
|
66
82
|
assert_kind_of(Hash, results)
|
67
83
|
assert_match_expected_hash(expected, results)
|
@@ -104,7 +120,7 @@ describe ServerLogParser::Parser do
|
|
104
120
|
'%>s' => 200,
|
105
121
|
'%b' => 2607,
|
106
122
|
'%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
|
107
|
-
'%{User-
|
123
|
+
'%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
|
108
124
|
results = @parser.handle(read_testcase('line.log'))
|
109
125
|
|
110
126
|
assert_kind_of(Hash, results)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server_log_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kurakin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,10 +71,11 @@ files:
|
|
71
71
|
- lib/server_log_parser/parser.rb
|
72
72
|
- lib/server_log_parser/version.rb
|
73
73
|
- server_log_parser.gemspec
|
74
|
-
- test/fixtures/line-with-slash-quote-in-referer.log
|
75
|
-
- test/fixtures/line-with-slash-quote-in-request.log
|
76
74
|
- test/fixtures/line.log
|
77
|
-
- test/
|
75
|
+
- test/fixtures/line_with_slash_quote_in_referer.log
|
76
|
+
- test/fixtures/line_with_slash_quote_in_request.log
|
77
|
+
- test/fixtures/line_with_slash_quote_in_user-agent.log
|
78
|
+
- test/server_log_parser/parser_test.rb
|
78
79
|
- test/server_log_parser_test.rb
|
79
80
|
- test/test_helper.rb
|
80
81
|
homepage: https://github.com/kuraga/server_log_parser
|
@@ -102,9 +103,10 @@ signing_key:
|
|
102
103
|
specification_version: 4
|
103
104
|
summary: Ruby library to parse Apache server log files using regular expressions.
|
104
105
|
test_files:
|
105
|
-
- test/fixtures/line-with-slash-quote-in-referer.log
|
106
|
-
- test/fixtures/line-with-slash-quote-in-request.log
|
107
106
|
- test/fixtures/line.log
|
108
|
-
- test/
|
107
|
+
- test/fixtures/line_with_slash_quote_in_referer.log
|
108
|
+
- test/fixtures/line_with_slash_quote_in_request.log
|
109
|
+
- test/fixtures/line_with_slash_quote_in_user-agent.log
|
110
|
+
- test/server_log_parser/parser_test.rb
|
109
111
|
- test/server_log_parser_test.rb
|
110
112
|
- test/test_helper.rb
|