Re: Logging down output from the a Lua script

2021-03-05 Thread Mihaly Zachar
On Fri, 5 Mar 2021 at 11:53, Adis Nezirovic  wrote:

> On 3/4/21 9:47 PM, Mihaly Zachar wrote:
> > If I do this:
> > applet:set_var('txn.myvar', 'myvar_value')
> >
> > Then in the HAProxy layer I can reach the variable with %[var(txn.myvar)]
> > So it DOES work !
> > But Is this safe ? Did I do it well or I was just lucky ?
>
> Actions expose 'txn', while services expose full 'applet' object, so I
> do think it works as intended, it's not an accident. You are using Lua
> service for redirection?
>

Hi Adis,

Ok, thanks for the confirmation.
Yes, I did build a small webservice using HAproxy + Lua.
Sometimes it does send back 200 Ok with some content, sometimes it sends
back 302 based on some logic, it depends on the request.
It controls device provisioning.

Thanks,
Misi


Re: Logging down output from the a Lua script

2021-03-04 Thread Mihaly Zachar
On Thu, 4 Mar 2021 at 13:49, Adis Nezirovic  wrote:

> On 3/4/21 1:39 PM, Mihaly Zachar wrote:
> > Dear Adis,
> >
> > Thank you very much for the prompt answer. It looks promising.
> > Yes, I do have the TXN object available.
> >
> > Currently I am checking the doc here:
> > http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#8.2.4
> > <http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#8.2.4>
> >
> > How can I use the sent back variable I don't see that in the variable
> > table :(
> >
> > Thank
>
>
> You have a few examples in our blog post:
> https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/
>
> Basically, like using variables in HAProxy config, you need to set
> variable name using "scope.name" syntax, e.g. in the example scope is
> "req" (request), variable value is false.
>
> txn:set_var('req.blocked', false)
>
> Then, it should be able to log that variable by adding a block in
> log-format (no need to "capture" anything or similar):
>
> log-format "%{+Q}[var(txn.MyVar)]"
>
> A few blog posts about logging:
> https://www.haproxy.com/blog/introduction-to-haproxy-logging/
> https://www.haproxy.com/blog/haproxy-log-customization/
>
>
Hi Adis,

I was a bit too quick in the afternoon. I tried the thing from where I have
the TXN object available but it turned out that at that point I do not have
the result yet.
I also have a callback function registered with core.register_service(),
where I have the result I need to send back to the HAProxy layer.

It seems that this callback gets an AppletHTTP object. This object also has
a set_var() method.

If I do this:
applet:set_var('txn.myvar', 'myvar_value')

Then in the HAProxy layer I can reach the variable with %[var(txn.myvar)]
So it DOES work !
But Is this safe ? Did I do it well or I was just lucky ?

Thanks,
Misi


Re: Logging down output from the a Lua script

2021-03-04 Thread Mihaly Zachar
On Thu, 4 Mar 2021 at 13:49, Adis Nezirovic  wrote:

> On 3/4/21 1:39 PM, Mihaly Zachar wrote:
> > Dear Adis,
> >
> > Thank you very much for the prompt answer. It looks promising.
> > Yes, I do have the TXN object available.
> >
> > Currently I am checking the doc here:
> > http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#8.2.4
> > <http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#8.2.4>
> >
> > How can I use the sent back variable I don't see that in the variable
> > table :(
> >
> > Thank
>
>
> You have a few examples in our blog post:
> https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/
>
> Basically, like using variables in HAProxy config, you need to set
> variable name using "scope.name" syntax, e.g. in the example scope is
> "req" (request), variable value is false.
>
> txn:set_var('req.blocked', false)
>
> Then, it should be able to log that variable by adding a block in
> log-format (no need to "capture" anything or similar):
>
> log-format "%{+Q}[var(txn.MyVar)]"
>
> A few blog posts about logging:
> https://www.haproxy.com/blog/introduction-to-haproxy-logging/
> https://www.haproxy.com/blog/haproxy-log-customization/



Dear Adis,

Sorry, my previous email was sent to you rather than to the list.
Thank you very much, this is what I did look for !

Great stuff, happy days.

Thanks,
Misi


Re: Logging down output from the a Lua script

2021-03-04 Thread Mihaly Zachar
On Thu, 4 Mar 2021 at 12:14, Mihaly Zachar  wrote:

> Hi All,
>
> I wrote a small HTTP redirect server using HAProxy and Lua.
> My question is thet is it possible to log down a value coming from the Lua
> script somehow ?
>
> I am wondering if maybe we can use the "capture" method or something
> similar.
>
> I have not found anything in the docs unfortunately, but I am still hoping
> that I missed a possibility.
>
> Thanks in advance.
>
> Regards,
> Misi
>


Sorry, the above might be misunderstood.

I would like to log from the frontend, because some timer values are
available only there.
So I know that I can send log from the Lua script using core.log() but I
need to have the information in the frontend.

 Thanks,
Misi


Logging down output from the a Lua script

2021-03-04 Thread Mihaly Zachar
Hi All,

I wrote a small HTTP redirect server using HAProxy and Lua.
My question is thet is it possible to log down a value coming from the Lua
script somehow ?

I am wondering if maybe we can use the "capture" method or something
similar.

I have not found anything in the docs unfortunately, but I am still hoping
that I missed a possibility.

Thanks in advance.

Regards,
Misi