apache_log-parser 3.0.0 → 3.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 338af4fdaec6a5a65bf000f5dc549f73ba1db221
4
- data.tar.gz: b5366447d647a4da67dbce66468730fa993fbd15
3
+ metadata.gz: 2679264013d2c6cf84bb77978e6380edd1c4ab67
4
+ data.tar.gz: 71b9d2114b248aaae424daadcfdd5e86e1cc9528
5
5
  SHA512:
6
- metadata.gz: fe677bb02e77958f076a1b68a1b6cf8f5c619c4b7f7c551e6e8ef9b7496617a13b7b25ff268881d0f6f9f3a3f978c2ee6165500a2477b507d8cb91d5eba79c13
7
- data.tar.gz: 2ee1ab1f75310b24e9ad8cdcfabcaa69607e76ce83534301519cfba81640ef3ebe80be56a35b7efde54f2b71c3d599a0c0eb443c341d670769b58551dfabf48a
6
+ metadata.gz: 3281247ab7a73b393dea4364c6595ee9adaa3803767555e3b95ccb575d6159ed5a0b0589e8f5ac6f1b98718ed666ab66be53a67718cf75799bf28f856aa25a06
7
+ data.tar.gz: e50f2cf1469c4a665581e4d2fbcba1490800033bb65f9e250b705a8dba821708dba266392177b776b738664571f36a2bb719b88213d42cffb75afbd002523b9d
@@ -7,7 +7,7 @@ module ApacheLog
7
7
  common_fields = %w(remote_host identity_check user datetime request status size)
8
8
  combined_fields = common_fields + %w(referer user_agent)
9
9
 
10
- common_pattern = '(\S+)\s+(\S+)\s+(\S+)\s+\[(\d{2}\/.*\d{4}:\d{2}:\d{2}:\d{2}\s.*)\]\s+"(\S+\s\S+\s\S+)"\s+(\S+)\s+(\S+)'
10
+ common_pattern = '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\S+)\s+(\S+)\s+\[(\d{2}\/.*\d{4}:\d{2}:\d{2}:\d{2}\s.*)\]\s+"(\S+\s\S+\s\S+)"\s+(\S+)\s+(\S+)'
11
11
  combined_pattern = common_pattern + '\s+"([^"]*)"\s+"([^"]*)"'
12
12
  additional_pattern = ''
13
13
 
@@ -18,10 +18,10 @@ module ApacheLog
18
18
  case format
19
19
  when 'common'
20
20
  @fields = common_fields + additional_fields
21
- @pattern = /^#{common_pattern}#{additional_pattern}$/
21
+ @pattern = /#{common_pattern}#{additional_pattern}/
22
22
  when 'combined'
23
23
  @fields = combined_fields + additional_fields
24
- @pattern = /^#{combined_pattern}#{additional_pattern}$/
24
+ @pattern = /#{combined_pattern}#{additional_pattern}/
25
25
  else
26
26
  raise "format error\n no such format: <#{format}> \n"
27
27
  end
@@ -1,5 +1,5 @@
1
1
  module ApacheLog
2
2
  class Parser
3
- VERSION = "3.0.0"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
@@ -26,10 +26,10 @@ describe ApacheLog::Parser do
26
26
  end
27
27
 
28
28
  it 'can parse combined format log' do
29
- line = '104.24.160.39 - - [07/Jun/2014:14:58:55 +0900] "GET /category/electronics HTTP/1.1" 200 128 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"'
29
+ line = '192.168.0.1 - - [07/Jun/2014:14:58:55 +0900] "GET /category/electronics HTTP/1.1" 200 128 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"'
30
30
  parser = ApacheLog::Parser.new('combined')
31
31
  entity = parser.parse(line.chomp)
