haproxy_log_parser 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdee7790396094ba841e7a79fda38388fddd31a6
4
- data.tar.gz: 77f1cfd3fbe289140fe605dc8092ac38def83fb0
3
+ metadata.gz: 82510f6d05e2f12c1f2fdb34da5c49bfbfe7c416
4
+ data.tar.gz: 5099552b7e372eae22dc135d2234e74780cbd24f
5
5
  SHA512:
6
- metadata.gz: 92830fae50828e5422a120884f24c7ce5c64c2e8904fd3c6f3846e1e3d5224e028b89243abffe28913ed78773a70cbd4c68816efdbac8b794078ea408ffa50a1
7
- data.tar.gz: 64254fac5285600842b6dd81b480f3ad5e8428558e7d92ef231b2b5ef4c0ad9e41e91c9b67196b65980242b880235e7dbb4fb4fbfe730257fc8056000f48b1c1
6
+ metadata.gz: ea79ad889e8b96dffb7cadb627ff419faa931f6abcc37ce3d82d31ca69506f2a52eaae26848bae953e53aec9e4a51bd2f4c737c85a579e9b8798446870e2a342
7
+ data.tar.gz: 45f033eb110c98d4e0018d02b9aa8cad1b3533e4f8c01304e31b18a62de77eea4450e76440bd84713ea2842904ec3f73d1bfa0e4e806fbd624054556a972e1ed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1.0
@@ -2,7 +2,7 @@ module HAProxyLogParser
2
2
  grammar Line
3
3
  rule line
4
4
  syslog_portion:([^\[]+ '[' integer ']: ')
5
- client_ip:ip4_address ':' client_port:integer ' '
5
+ client_ip:ip_address ':' client_port:integer ' '
6
6
  '[' accept_date '] '
7
7
  suffix:(normal_suffix / error_suffix)
8
8
  "\n"?
@@ -38,8 +38,60 @@ module HAProxyLogParser
38
38
  ([0-9] 2..2 ':') 2..2 ([0-9] 2..2)
39
39
  end
40
40
 
41
+ rule ip_address
42
+ # Asserting port is a little hacky but required because of the way
43
+ # HAProxy writes IPv6 addresses in the logs. It uses a valid RFC5952
44
+ # method of IP:PORT, but this complicates things by having valid IP:PORT
45
+ # combos that are themselves valid IPv6 addresses.
46
+ # e.g. 1::2:123
47
+ ip4_address / ip6_address_assert_port
48
+ end
49
+
41
50
  rule ip4_address
42
- ([0-9] 1..3 '.') 3..3 ([0-9] 1..3)
51
+ dec_octet '.' dec_octet '.' dec_octet '.' dec_octet
52
+ end
53
+
54
+ rule colon_port
55
+ ':' integer ' '
56
+ end
57
+
58
+ rule ip6_address_assert_port
59
+ # Taken from https://tools.ietf.org/html/rfc3986#section-3.2.2
60
+ # Performs look-ahead assertion on the port, assuming format IP:PORT
61
+ ( h16 ':' ) 6..6 ls32 &colon_port
62
+ / '::' ( h16 ':' ) 5..5 ls32 &colon_port
63
+ / ( h16 )? '::' ( h16 ':' ) 4..4 ls32 &colon_port
64
+ / ( h16 ( ':' h16 ) ..1 )? '::' ( h16 ':' ) 3..3 ls32 &colon_port
65
+ / ( h16 ( ':' h16 ) ..2 )? '::' ( h16 ':' ) 2..2 ls32 &colon_port
66
+ / ( h16 ( ':' h16 ) ..3 )? '::' h16 ':' ls32 &colon_port
67
+ / ( h16 ( ':' h16 ) ..4 )? '::' ls32 &colon_port
68
+ / ( h16 ( ':' h16 ) ..5 )? '::' h16 &colon_port
69
+ / ( h16 ( ':' h16 ) ..6 )? '::' &colon_port
70
+ end
71
+
72
+ rule ls32
73
+ # least-significant 32 bits of address
74
+ ( h16 ':' h16 ) / ip4_address
75
+ end
76
+
77
+ rule h16
78
+ # 16 bits of address represented in hexadecimal
79
+ hex_digit 1..4
80
+ end
81
+
82
+ rule hex_digit
83
+ [a-f0-9A-F]
84
+ end
85
+
86
+ rule dec_octet
87
+ '25' [0-5]
88
+ / '2' [0-4] dec_digit
89
+ / '1' dec_digit 2..2
90
+ / dec_digit 1..2
91
+ end
92
+
93
+ rule dec_digit
94
+ [0-9]
43
95
  end
44
96
 
45
97
  rule accept_date
@@ -6,6 +6,9 @@ RSpec.describe HAProxyLogParser do
6
6
  map { |line| line.split(',', 2) }
7
7
  ]
