Skip to content

Commit fc86100

Browse files
committed
Support TIMESTAMP_ISO8601 in HAProxy patterns
Rsyslog (and probably others) can be configured to use ISO8601 timestamps, usually high-precision with microsecond resolution. The HAProxy patterns should take this possibility into account and not be arbitrarily limited to just SYSLOGTIMESTAMP.
1 parent d074466 commit fc86100

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

patterns/haproxy

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ HAPROXYCAPTUREDRESPONSEHEADERS %{DATA:captured_response_headers}
1313

1414
# Example:
1515
# These haproxy config lines will add data to the logs that are captured
16-
# by the patterns below. Place them in your custom patterns directory to
17-
# override the defaults.
16+
# by the patterns below. Place them in your custom patterns directory to
17+
# override the defaults.
1818
#
1919
# capture request header Host len 40
2020
# capture request header X-Forwarded-For len 50
@@ -26,14 +26,14 @@ HAPROXYCAPTUREDRESPONSEHEADERS %{DATA:captured_response_headers}
2626
# capture response header Content-Encoding len 10
2727
# capture response header Cache-Control len 200
2828
# capture response header Last-Modified len 200
29-
#
29+
#
3030
# HAPROXYCAPTUREDREQUESTHEADERS %{DATA:request_header_host}\|%{DATA:request_header_x_forwarded_for}\|%{DATA:request_header_accept_language}\|%{DATA:request_header_referer}\|%{DATA:request_header_user_agent}
3131
# HAPROXYCAPTUREDRESPONSEHEADERS %{DATA:response_header_content_type}\|%{DATA:response_header_content_encoding}\|%{DATA:response_header_cache_control}\|%{DATA:response_header_last_modified}
3232

33-
# parse a haproxy 'httplog' line
33+
# parse a haproxy 'httplog' line
3434
HAPROXYHTTPBASE %{IP:client_ip}:%{INT:client_port} \[%{HAPROXYDATE:accept_date}\] %{NOTSPACE:frontend_name} %{NOTSPACE:backend_name}/%{NOTSPACE:server_name} %{INT:time_request}/%{INT:time_queue}/%{INT:time_backend_connect}/%{INT:time_backend_response}/%{NOTSPACE:time_duration} %{INT:http_status_code} %{NOTSPACE:bytes_read} %{DATA:captured_request_cookie} %{DATA:captured_response_cookie} %{NOTSPACE:termination_state} %{INT:actconn}/%{INT:feconn}/%{INT:beconn}/%{INT:srvconn}/%{NOTSPACE:retries} %{INT:srv_queue}/%{INT:backend_queue} (\{%{HAPROXYCAPTUREDREQUESTHEADERS}\})?( )?(\{%{HAPROXYCAPTUREDRESPONSEHEADERS}\})?( )?"(<BADREQ>|(%{WORD:http_verb} (%{URIPROTO:http_proto}://)?(?:%{USER:http_user}(?::[^@]*)?@)?(?:%{URIHOST:http_host})?(?:%{URIPATHPARAM:http_request})?( HTTP/%{NUMBER:http_version})?))?"
3535

36-
HAPROXYHTTP %{SYSLOGTIMESTAMP:syslog_timestamp} %{IPORHOST:syslog_server} %{SYSLOGPROG}: %{HAPROXYHTTPBASE}
36+
HAPROXYHTTP %{SYSLOGTIMESTAMP:syslog_timestamp}|%{TIMESTAMP_ISO8601:timestamp8601} %{IPORHOST:syslog_server} %{SYSLOGPROG}: %{HAPROXYHTTPBASE}
3737

