sgp - pedro afonso2

This commit is contained in:
Rodrigo Bertoldo de Sousa Martins committed 2026-10-14 15:41:21 -03:00
1 parent 828b6e7209
commit 6bc106a461
2 files changed
+42 -2

No files matched your search

+41 -1
View File
@@ -247,7 +247,7 @@ class SgpAPI {
id_olt_sgp: onu.olt_id,
pon: onu.pon !== undefined ? `${onu.slot ?? ''}/${onu.pon}` : '',
perfil: '',
serial: onu.serial || '',
serial: onu.serial || onu.phy_addr || onu.addr || onu.serial_onu || srv.serial || '',
serviceport: '',
ultimo_rx_power: onu.rx || '',
ultimo_tx_power: onu.tx || '',
@@ -325,10 +325,50 @@ class SgpAPI {
const clientes = await this._listarClientes(credentials, { cliente_id: id });
const dados = [];
clientes.forEach(c => dados.push(...this._mapServicos({ ...c, id: this._clienteId(c) ?? id })));
await this._completarDadosOnu(credentials, dados);
return { dados };
});
}
/**
* Lista de ONUs do SGP (cache curto). Cada item traz phy_addr (serial),
* login do serviço e contrato vinculado.
*/
async _listarOnus(credentials) {
if (this.onuCache && Date.now() - this.onuCache.at < 5 * 60 * 1000) return this.onuCache.lista;
const lista = await this._request(credentials, 'GET', '/api/fttx/onu/list/');
const arr = Array.isArray(lista) ? lista : (lista.onus || lista.result || []);
this.onuCache = { at: Date.now(), lista: arr };
return arr;
}
/**
* Quando o cadastro do cliente não traz o serial da ONU, busca na lista de
* ONUs do SGP pelo contrato ou pelo login do serviço.
*/
async _completarDadosOnu(credentials, servicos) {
const faltando = servicos.filter(s => !s.serial);
if (!faltando.length) return;
try {
const onus = await this._listarOnus(credentials);
faltando.forEach(srv => {
const onu = onus.find(o =>
(o.service_contrato !== undefined && String(o.service_contrato) === String(srv.id_servico)) ||
(srv.login && o.login && String(o.login).toLowerCase() === String(srv.login).toLowerCase()));
if (!onu) return;
srv.serial = onu.phy_addr || '';
if (onu.olt_name && !srv.base) srv.base = onu.olt_name;
if (onu.olt_id !== undefined && !srv.id_ap) {
srv.id_ap = this._idApLegado({ olt_id: onu.olt_id, olt_nome: onu.olt_name });
srv.id_olt_sgp = onu.olt_id;
}
if (!srv.pon && onu.pon !== undefined) srv.pon = `${onu.slot ?? ''}/${onu.pon}`;
});
} catch (error) {
logger.warn('SGP: não foi possível completar dados da ONU', { error: error.message });
}
}
async obterDadosCompletosCliente(idCliente, location = '', credentials) {
const instance = this.getInstanceByLocation();
try {
+1 -1
View File
@@ -38,7 +38,7 @@ class SSHManager {
// Concentrador Juniper - Pedro Afonso
const juniperPedroAfonso = {
name: 'Concentrador Juniper Pedro Afonso',
host: process.env.JUNIPER_PEDRO_AFONSO_HOST || '45.189.140.2',
host: process.env.JUNIPER_PEDRO_AFONSO_HOST || '192.168.100.10',
username: process.env.JUNIPER_PEDRO_AFONSO_USER || 'rodrigo',
password: process.env.JUNIPER_PEDRO_AFONSO_PASS || '',
port: 22,