fix SSH login alert delivery (#1100)

This commit is contained in:
ZacharyZcR
2026-07-28 01:47:54 +08:00
committed by GitHub
parent 6d790b8d61
commit 1139f17319
3 changed files with 94 additions and 37 deletions
+16 -7
View File
@@ -11,14 +11,23 @@ export async function triggerLoginAlert(
): Promise<void> {
try {
const token = await SystemCrypto.getInstance().getInternalAuthToken();
await fetch(`${METRICS_SERVICE_URL}/internal/login-alert`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-internal-auth": token,
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 }),
},
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",