8
8
 
9
+ TEST_IP_ADDRESSES = IO.readlines(File.join(File.dirname(__FILE__), 'test_ips.log')).
10
+ map { |line| line.chomp }
11
+
9
12
  describe '.parse' do
10
13
  it 'parses the good1 case correctly' do
11
14
  entry = HAProxyLogParser.parse(LINES['good1'])
@@ -69,6 +72,39 @@ RSpec.describe HAProxyLogParser do
69
72
  expect(entry.http_request).to eq('GET /images/image.gif HTTP/1.1')
70
73
  end
71
74
 
75
+ TEST_IP_ADDRESSES.each do |test_ip|
76
+ it "parses generic case with test IP #{test_ip} correctly" do
77
+ entry = HAProxyLogParser.parse(LINES['generic_ip_test'].sub(/IPADDRESS/, test_ip))
78
+ expect(entry.client_ip).to eq(test_ip)
79
+ expect(entry.client_port).to eq(50679)
80
+ expect(entry.accept_date).to eq(Time.local(2012, 5, 21, 1, 35, 46, 146))
81
+ expect(entry.frontend_name).to eq('webapp')
82
+ expect(entry).to_not be_ssl
83
+ expect(entry.backend_name).to eq('webapp_backend')
84
+ expect(entry.server_name).to eq('web09')
85
+ expect(entry.tq).to eq(27)
86
+ expect(entry.tw).to eq(0)
87
+ expect(entry.tc).to eq(1)
88
+ expect(entry.tr).to eq(0)
89
+ expect(entry.tt).to eq(217)
90
+ expect(entry.status_code).to eq(200)
91
+ expect(entry.bytes_read).to eq(1367)
92
+ expect(entry.captured_request_cookie).to eq({'session' => 'abc'})
93
+ expect(entry.captured_response_cookie).to eq({'session' => 'xyz'})
94
+ expect(entry.termination_state).to eq('----')
95
+ expect(entry.actconn).to eq(600)
96
+ expect(entry.feconn).to eq(529)
97
+ expect(entry.beconn).to eq(336)
98
+ expect(entry.srv_conn).to eq(158)
99
+ expect(entry.retries).to eq(0)
100
+ expect(entry.srv_queue).to eq(0)
101
+ expect(entry.backend_queue).to eq(0)
102
+ expect(entry.captured_request_headers).to eq(['|| {5F41}', 'http://google.com/', ''])
103
+ expect(entry.captured_response_headers).to eq([])
104
+ expect(entry.http_request).to eq('GET /images/image.gif HTTP/1.1')
105
+ end
106
+ end
107
+
72
108
  it 'parses connection error lines correctly' do
73
109
  entry = HAProxyLogParser.parse(LINES['error1'])
74
110
  expect(entry.client_ip).to eq('127.0.0.1')
@@ -1,3 +1,4 @@
1
1
  good1,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
  good2,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"
3
+ generic_ip_test,May 21 01:35:46 10.18.237.5 haproxy[26747]: IPADDRESS: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"
3
4
  error1,Dec 3 18:27:14 localhost haproxy[6103]: 127.0.0.1:56059 [03/Dec/2012:17:35:10.380] frt/f1: Connection error during SSL handshake
@@ -0,0 +1,16 @@
1
+ 12::3a:829
2
+ 123.41.31.2
3
+ 127.0.0.1
4
+ 2.3.4.50
5
+ 2001:db8::42:8329
6
+ ::ffff:192.0.2.128
7
+ 2001:0db8:85a3:08d3:1319:8a2e:0370:7334
8
+ 201:0db8:85a3::1319:8a2e:0370:7344
9
+ 2001:0DB8:0::0:1428:57ab
10
+ 2001:0DB8::1428:57ab
11
+ ::ffff:192.168.89.9
12
+ ::ffff:c0a8:5909
13
+ ::1.2.3.4
14
+ ::c0a8:5909
15
+ ::192.0.2.128
16
+ 1::2:123
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haproxy_log_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Hsieh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop
@@ -56,6 +56,7 @@ files:
56
56
  - lib/haproxy_log_parser/line.treetop
57
57
  - spec/haproxy_log_parser_spec.rb
58
58
  - spec/sample.log
59
+ - spec/test_ips.log
59
60
  homepage: https://github.com/tobyhs/haproxy_log_parser
60
61
  licenses:
61
62
  - MIT
@@ -76,10 +77,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  version: '0'
77
78
  requirements: []
78
79
  rubyforge_project:
79
- rubygems_version: 2.6.8
80
+ rubygems_version: 2.6.11
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: Parser for HAProxy logs in the HTTP log format
83
84
  test_files:
84
85
  - spec/haproxy_log_parser_spec.rb
85
86
  - spec/sample.log
87
+ - spec/test_ips.log