-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox_httpoutput.lua
51 lines (44 loc) · 1.21 KB
/
sandbox_httpoutput.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--[[
hekad.toml
[HttpOutput]
message_matcher = "TRUE"
type = "SandboxOutput"
filename = "sandbox_httpoutput.lua"
[Log4jOutput.config]
url = "http://some url"
method = "POST"
req_body = "foo=bar"
outfile = "log.txt"
]]
require"io"
require"ltn12"
require"string"
local http = require("socket.http")
local url = read_config("url") or error("url must be set")
local method = read_config("method") or error("method must be set")
local req_body = read_config("req_body")
local outfile = read_config("outfile")
function process_message()
local log = read_message("Payload")
--local ok, json = pcall(cjson.decode, log)
--if not ok then
-- return -1
--end
-- do request
local respbody = {}
local result, respcode, respheaders, respstatus = http.request {
url = url,
method = method,
source = ltn12.source.string(reqbody),
headers = {
["content-type"] = "text/plain",
["content-length"] = tostring(#reqbody)
},
sink = ltn12.sink.table(respbody)
}
respbody = table.concat(respbody)
-- wirte respbody to file
local f, e = io.open("/opt/res", "a+")
f:write(respbody)
return 0
end