mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-08-29 10:21:34 +00:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { SystemCrypto } from "./system-crypto.js";
|
|
import { sshLogger } from "./logger.js";
|
|
|
|
const METRICS_SERVICE_URL = "http://localhost:30005";
|
|
|
|
export async function triggerLoginAlert(
|
|
hostId: number,
|
|
userId: string,
|
|
sshUser: string,
|
|
fromIp: string,
|
|
): Promise<void> {
|
|
try {
|
|
const token = await SystemCrypto.getInstance().getInternalAuthToken();
|
|
const response = await fetch(
|
|
`${METRICS_SERVICE_URL}/internal/login-alert`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"x-internal-auth": token,
|
|
},
|
|
body: JSON.stringify({ hostId, userId, sshUser, fromIp }),
|
|
},
|
|
);
|
|
if (!response.ok) {
|
|
const details = await response.text();
|
|
throw new Error(
|
|
`Metrics service returned ${response.status}${details ? `: ${details}` : ""}`,
|
|
);
|
|
}
|
|
} catch (err) {
|
|
sshLogger.warn("Failed to trigger login alert", {
|
|
operation: "login_alert_trigger_error",
|
|
hostId,
|
|
error: err instanceof Error ? err.message : String(err),
|
|
});
|
|
}
|
|
}
|