haproxy_log_parser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/haproxy_log_parser.gemspec +2 -1
- data/lib/haproxy_log_parser/line.treetop +2 -4
- data/lib/haproxy_log_parser.rb +9 -1
- data/spec/haproxy_log_parser_spec.rb +53 -53
- data/spec/sample.log +1 -1
- metadata +11 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/haproxy_log_parser.gemspec
CHANGED
@@ -5,10 +5,11 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.homepage = 'https://github.com/tobyhs/haproxy_log_parser'
|
6
6
|
s.summary = 'Parser for HAProxy logs in the HTTP log format'
|
7
7
|
s.description = s.summary
|
8
|
+
s.license = 'MIT'
|
8
9
|
|
9
10
|
s.add_dependency 'treetop'
|
10
11
|
|
11
|
-
s.add_development_dependency 'rspec'
|
12
|
+
s.add_development_dependency 'rspec', '~> 2.13'
|
12
13
|
|
13
14
|
s.files = Dir.glob('lib/**/*') + [
|
14
15
|
'README.rdoc',
|
@@ -15,8 +15,8 @@ module HAProxyLogParser
|
|
15
15
|
actconn:integer '/' feconn:integer '/' beconn:integer '/'
|
16
16
|
srv_conn:integer '/' retries:integer ' '
|
17
17
|
srv_queue:integer '/' backend_queue:integer ' '
|
18
|
-
'{'
|
19
|
-
'{'
|
18
|
+
captured_request_headers:('{' headers:captured_headers '} ')?
|
19
|
+
captured_response_headers:('{' headers:captured_headers '} ')?
|
20
20
|
'"' http_request:[^"]+ '"'
|
21
21
|
"\n"?
|
22
22
|
end
|
@@ -54,5 +54,3 @@ module HAProxyLogParser
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
58
|
-
# vim:ai
|
data/lib/haproxy_log_parser.rb
CHANGED
@@ -39,10 +39,18 @@ module HAProxyLogParser
|
|
39
39
|
cookie = decode_captured_cookie(result.send(field).text_value)
|
40
40
|
entry.send("#{field}=", cookie)
|
41
41
|
end
|
42
|
+
|
42
43
|
[:captured_request_headers, :captured_response_headers].each do |field|
|
43
|
-
|
44
|
+
if result.send(field).respond_to?(:headers)
|
45
|
+
headers = decode_captured_headers(
|
46
|
+
result.send(field).headers.text_value
|
47
|
+
)
|
48
|
+
else
|
49
|
+
headers = []
|
50
|
+
end
|
44
51
|
entry.send("#{field}=", headers)
|
45
52
|
end
|
53
|
+
|
46
54
|
entry.http_request = unescape(result.http_request.text_value)
|
47
55
|
|
48
56
|
entry
|
@@ -7,68 +7,68 @@ describe HAProxyLogParser do
|
|
7
7
|
describe '.parse' do
|
8
8
|
it 'parses LINE[0] correctly' do
|
9
9
|
entry = HAProxyLogParser.parse(LINES[0])
|
10
|
-
entry.client_ip.
|
11
|
-
entry.client_port.
|
12
|
-
entry.accept_date.
|
13
|
-
entry.frontend_name.
|
10
|
+
expect(entry.client_ip).to eq('10.0.8.2')
|
11
|
+
expect(entry.client_port).to eq(34028)
|
12
|
+
expect(entry.accept_date).to eq(Time.local(2011, 8, 9, 20, 30, 46, 429))
|
13
|
+
expect(entry.frontend_name).to eq('proxy-out')
|
14
14
|
expect(entry).to be_ssl
|
15
|
-
entry.backend_name.
|
16
|
-
entry.server_name.
|
17
|
-
entry.tq.
|
18
|
-
entry.tw.
|
19
|
-
entry.tc.
|
20
|
-
entry.tr.
|
21
|
-
entry.tt.
|
22
|
-
entry.status_code.
|
23
|
-
entry.bytes_read.
|
24
|
-
entry.captured_request_cookie.
|
25
|
-
entry.captured_response_cookie.
|
26
|
-
entry.termination_state.
|
27
|
-
entry.actconn.
|
28
|
-
entry.feconn.
|
29
|
-
entry.beconn.
|
30
|
-
entry.srv_conn.
|
31
|
-
entry.retries.
|
32
|
-
entry.srv_queue.
|
33
|
-
entry.backend_queue.
|
34
|
-
entry.captured_request_headers.
|
35
|
-
entry.captured_response_headers.
|
36
|
-
entry.http_request.
|
15
|
+
expect(entry.backend_name).to eq('proxy-out')
|
16
|
+
expect(entry.server_name).to eq('cache1')
|
17
|
+
expect(entry.tq).to eq(1)
|
18
|
+
expect(entry.tw).to eq(0)
|
19
|
+
expect(entry.tc).to eq(2)
|
20
|
+
expect(entry.tr).to eq(126)
|
21
|
+
expect(entry.tt).to eq(128)
|
22
|
+
expect(entry.status_code).to eq(301)
|
23
|
+
expect(entry.bytes_read).to eq(223)
|
24
|
+
expect(entry.captured_request_cookie).to eq({})
|
25
|
+
expect(entry.captured_response_cookie).to eq({})
|
26
|
+
expect(entry.termination_state).to eq('----')
|
27
|
+
expect(entry.actconn).to eq(617)
|
28
|
+
expect(entry.feconn).to eq(523)
|
29
|
+
expect(entry.beconn).to eq(336)
|
30
|
+
expect(entry.srv_conn).to eq(168)
|
31
|
+
expect(entry.retries).to eq(0)
|
32
|
+
expect(entry.srv_queue).to eq(0)
|
33
|
+
expect(entry.backend_queue).to eq(0)
|
34
|
+
expect(entry.captured_request_headers).to eq(['www.sytadin.equipement.gouv.fr', '', 'http://trafic.1wt.eu/'])
|
35
|
+
expect(entry.captured_response_headers).to eq(['Apache', '230', '', '', 'http://www.sytadin.'])
|
36
|
+
expect(entry.http_request).to eq('GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1')
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'parses LINES[1] correctly' do
|
40
40
|
entry = HAProxyLogParser.parse(LINES[1])
|
41
|
-
entry.client_ip.
|
42
|
-
entry.client_port.
|
43
|
-
entry.accept_date.
|
44
|
-
entry.frontend_name.
|
41
|
+
expect(entry.client_ip).to eq('192.168.1.215')
|
42
|
+
expect(entry.client_port).to eq(50679)
|
43
|
+
expect(entry.accept_date).to eq(Time.local(2012, 5, 21, 1, 35, 46, 146))
|
44
|
+
expect(entry.frontend_name).to eq('webapp')
|
45
45
|
expect(entry).to_not be_ssl
|
46
|
-
entry.backend_name.
|
47
|
-
entry.server_name.
|
48
|
-
entry.tq.
|
49
|
-
entry.tw.
|
50
|
-
entry.tc.
|
51
|
-
entry.tr.
|
52
|
-
entry.tt.
|
53
|
-
entry.status_code.
|
54
|
-
entry.bytes_read.
|
55
|
-
entry.captured_request_cookie.
|
56
|
-
entry.captured_response_cookie.
|
57
|
-
entry.termination_state.
|
58
|
-
entry.actconn.
|
59
|
-
entry.feconn.
|
60
|
-
entry.beconn.
|
61
|
-
entry.srv_conn.
|
62
|
-
entry.retries.
|
63
|
-
entry.srv_queue.
|
64
|
-
entry.backend_queue.
|
65
|
-
entry.captured_request_headers.
|
66
|
-
entry.captured_response_headers.
|
67
|
-
entry.http_request.
|
46
|
+
expect(entry.backend_name).to eq('webapp_backend')
|
47
|
+
expect(entry.server_name).to eq('web09')
|
48
|
+
expect(entry.tq).to eq(27)
|
49
|
+
expect(entry.tw).to eq(0)
|
50
|
+
expect(entry.tc).to eq(1)
|
51
|
+
expect(entry.tr).to eq(0)
|
52
|
+
expect(entry.tt).to eq(217)
|
53
|
+
expect(entry.status_code).to eq(200)
|
54
|
+
expect(entry.bytes_read).to eq(1367)
|
55
|
+
expect(entry.captured_request_cookie).to eq({'session' => 'abc'})
|
56
|
+
expect(entry.captured_response_cookie).to eq({'session' => 'xyz'})
|
57
|
+
expect(entry.termination_state).to eq('----')
|
58
|
+
expect(entry.actconn).to eq(600)
|
59
|
+
expect(entry.feconn).to eq(529)
|
60
|
+
expect(entry.beconn).to eq(336)
|
61
|
+
expect(entry.srv_conn).to eq(158)
|
62
|
+
expect(entry.retries).to eq(0)
|
63
|
+
expect(entry.srv_queue).to eq(0)
|
64
|
+
expect(entry.backend_queue).to eq(0)
|
65
|
+
expect(entry.captured_request_headers).to eq(['|| {5F41}', 'http://google.com/', ''])
|
66
|
+
expect(entry.captured_response_headers).to eq([])
|
67
|
+
expect(entry.http_request).to eq('GET /images/image.gif HTTP/1.1')
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'returns nil if the line is invalid' do
|
71
|
-
HAProxyLogParser.parse('asdf jkl;').
|
71
|
+
expect(HAProxyLogParser.parse('asdf jkl;')).to be_nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
data/spec/sample.log
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
Aug 9 20:30:46 localhost haproxy[2022]: 10.0.8.2:34028 [09/Aug/2011:20:30:46.429] proxy-out~ proxy-out/cache1 1/0/2/126/+128 301 +223 - - ---- 617/523/336/168/0 0/0 {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} {Apache|230|||http://www.sytadin.} "GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1"
|
2
|
-
May 21 01:35:46 10.18.237.5 haproxy[26747]: 192.168.1.215:50679 [21/May/2012:01:35:46.146] webapp webapp_backend/web09 27/0/1/0/217 200 1367 session=abc session=xyz ---- 600/529/336/158/0 0/0 {#7C#7C #7B5F41#7D|http://google.com/|}
|
2
|
+
May 21 01:35:46 10.18.237.5 haproxy[26747]: 192.168.1.215:50679 [21/May/2012:01:35:46.146] webapp webapp_backend/web09 27/0/1/0/217 200 1367 session=abc session=xyz ---- 600/529/336/158/0 0/0 {#7C#7C #7B5F41#7D|http://google.com/|} "GET /images/image.gif HTTP/1.1"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haproxy_log_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Toby Hsieh
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-12-16 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -38,12 +38,13 @@ dependencies:
|
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 25
|
44
44
|
segments:
|
45
|
-
-
|
46
|
-
|
45
|
+
- 2
|
46
|
+
- 13
|
47
|
+
version: "2.13"
|
47
48
|
type: :development
|
48
49
|
version_requirements: *id002
|
49
50
|
description: Parser for HAProxy logs in the HTTP log format
|
@@ -65,8 +66,8 @@ files:
|
|
65
66
|
- spec/sample.log
|
66
67
|
has_rdoc: true
|
67
68
|
homepage: https://github.com/tobyhs/haproxy_log_parser
|
68
|
-
licenses:
|
69
|
-
|
69
|
+
licenses:
|
70
|
+
- MIT
|
70
71
|
post_install_message:
|
71
72
|
rdoc_options: []
|
72
73
|
|