3838
# parse a haproxy 'tcplog' line
39-
HAPROXYTCP %{SYSLOGTIMESTAMP:syslog_timestamp} %{IPORHOST:syslog_server} %{SYSLOGPROG}: %{IP:client_ip}:%{INT:client_port} \[%{HAPROXYDATE:accept_date}\] %{NOTSPACE:frontend_name} %{NOTSPACE:backend_name}/%{NOTSPACE:server_name} %{INT:time_queue}/%{INT:time_backend_connect}/%{NOTSPACE:time_duration} %{NOTSPACE:bytes_read} %{NOTSPACE:termination_state} %{INT:actconn}/%{INT:feconn}/%{INT:beconn}/%{INT:srvconn}/%{NOTSPACE:retries} %{INT:srv_queue}/%{INT:backend_queue}
39+
HAPROXYTCP %{SYSLOGTIMESTAMP:syslog_timestamp}|%{TIMESTAMP_ISO8601:timestamp8601} %{IPORHOST:syslog_server} %{SYSLOGPROG}: %{IP:client_ip}:%{INT:client_port} \[%{HAPROXYDATE:accept_date}\] %{NOTSPACE:frontend_name} %{NOTSPACE:backend_name}/%{NOTSPACE:server_name} %{INT:time_queue}/%{INT:time_backend_connect}/%{NOTSPACE:time_duration} %{NOTSPACE:bytes_read} %{NOTSPACE:termination_state} %{INT:actconn}/%{INT:feconn}/%{INT:beconn}/%{INT:srvconn}/%{NOTSPACE:retries} %{INT:srv_queue}/%{INT:backend_queue}

spec/patterns/haproxy_spec.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,23 @@
88

99
context "Parsing HAPROXY log line from raw syslog line" do
1010

11-
let(:value) { 'Dec 9 13:01:26 localhost haproxy[28029]: 127.0.0.1:39759 [09/Dec/2013:12:59:46.633] loadbalancer default/instance8 0/51536/1/48082/99627 200 83285 - - ---- 87/87/87/1/0 0/67 {77.24.148.74} "GET /path/to/image HTTP/1.1"' }
11+
let(:value) { 'Dec 9 13:01:26 localhost haproxy[28029]: 127.0.0.1:39759 [09/Dec/2013:12:59:46.633] loadbalancer default/instance8 0/51536/1/48082/99627 200 83285 - - ---- 87/87/87/1/0 0/67 {77.24.148.74} "GET /path/to/image HTTP/1.1"' }
12+
subject { grok_match(haproxyhttp_pattern, value) }
13+
14+
it { should include("program" => "haproxy") }
15+
it { should include("client_ip" => "127.0.0.1") }
16+
it { should include("http_verb" => "GET") }
17+
it { should include("server_name" => "instance8") }
18+
19+
it "generates a message field" do
20+
expect(subject["message"]).to include("loadbalancer default/instance8")
21+
end
22+
23+
end
24+
25+
context "Parsing HAPROXY log line from raw syslog line with ISO8601 timestamp" do
26+
27+
let(:value) { '2015-08-26T02:09:48+02:00 localhost haproxy[28029]: 127.0.0.1:39759 [09/Dec/2013:12:59:46.633] loadbalancer default/instance8 0/51536/1/48082/99627 200 83285 - - ---- 87/87/87/1/0 0/67 {77.24.148.74} "GET /path/to/image HTTP/1.1"' }
1228
subject { grok_match(haproxyhttp_pattern, value) }
1329

1430
it { should include("program" => "haproxy") }
@@ -26,7 +42,7 @@
2642

2743
context "Parsing HAPROXY log line without syslog specific enteries. This mimics an event coming from a syslog input." do
2844

29-
let(:value) { '127.0.0.1:39759 [09/Dec/2013:12:59:46.633] loadbalancer default/instance8 0/51536/1/48082/99627 200 83285 - - ---- 87/87/87/1/0 0/67 {77.24.148.74} "GET /path/to/image HTTP/1.1"' }
45+
let(:value) { '127.0.0.1:39759 [09/Dec/2013:12:59:46.633] loadbalancer default/instance8 0/51536/1/48082/99627 200 83285 - - ---- 87/87/87/1/0 0/67 {77.24.148.74} "GET /path/to/image HTTP/1.1"' }
3046
subject { grok_match(haproxyhttpbase_pattern, value) }
3147

3248
# Assume 'program' would be matched by the syslog input.

0 commit comments

Comments
 (0)