paulbsd-salt/states/haproxy/scripts/collector.lua

37 lines
914 B
Lua
Raw Normal View History

2022-10-23 16:37:53 +02:00
--require = GLOBAL.require
--require("http.request")
local request = require("http")
local json = require("json")
core.register_action("test", { "http-req" }, function(txn)
local info = {}
local headers = {}
local reqbody = txn.sf:req_body()
local reqclientip = txn.f:src()
local reqheaders = txn.http:req_get_headers()
local reqmethod = txn.f:method()
local reqpath = txn.f:path()
info["body"] = reqbody
info["clientip"] = reqclientip
local headers = {}
for k,v in pairs(reqheaders) do
headers[k] = {}
for z,y in pairs(v) do
table.insert(headers[k],y)
end
end
info["headers"] = headers
info["method"] = reqmethod
info["path"] = reqpath
local infojson = json.encode(info)
--local req = request.new_from_uri("https://ipbl.paulbsd.com")
--local headers, stream = req:go()
--local body = assert(stream:get_body_as_string())
txn.Info(txn, infojson)
end
)