Compare commits

...

3 Commits
v1.9.0 ... dev

Author SHA1 Message Date
shamoon
d3f1832f70 Merge branch 'main' into dev
Some checks are pending
Docker CI / Linting Checks (push) Waiting to run
Docker CI / Docker Build & Push (push) Blocked by required conditions
2026-01-19 09:29:16 -08:00
shamoon
f524531a13 Fix truenas proxy widget logging 2026-01-19 07:49:46 -08:00
shamoon
d6dde5fc41 Documentaiton: clarify backend port usage in NetAlertX widget docs 2026-01-19 07:46:11 -08:00
2 changed files with 4 additions and 12 deletions

View File

@@ -19,7 +19,7 @@ Provide the `API_TOKEN` (f.k.a. `SYNC_api_token`) as the `key` in your config.
```yaml ```yaml
widget: widget:
type: netalertx type: netalertx
url: http://ip:port url: http://ip:port # backend port
key: yournetalertxapitoken key: yournetalertxapitoken
version: 2 # optional, default is 1 version: 2 # optional, default is 1
``` ```

View File

@@ -25,9 +25,6 @@ function waitForEvent(ws, handler, { event = "message", parseJson = true } = {})
} else if (typeof payload === "string") { } else if (typeof payload === "string") {
parsed = JSON.parse(payload); parsed = JSON.parse(payload);
} }
logger.info("Received TrueNAS websocket message: %o", parsed);
} else {
logger.info("Received TrueNAS websocket message: %o", payload);
} }
const handlerResult = handler(parsed); const handlerResult = handler(parsed);
if (handlerResult !== undefined) { if (handlerResult !== undefined) {
@@ -52,7 +49,7 @@ function waitForEvent(ws, handler, { event = "message", parseJson = true } = {})
const handleClose = () => { const handleClose = () => {
cleanup(); cleanup();
logger.error("TrueNAS websocket connection closed unexpectedly"); logger.debug("TrueNAS websocket connection closed unexpectedly");
reject(new Error("TrueNAS websocket closed the connection")); reject(new Error("TrueNAS websocket closed the connection"));
}; };
@@ -73,7 +70,6 @@ let nextId = 1;
async function sendMethod(ws, method, params = []) { async function sendMethod(ws, method, params = []) {
const id = nextId++; const id = nextId++;
const payload = { jsonrpc: "2.0", id, method, params }; const payload = { jsonrpc: "2.0", id, method, params };
logger.info("Sending TrueNAS websocket method %s with id %d", method, id);
ws.send(JSON.stringify(payload)); ws.send(JSON.stringify(payload));
return waitForEvent(ws, (message) => { return waitForEvent(ws, (message) => {
@@ -92,7 +88,7 @@ async function authenticate(ws, widget) {
if (apiKeyResult === true) return; if (apiKeyResult === true) return;
logger.warn("TrueNAS API key authentication failed, falling back to username/password when available."); logger.warn("TrueNAS API key authentication failed, falling back to username/password when available.");
} catch (err) { } catch (err) {
logger.warn("TrueNAS API key authentication failed: %s", err?.message ?? err); logger.error("TrueNAS API key authentication failed: %s", err?.message ?? err);
} }
} }
@@ -141,13 +137,9 @@ export default async function truenasProxyHandler(req, res, map) {
let data; let data;
const wsUrl = new URL(formatApiCall(widgets[widget.type].wsAPI, { ...widget })); const wsUrl = new URL(formatApiCall(widgets[widget.type].wsAPI, { ...widget }));
const useSecure = wsUrl.protocol === "https:" || Boolean(widget.key); // API key requires secure connection const useSecure = wsUrl.protocol === "https:" || Boolean(widget.key); // API key requires secure connection
if (useSecure && wsUrl.protocol !== "https:")
logger.info("Upgrading TrueNAS websocket connection to secure wss://");
wsUrl.protocol = useSecure ? "wss:" : "ws:"; wsUrl.protocol = useSecure ? "wss:" : "ws:";
logger.info("Connecting to TrueNAS websocket at %s", wsUrl);
const ws = new WebSocket(wsUrl, { rejectUnauthorized: false }); const ws = new WebSocket(wsUrl, { rejectUnauthorized: false });
await waitForEvent(ws, () => true, { event: "open", parseJson: false }); // wait for open await waitForEvent(ws, () => true, { event: "open", parseJson: false }); // wait for open
logger.info("Connected to TrueNAS websocket at %s", wsUrl);
try { try {
await authenticate(ws, widget); await authenticate(ws, widget);
data = await sendMethod(ws, wsMethod); data = await sendMethod(ws, wsMethod);
@@ -166,7 +158,7 @@ export default async function truenasProxyHandler(req, res, map) {
if (err?.status) { if (err?.status) {
return res.status(err.status).json({ error: err.message }); return res.status(err.status).json({ error: err.message });
} }
logger.warn("Websocket call for TrueNAS failed: %s", err?.message ?? err); logger.error("Websocket call for TrueNAS failed: %s", err?.message ?? err);
return res.status(500).json({ error: err?.message ?? "TrueNAS websocket call failed" }); return res.status(500).json({ error: err?.message ?? "TrueNAS websocket call failed" });
} }
} }