On Tue, 29 Sep 2015 09:57:46 -0400
Michael Ezzell <[email protected]> wrote:

> We have "fetches" accessible from Lua, but I have not found a mechanism
> that allows me to access the value of log format variables.
> 
> Examples of useful variables:
> 
> %b   | backend_name
> %f   | frontend_name
> %rt  | request_counter
> 
> Is there a way to access values like these from Lua, since they aren't (as
> far as I can tell) available as fetches?
> 
> I realize not all variables would be available in every context, and I
> don't want to modify them, of course -- I only want to read them -- but I
> would like to be able to read them and use them in content generated in Lua.
> 
> Are they accessible?

Hi,

Sadly these information are not avalaible. In addition the 1.6.0
release is very close, so Willy freezes the features.

You can get the id of the current fontend/backend with the following
fetches:

   TXN.f.be_id
   TXN.f.fe_id

But it not the name. You have some ugly methods: The most ugly is
adding a request header containing the frontend / backend name, the Lua
permit to fetch headers.

So the HAProxy is like this:

   http-request add-header x-haproxy-fe-name %f
   http-request add-header x-haproxy-be-name %b

In the lua:

   TXN.f.req_fhdr("x-haproxy-fe-name")
   TXN.f.req_fhdr("x-haproxy-be-name")

Another way is use the vars, but we considers that the fe/be name must
be enter with manual input, like this:

   tcp-request content set-var(txn.be) name-of-the-current-backend
   tcp-request content set-var(txn.fe) name-of-the-current-frontend

In the Lua:

   TXN.f.var("txn.be")
   TXN.f.var("txn.be")

For the request counter is avalaible with this fetch:

   TXN.f.http_req_cnt

Thierry

Reply via email to