Last active
November 20, 2024 20:27
-
-
Save esseti/477b3cd0d66182fa93d7fca8136336cd to your computer and use it in GitHub Desktop.
Read sticky table of HA proxy from lua action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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