Hello,

Le 24/09/2018 à 12:29, Franks Andy (IT Technical Architecture Manager) a écrit :

Sorry to be a nag, but anyone any ideas with this. Or is it just indicated to regularly parse log files (seems a bit of a hacky solution).

Thanks!

*From:*Franks Andy (IT Technical Architecture Manager) [mailto:andy.fra...@sath.nhs.uk]
*Sent:* 21 September 2018 13:20
*To:* haproxy@formilux.org
*Subject:* LUA and doing things

Hi all,

  Just hopefully a really quick question.. I would like to use LUA to, on connection use of a specific backend service, do something (like write an entry to a log file for example). I realise the example here is possibly locking etc but I’m not too worried at this point about that.

LUA seems, with my basic knowledge, to expect to do something to the traffic – for example I have this :

frontend test_84

  bind 0.0.0.0:84

  mode http

  default_backend bk_test_84

backend bk_test_84

  mode http

  stick on src table connections_test_84

  server localhost 127.0.0.1:80

I have a working lua script to do something like core.Alert(“hello world”).

The thing I would like to do is run this script without any effect on traffic – if I try and use ‘http-request’ or ‘stick on’ or similar keywords which can use lua scripts, they want me to program in some action that decides what criteria to stick on or what to do with that http-request. I just want something to “fire” and do nothing but run the lua script and carry on. Can I do it?

Please forgive my noobiness.

Thanks

Andy

I think you can find usefull documentation here : https://www.arpalert.org/haproxy-lua.html

concepts, API documentation ...

For your purpose why don't you just use :

backend bk_test_84
  mode http
  stick on src table connections_test_84
  http-request lua.myfunction
  server localhost 127.0.0.1:80

and in your lua file :

function myfunction(txn)

 //do what you want

end

core.register_action("myfunction", { "http-req" }, myfunction)

You have an exemple here : https://www.arpalert.org/src/haproxy-lua-api/1.7/index.html

core.register_action("hello-world", { "tcp-req", "http-req" }, function(txn)
   txn:Info("Hello world")
end)

with

frontend http_frt
  mode http
  http-request lua.hello-world

Reply via email to