How to use lua StickTable Class?

Hi there, I’m trying to get a stick-table entry for a given key from Lua.

I’m using HAproxy version 1.9.14 Built with Lua version: Lua 5.3.5

#!/usr/bin/lua

function getStickTable(sticktable)

        local t = sticktable.lookup("/usage")
        for key,value in pairs(t)
        do
                core.log(core.debug,"stick table: "..tostring(key).."=>"..tostring(value))

        end

        return "OK"
end

core.register_fetches("getStickTable", getStickTable)

I got this error log when I try to use sample-fetch from haproxy.

Mar 24 17:04:59 localhost haproxy[18267]: Lua sample-fetch 'getStickTable': runtime error: /etc/haproxy/lua-sticktable.lua:5: attempt to call a nil value (field 'lookup') from /etc/haproxy/lua-sticktable.lua:5 C function line 3.

Is there anyone who knows how to use Lua StickTable Class?
If possible I want to get some sample Lua code for testing.

Thanks.

1 Like

did you manage to get it working?
i’m struggle in finding a way to access sticky table data within an action / function.

FYI i was able to read a sticky table. Open the link, the intresting part is below the first utils function