|
|
@@ -23,7 +23,6 @@ local luv_ok, luv = pcall(require, "luv")
|
|
|
local ws_client = nil
|
|
|
local has_websocket, websocket = pcall(require, "websocket")
|
|
|
|
|
|
-
|
|
|
if has_websocket then
|
|
|
ws_client = websocket.client.sync()
|
|
|
end
|
|
|
@@ -35,6 +34,18 @@ if has_http then
|
|
|
http_client = http
|
|
|
end
|
|
|
|
|
|
+-- Shell-based HTTP fallback (works on minimal OpenWrt)
|
|
|
+local function http_post_shell(url, data)
|
|
|
+ local cmd = string.format(
|
|
|
+ 'curl -s -X POST -H "Content-Type: application/json" -d "%s" "%s" 2>/dev/null',
|
|
|
+ data:gsub('"', '\\"'), url
|
|
|
+ )
|
|
|
+ local f = io.popen(cmd)
|
|
|
+ local resp = f and f:read("*a") or ""
|
|
|
+ if f then f:close() end
|
|
|
+ return resp ~= ""
|
|
|
+end
|
|
|
+
|
|
|
-- ============================================================================
|
|
|
-- CONFIG
|
|
|
-- ============================================================================
|
|
|
@@ -609,21 +620,22 @@ local function main()
|
|
|
end
|
|
|
|
|
|
-- Fallback to HTTP POST if no WebSocket
|
|
|
- if not sock and http_client then
|
|
|
- -- Send events via HTTP POST
|
|
|
+ if not sock then
|
|
|
+ -- Send events via curl (shell fallback)
|
|
|
local url = cfg.url:gsub("wss", "https"):gsub("ws", "http")
|
|
|
if url == cfg.url then url = cfg.url .. "/events" end
|
|
|
|
|
|
-- POST buffered events
|
|
|
+ local sent = false
|
|
|
for _, event in ipairs(buffer.events) do
|
|
|
- local ok = http_client.request(url, "POST", event, {
|
|
|
- ["Content-Type"] = "application/json"
|
|
|
- })
|
|
|
- if ok then
|
|
|
+ if http_post_shell(url, event) then
|
|
|
log("info", "Event sent: " .. event)
|
|
|
+ sent = true
|
|
|
end
|
|
|
end
|
|
|
- buffer.clear()
|
|
|
+ if sent then
|
|
|
+ buffer.clear()
|
|
|
+ end
|
|
|
sock = "http" -- Mark as connected
|
|
|
end
|
|
|
|