Goal
I am trying to output the full payload of the request as part of an error message, because I believe the requester is giving me a garbage payload. The original, working log was
setenv TCP_LOG "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"
log-format "${TCP_LOG} %[var(txn.sendercompid)] %[var(txn.errormessage)] %[var(txn.sendercompid)] %[var(txn.mapped_sendercompid)]"
tcp-request content set-var(txn.errormessage) str("ERROR: SenderCompID not in request") unless { var(txn.sendercompid) -m found }
This is exactly the standard tcp log format from HAProxy plus some strings we care about.
I want to change the value of txn.errormessage
to include the full request payload when it fails.
What I've tried so far:
tcp-request content set-var(txn.errormessage) str("ERROR: SenderCompID not in request %[req.payload(0,0),regsub(\001,|,g)]")
which fails with
> [ALERT] (1) : config : parsing [/bitnami/haproxy/conf/haproxy.cfg:44] : fetch method 'str' : expected ')' before ',0),regsub(\001,|,g)])'
and
tcp-request content set-var(txn.errormessage) req.payload(0,0)
which I believe logs the empty string in
$IP:43384 [11/Jul/2023:20:05:00.748] fix_listener fix_listener/ -1/-1/0 0 PR 1/1/0/0/0 0/0 - - -
Though I can see that I am being given a payload with
tcp-request content set-var(txn.errormessage) req.len
giving me
$IP:43536 [11/Jul/2023:20:25:26.805] fix_listener fix_listener/ -1/-1/0 0 PR 1/1/0/0/0 0/0 - 206 - -
$IP:43540 [11/Jul/2023:20:26:15.825] fix_listener fix_listener/ -1/-1/0 0 PR 1/1/0/0/0 0/0 - 206 - -
$IP:43544 [11/Jul/2023:20:27:04.879] fix_listener fix_listener/ -1/-1/0 0 PR 1/1/0/0/0 0/0 - 206 - -
The closest I could get to working was
tcp-request content set-var(txn.errormessage) req.payload(0,0),hex unless { var(txn.sendercompid) -m found }
Which outputs hex, and if I pipe it into xxd -r -p
I get a bunch of garbage with an IP address at the end.
I have read a decent amount of the docs, but the docs for tcp-request content set-var
(after redirecting to http-request set-var
) only describe the expression I can use as
<expr> Is a standard HAProxy expression formed by a sample-fetch
followed by some converters.
and there's no obvious section describing a standard HAProxy expression. I read through the quoting and escaping section and also didn't understand why I couldn't have a comma inside str()
.
Questions
- How do I quote / format
str("ERROR: SenderCompID not in request %[req.payload(0,0),regsub(\001,|,g)]")
correctly to be able to concatenate a string with a variable?
- Why doesn't setting
txn.errormessage
to req.payload(0,0)
print anything in my logs?
- What is the easiest way to print out the full payload of a request in a log statement?