Soportar autenticacion SSH por clave privada
This commit is contained in:
@@ -364,17 +364,15 @@ function runCommandWithInput(command, args, input, timeoutMs) {
|
||||
}
|
||||
|
||||
async function sshMetrics(device) {
|
||||
if (!device.password) {
|
||||
throw new Error("Password SSH no configurada");
|
||||
const hasPrivateKey = Boolean(device.privateKeyPath);
|
||||
if (!hasPrivateKey && !device.password) {
|
||||
throw new Error("Credenciales SSH no configuradas");
|
||||
}
|
||||
|
||||
const timeoutMs = Math.max(2, config.sshTimeoutSeconds || 8) * 1000;
|
||||
const port = Number(device.port || 22);
|
||||
const destination = `${device.username || "pi"}@${device.host}`;
|
||||
const args = [
|
||||
"-p",
|
||||
device.password,
|
||||
"ssh",
|
||||
const sshArgs = [
|
||||
"-o",
|
||||
"StrictHostKeyChecking=no",
|
||||
"-o",
|
||||
@@ -388,7 +386,29 @@ async function sshMetrics(device) {
|
||||
"-s"
|
||||
];
|
||||
|
||||
const { stdout } = await runCommandWithInput("sshpass", args, REMOTE_METRICS_SCRIPT, timeoutMs);
|
||||
let command = "ssh";
|
||||
let args = sshArgs;
|
||||
if (hasPrivateKey) {
|
||||
args = [
|
||||
"-i",
|
||||
device.privateKeyPath,
|
||||
"-o",
|
||||
"BatchMode=yes",
|
||||
"-o",
|
||||
"IdentitiesOnly=yes",
|
||||
...sshArgs
|
||||
];
|
||||
} else {
|
||||
command = "sshpass";
|
||||
args = [
|
||||
"-p",
|
||||
device.password,
|
||||
"ssh",
|
||||
...sshArgs
|
||||
];
|
||||
}
|
||||
|
||||
const { stdout } = await runCommandWithInput(command, args, REMOTE_METRICS_SCRIPT, timeoutMs);
|
||||
const values = parseKeyValueOutput(stdout);
|
||||
const temp = toNumber(values.cpuTempC, 0);
|
||||
const loadAverage = String(values.loadAverage || "")
|
||||
|
||||
Reference in New Issue
Block a user