32
- expect = {remote_host: '104.24.160.39', identity_check: '-', user: '-', datetime: DateTime.new(2014, 6, 7, 14, 58, 55, 0.375),
32
+ expect = {remote_host: '192.168.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2014, 6, 7, 14, 58, 55, 0.375),
33
33
  request: {method: 'GET', path: '/category/electronics', protocol: 'HTTP/1.1'}, status: '200', size: '128', referer: '-',
34
34
  user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1'}
35
35
  expect(entity).to eq(expect)
@@ -46,20 +46,20 @@ describe ApacheLog::Parser do
46
46
  end
47
47
 
48
48
  it 'can parse tab separated combined format log' do
49
- line = "203.0.113.254\t-\t-\t[07/Feb/2011:10:59:59 +0900]\t\"GET /x/i.cgi/movie/0001/-0002 HTTP/1.1\"\t200\t14462\t\"-\"\t\"DoCoMo/2.0 F08A3(c500;TB;W30H20)\"";
49
+ line = "192.168.0.1\t-\t-\t[07/Feb/2011:10:59:59 +0900]\t\"GET /x/i.cgi/movie/0001/-0002 HTTP/1.1\"\t200\t14462\t\"-\"\t\"DoCoMo/2.0 F08A3(c500;TB;W30H20)\"";
50
50
  parser = ApacheLog::Parser.new('combined')
51
51
  entity = parser.parse(line.chomp)
52
- expect = {remote_host: '203.0.113.254', identity_check: '-', user:'-', datetime: DateTime.new(2011, 2, 7, 10, 59, 59, 0.375),
52
+ expect = {remote_host: '192.168.0.1', identity_check: '-', user:'-', datetime: DateTime.new(2011, 2, 7, 10, 59, 59, 0.375),
53
53
  request: {method: 'GET', path: '/x/i.cgi/movie/0001/-0002', protocol: 'HTTP/1.1'}, status: '200', size: '14462', referer: '-',
54
54
  user_agent: 'DoCoMo/2.0 F08A3(c500;TB;W30H20)'}
55
55
  expect(entity).to eq(expect)
56
56
  end
57
57
 
58
58
  it 'can parse custom format log based on combined format' do
59
- line = '104.24.160.39 - - [07/Jun/2014:14:58:55 +0900] "GET /category/electronics HTTP/1.1" 200 128 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" "example.com" "192.168.0.1201102091208001" "901"'
59
+ line = '192.168.0.1 - - [07/Jun/2014:14:58:55 +0900] "GET /category/electronics HTTP/1.1" 200 128 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" "example.com" "192.168.0.1201102091208001" "901"'
60
60
  parser = ApacheLog::Parser.new('combined', %w(vhost usertrack request_duration))
61
61
  entity = parser.parse(line.chomp)
62
- expect = {remote_host: '104.24.160.39', identity_check: '-', user: '-', datetime: DateTime.new(2014, 6, 7, 14, 58, 55, 0.375),
62
+ expect = {remote_host: '192.168.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2014, 6, 7, 14, 58, 55, 0.375),
63
63
  request: {method: 'GET', path: '/category/electronics', protocol: 'HTTP/1.1'}, status: '200', size: '128', referer: '-',
64
64
  user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1', vhost: 'example.com',
65
65
  usertrack: '192.168.0.1201102091208001', request_duration: '901'}
@@ -78,13 +78,51 @@ describe ApacheLog::Parser do
78
78
  end
79
79
 
80
80
  it 'can parse tab separated custom format log based on combined format' do
81
- line = "203.0.113.254\t-\t-\t[07/Feb/2011:10:59:59 +0900]\t\"GET /x/i.cgi/movie/0001/-0002 HTTP/1.1\"\t200\t14462\t\"http://headlines.yahoo.co.jp/hl\"\t\"DoCoMo/2.0 F08A3(c500;TB;W30H20)\"\t\"virtualhost.example.jp\"\t\"192.0.2.16794832933550\"\t\"09011112222333_xx.ezweb.ne.jp\"\t533593";
81
+ line = "192.168.0.1\t-\t-\t[07/Feb/2011:10:59:59 +0900]\t\"GET /x/i.cgi/movie/0001/-0002 HTTP/1.1\"\t200\t14462\t\"http://headlines.yahoo.co.jp/hl\"\t\"DoCoMo/2.0 F08A3(c500;TB;W30H20)\"\t\"virtualhost.example.jp\"\t\"192.0.2.16794832933550\"\t\"09011112222333_xx.ezweb.ne.jp\"\t533593";
82
82
  parser = ApacheLog::Parser.new('combined', %w(vhost usertrack mobileid request_duration))
83
83
  entity = parser.parse(line.chomp)
84
- expect = {remote_host: '203.0.113.254', identity_check: '-', user: '-', datetime: DateTime.new(2011, 2, 7, 10, 59, 59, 0.375),
84
+ expect = {remote_host: '192.168.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2011, 2, 7, 10, 59, 59, 0.375),
85
85
  request: {method: 'GET', path: '/x/i.cgi/movie/0001/-0002', protocol: 'HTTP/1.1'}, status: '200', size: '14462', referer: 'http://headlines.yahoo.co.jp/hl',
86
86
  user_agent: 'DoCoMo/2.0 F08A3(c500;TB;W30H20)', vhost: 'virtualhost.example.jp',
87
87
  usertrack: '192.0.2.16794832933550', mobileid: '09011112222333_xx.ezweb.ne.jp', request_duration: '533593'}
88
88
  expect(entity).to eq(expect)
89
89
  end
90
+
91
+ it 'can parse even if there are any columns at the beginning of line' do
92
+ line = 'foo 127.0.0.1 - - [20/May/2014:20:04:04 +0900] "GET /test/indx.html HTTP/1.1" 200 4576'
93
+ parser = ApacheLog::Parser.new('common')
94
+ entity = parser.parse(line.chomp)
95
+ expect = {remote_host: '127.0.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2014, 5, 20, 20, 04, 04, 0.375),
96
+ request: {method: 'GET', path: '/test/indx.html', protocol: 'HTTP/1.1'}, status: '200', size: '4576'}
97
+ expect(entity).to eq(expect)
98
+ end
99
+
100
+ it 'can parse even if there are any columns at the beginning of line' do
101
+ line = '200 127.0.0.1 - - [20/May/2014:20:04:04 +0900] "GET /test/indx.html HTTP/1.1" 200 4576'
102
+ parser = ApacheLog::Parser.new('common')
103
+ entity = parser.parse(line.chomp)
104
+ expect = {remote_host: '127.0.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2014, 5, 20, 20, 04, 04, 0.375),
105
+ request: {method: 'GET', path: '/test/indx.html', protocol: 'HTTP/1.1'}, status: '200', size: '4576'}
106
+ expect(entity).to eq(expect)
107
+ end
108
+
109
+ it 'can parse even if there are any columns at the beginning of line' do
110
+ line = '200 foo 192.168.0.1 - - [07/Jun/2014:14:58:55 +0900] "GET /category/electronics HTTP/1.1" 200 128 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"'
111
+ parser = ApacheLog::Parser.new('combined')
112
+ entity = parser.parse(line.chomp)
113
+ expect = {remote_host: '192.168.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2014, 6, 7, 14, 58, 55, 0.375),
114
+ request: {method: 'GET', path: '/category/electronics', protocol: 'HTTP/1.1'}, status: '200', size: '128', referer: '-',
115
+ user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1'}
116
+ expect(entity).to eq(expect)
117
+ end
118
+
119
+ it 'can parse even if there are any columns at the end of line' do
120
+ line = '192.168.0.1 - - [07/Jun/2014:14:58:55 +0900] "GET /category/electronics HTTP/1.1" 200 128 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"'
121
+ parser = ApacheLog::Parser.new('combined')
122
+ entity = parser.parse(line.chomp)
123
+ expect = {remote_host: '192.168.0.1', identity_check: '-', user: '-', datetime: DateTime.new(2014, 6, 7, 14, 58, 55, 0.375),
124
+ request: {method: 'GET', path: '/category/electronics', protocol: 'HTTP/1.1'}, status: '200', size: '128', referer: '-',
125
+ user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1'}
126
+ expect(entity).to eq(expect)
127
+ end
90
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apache_log-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichi Takada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-11 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler