Skip to content

Instantly share code, notes, and snippets.

@esseti
Last active July 1, 2022 18:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esseti/477b3cd0d66182fa93d7fca8136336cd to your computer and use it in GitHub Desktop.
Save esseti/477b3cd0d66182fa93d7fca8136336cd to your computer and use it in GitHub Desktop.
Read sticky table of HA proxy from lua action
function dump_str(o)
-- transform a table into a string for the printing.
-- found it on google
-- better to use print_r from here http://www.arpalert.org/haproxy-scripts.html
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump_str(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
-- name of the sticky table we are lookgin for
-- in the hapory.cfg something like
-- backend per_auth_rates
-- stick-table type string len 180 size 200k expire 60s store gpc1,http_req_rate(60s),conn_rate(60s)
my_stk_name = 'per_auth_rates'
function read_stk(txh)
-- get the proxy, since we have to first get it and read it sticky
my_stk = core.proxies[my_stk_name]
-- get the sicky and use it's dump function.
-- in lua, functions of an object are called with : not .
-- thanks to Thierry Fournier
core.Info(dump_str(my_stk.stktable:dump({})))
end
core.register_action("read_stk", {'tcp-req', 'http-req'}, read_stk, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment