V0.1.1 Added env var and enabled websocket

This commit is contained in:
Christian Risi 2025-06-05 11:09:26 +02:00
parent b02370a69a
commit 8a75d7c0e7
2 changed files with 12 additions and 19 deletions

View File

@ -1,8 +1,12 @@
import { SuricataSocketStream } from "./socket-server/server.ts"; import { SuricataSocketStream } from "./socket-server/server.ts";
// UGLY: take them from // UGLY: take them from
const UNIXPATH = "/var/lib/suricata/eve.sock" const UNIXPATH = "/var/lib/suricata/eve.sock"
const WEB_SOCKET_URI = "" const WEB_SOCKET_URI = Deno.env.get("WEBSOCKET_RELAY")
if (!WEB_SOCKET_URI) {
throw Error("There's no value associated with WEBSOCKET_RELAY environment variable")
}
const app = new SuricataSocketStream( const app = new SuricataSocketStream(
UNIXPATH, UNIXPATH,

View File

@ -17,7 +17,7 @@ export class SuricataSocketStream {
}); });
this.webSocket = new WebSocket(webSocketURI); this.webSocket = new WebSocket(webSocketURI);
} }
public async serve() { public async serve() {
@ -31,7 +31,7 @@ export class SuricataSocketStream {
const jsonParser = new JSON_Chunker() const jsonParser = new JSON_Chunker()
do { do {
let bytesRead: number | null = 0; let bytesRead: number | null = 0;
const chunk: Uint8Array = new Uint8Array(this.maxBlobSize); const chunk: Uint8Array = new Uint8Array(this.maxBlobSize);
@ -48,28 +48,17 @@ export class SuricataSocketStream {
while (jsonParser.messageReady) { while (jsonParser.messageReady) {
this.messageProcess(jsonParser.message!) this.messageProcess(jsonParser.message!)
} }
} while (true); } while (true);
} }
} }
// UGLY: change this to a more flexible method // UGLY: change this to a more flexible method
private messageProcess(msg: string | Uint8Array) { private messageProcess(msg: string | Uint8Array) {
// this.webSocket.send(msg); this.webSocket.send(msg);
console.log(
`
Debug, found this message:
${msg}
END OF MESSAGE
`
)
} }
} }