haproxy_log_parser 0.0.4 → 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/LICENSE +21 -0
- data/README.md +10 -0
- data/VERSION +1 -1
- data/haproxy_log_parser.gemspec +3 -2
- data/lib/haproxy_log_parser/entry.rb +1 -1
- data/lib/haproxy_log_parser.rb +21 -14
- data/spec/haproxy_log_parser_spec.rb +6 -4
- data/spec/sample.log +1 -1
- metadata +49 -70
- data/README.rdoc +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f019630e3a37d631615874f51d00936ade7a58a2
|
4
|
+
data.tar.gz: c95c16a28cfc263e3b5f5b3310836b4afbf30094
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d9567c587f66a274e8fa1d829e59c42cb07969094061c0fe5cde805ca322114880c71d62ff18a88f9494f779fc04d4f132105d425d5c22aff3de6e8b95bfef8
|
7
|
+
data.tar.gz: 5d1d021bef436b3651e362a89ca555c1b3a8e3912bec57030a1bd3c76ad54d93f5fd5560df38460f9181bd36d232084e9020d28e254e0b319436735605d7d98b
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013, Toby Hsieh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# haproxy\_log\_parser
|
2
|
+
|
3
|
+
haproxy\_log\_parser is a gem that parses logs in HAProxy's HTTP log format.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
|
7
|
+
require 'haproxy_log_parser'
|
8
|
+
result = HAProxyLogParser.parse('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|||true} "GET /index.html HTTP/1.1"')
|
9
|
+
result.client_ip # => "10.0.8.2"
|
10
|
+
result.captured_response_headers # => ["Apache", "230", "", "", "true"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/haproxy_log_parser.gemspec
CHANGED
@@ -9,10 +9,11 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.add_dependency 'treetop'
|
11
11
|
|
12
|
-
s.add_development_dependency 'rspec', '~>
|
12
|
+
s.add_development_dependency 'rspec', '~> 3.5.0'
|
13
13
|
|
14
14
|
s.files = Dir.glob('lib/**/*') + [
|
15
|
-
'
|
15
|
+
'LICENSE',
|
16
|
+
'README.md',
|
16
17
|
'VERSION',
|
17
18
|
'haproxy_log_parser.gemspec'
|
18
19
|
]
|
data/lib/haproxy_log_parser.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
require 'treetop'
|
2
2
|
|
3
3
|
require 'haproxy_log_parser/entry'
|
4
|
-
|
5
|
-
Treetop.load(File.expand_path('haproxy_log_parser/line.treetop', File.dirname(__FILE__)))
|
4
|
+
require 'haproxy_log_parser/line'
|
6
5
|
|
7
6
|
module HAProxyLogParser
|
8
7
|
VERSION = IO.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).chomp.freeze
|
9
8
|
|
10
|
-
|
9
|
+
# Exception for failures when parsing lines
|
10
|
+
class ParseError < ::StandardError; end
|
11
11
|
|
12
12
|
class << self
|
13
13
|
# Returns an Entry object resulting from the given HAProxy HTTP-format log
|
14
|
-
# +line
|
14
|
+
# +line+.
|
15
15
|
#
|
16
|
-
# @param [String]
|
17
|
-
# @return [Entry
|
16
|
+
# @param line [String] a line from an HAProxy log
|
17
|
+
# @return [Entry]
|
18
|
+
# @raise [ParseError] if the line was not parsed successfully
|
18
19
|
def parse(line)
|
19
|
-
|
20
|
-
|
20
|
+
parser = LineParser.new
|
21
|
+
result = parser.parse(line)
|
22
|
+
|
23
|
+
unless result
|
24
|
+
raise ParseError, parser.failure_reason
|
25
|
+
end
|
21
26
|
|
22
27
|
entry = Entry.new
|
23
28
|
[
|
@@ -59,8 +64,8 @@ module HAProxyLogParser
|
|
59
64
|
# Returns the given string un-escaped. See the "Logging > Non-printable
|
60
65
|
# characters" section in HAProxy documentation.
|
61
66
|
#
|
62
|
-
# @param [String] string
|
63
|
-
# @return [String]
|
67
|
+
# @param string [String] string to unescape
|
68
|
+
# @return [String] an unescaped string
|
64
69
|
def unescape(string)
|
65
70
|
string.gsub(/#[[:xdigit:]]{2}/) do |match|
|
66
71
|
match[1..-1].to_i(16).chr
|
@@ -69,7 +74,7 @@ module HAProxyLogParser
|
|
69
74
|
|
70
75
|
# Converts the value of an accept_date field to a Time object.
|
71
76
|
#
|
72
|
-
# @param [String]
|
77
|
+
# @param string [String] value of an accept_date field
|
73
78
|
# @return [Time]
|
74
79
|
def parse_accept_date(string)
|
75
80
|
parts = string.split(/[\/:.]/)
|
@@ -78,8 +83,10 @@ module HAProxyLogParser
|
|
78
83
|
|
79
84
|
# Converts a captured cookie string to a Hash.
|
80
85
|
#
|
81
|
-
# @param [String] string
|
86
|
+
# @param string [String] a captured cookie string
|
82
87
|
# @return [Hash{String => String}]
|
88
|
+
# a one-entry Hash with the cookie name and value, or an empty Hash if no
|
89
|
+
# cookie was captured
|
83
90
|
def decode_captured_cookie(string)
|
84
91
|
if string == '-'
|
85
92
|
{}
|
@@ -91,8 +98,8 @@ module HAProxyLogParser
|
|
91
98
|
|
92
99
|
# Converts a captured headers string to an Array.
|
93
100
|
#
|
94
|
-
# @param [String]
|
95
|
-
# @return [Array<String>]
|
101
|
+
# @param string [String] a captured headers section
|
102
|
+
# @return [Array<String>] array of captured header values
|
96
103
|
def decode_captured_headers(string)
|
97
104
|
string.split('|', -1).map! { |header| unescape(header) }
|
98
105
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'haproxy_log_parser'
|
2
2
|
|
3
|
-
describe HAProxyLogParser do
|
3
|
+
RSpec.describe HAProxyLogParser do
|
4
4
|
# TODO Use something better instead of LINES[0], LINES[1], ...
|
5
5
|
LINES = IO.readlines(File.join(File.dirname(__FILE__), 'sample.log'))
|
6
6
|
|
@@ -33,7 +33,7 @@ describe HAProxyLogParser do
|
|
33
33
|
expect(entry.backend_queue).to eq(0)
|
34
34
|
expect(entry.captured_request_headers).to eq(['www.sytadin.equipement.gouv.fr', '', 'http://trafic.1wt.eu/'])
|
35
35
|
expect(entry.captured_response_headers).to eq(['Apache', '230', '', '', 'http://www.sytadin.'])
|
36
|
-
expect(entry.http_request).to eq('GET
|
36
|
+
expect(entry.http_request).to eq('GET / HTTP/1.1')
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'parses LINES[1] correctly' do
|
@@ -67,8 +67,10 @@ describe HAProxyLogParser do
|
|
67
67
|
expect(entry.http_request).to eq('GET /images/image.gif HTTP/1.1')
|
68
68
|
end
|
69
69
|
|
70
|
-
it '
|
71
|
-
|
70
|
+
it 'raises ParseError if the line is invalid' do
|
71
|
+
line = 'Aug 9 20:30:46 localhost haproxy[2022]: '
|
72
|
+
expect { HAProxyLogParser.parse(line) }.
|
73
|
+
to raise_error(HAProxyLogParser::ParseError)
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
data/spec/sample.log
CHANGED
@@ -1,2 +1,2 @@
|
|
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 - - LR-- 617/523/336/168/0 0/0 {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} {Apache|230|||http://www.sytadin.} "GET
|
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 - - LR-- 617/523/336/168/0 0/0 {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} {Apache|230|||http://www.sytadin.} "GET / HTTP/1.1"
|
2
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,103 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: haproxy_log_parser
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Toby Hsieh
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2016-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: treetop
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
27
17
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
33
20
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
21
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.5.0
|
48
34
|
type: :development
|
49
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.5.0
|
50
41
|
description: Parser for HAProxy logs in the HTTP log format
|
51
42
|
email:
|
52
43
|
executables: []
|
53
|
-
|
54
44
|
extensions: []
|
55
|
-
|
56
45
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
|
59
|
-
-
|
60
|
-
- lib/haproxy_log_parser/line.treetop
|
61
|
-
- lib/haproxy_log_parser.rb
|
62
|
-
- README.rdoc
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
63
49
|
- VERSION
|
64
50
|
- haproxy_log_parser.gemspec
|
51
|
+
- lib/haproxy_log_parser.rb
|
52
|
+
- lib/haproxy_log_parser/entry.rb
|
53
|
+
- lib/haproxy_log_parser/line.treetop
|
65
54
|
- spec/haproxy_log_parser_spec.rb
|
66
55
|
- spec/sample.log
|
67
|
-
has_rdoc: true
|
68
56
|
homepage: https://github.com/tobyhs/haproxy_log_parser
|
69
|
-
licenses:
|
57
|
+
licenses:
|
70
58
|
- MIT
|
59
|
+
metadata: {}
|
71
60
|
post_install_message:
|
72
61
|
rdoc_options: []
|
73
|
-
|
74
|
-
require_paths:
|
62
|
+
require_paths:
|
75
63
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
|
78
|
-
requirements:
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
79
66
|
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
version: "0"
|
85
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
|
-
requirements:
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
88
71
|
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
version: "0"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
94
74
|
requirements: []
|
95
|
-
|
96
75
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.5.1
|
98
77
|
signing_key:
|
99
|
-
specification_version:
|
78
|
+
specification_version: 4
|
100
79
|
summary: Parser for HAProxy logs in the HTTP log format
|
101
|
-
test_files:
|
80
|
+
test_files:
|
102
81
|
- spec/haproxy_log_parser_spec.rb
|
103
82
|
- spec/sample.log
|
data/README.rdoc
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
= haproxy_log_parser
|
2
|
-
|
3
|
-
haproxy_log_parser is a gem that uses Treetop to parse HAProxy logs in
|
4
|
-
HAProxy's HTTP log format.
|
5
|
-
|
6
|
-
== Example
|
7
|
-
|
8
|
-
require 'haproxy_log_parser'
|
9
|
-
result = HAProxyLogParser.parse('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"')
|
10
|
-
result.client_ip # => "10.0.8.2"
|
11
|
-
result.captured_response_headers # => ["Apache", "230", "", "", "http://www.sytadin."]
|