Problems retrieving parameters from genieacs

Good morning, I use the GenieACS inform function to update the following parameters.

const hourly = Date.now()-600000;
// Refresh basic parameters hourly(30000=5 minutos)

declare(“InternetGatewayDevice.WANDevice.1.X_GponInterafceConfig.RXPower”, {path: hourly, value: hourly});

declare(“InternetGatewayDevice.WANDevice.1.X_GponInterafceConfig.TXPower”, {path: hourly, value: hourly});

declare(“InternetGatewayDevice.DeviceInfo.X_HW_CpuUsed”, {path: hourly, value: hourly});

declare(“InternetGatewayDevice.DeviceInfo.X_HW_MemUsed”, {path: hourly, value: hourly});

declare(“InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.TotalAssociations”, {path: hourly, value: hourly});
declare(“InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.TotalAssociations”, {path: hourly, value: hourly});

I have the following provision:

function get1(name) {
const q = declare(name, {value: 1});
return q.size ? q.value[0] : ‘’;
}

function hasTag(name) {
const tag = declare(Tags.${name}, { value: 1 });
return tag.size > 0;
}

function getUsername() {
for (let i = 1; i <= 10; i++) { // Limite de WANConnectionDevice (ajuste se quiser)
const path = InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${i}.WANPPPConnection.1.Username;
const q = declare(path, { value: 1 });

if (q.size > 0 && q.value[0]) {
  return q.value[0];
}

}
return “”;
}

const user = getUsername();
// Exemplo de leitura que só consulta cache
const sinal = get1(‘InternetGatewayDevice.WANDevice.1.X_GponInterafceConfig.RXPower’);
//const sinalTX = get1(‘InternetGatewayDevice.WANDevice.1.X_GponInterafceConfig.TXPower’);
const sinalTX = 2;
const cpu = get1(‘InternetGatewayDevice.DeviceInfo.X_HW_CpuUsed’);
const ram = get1(‘InternetGatewayDevice.DeviceInfo.X_HW_MemUsed’);
//const con2 = get1(‘InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.TotalAssociations’);
//const con5 = get1(‘InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.TotalAssociations’);
//const ram = 50;
const key = ‘AK4715091997’;

//const payload = { source: ‘genieacs’, event: ‘auto-reboot’, user, sinal, sinalTX, cpu, ram, key};
const payload = { source: ‘genieacs’, event: ‘auto-reboot’, user, sinal, sinalTX, cpu, ram, key};
try {
const resp = ext(‘events’, ‘send’, JSON.stringify(payload));
// log('Webhook resp: ’ + JSON.stringify(resp));
} catch (e) {
log('Webhook erro: ’ + e.toString());
}

The problem is that I can only retrieve 3 parameters; if I try to retrieve the others, I get session timeout errors.

Can anyone help me?

Does everything work correctly if you remove this block?

try {
const resp = ext(‘events’, ‘send’, JSON.stringify(payload));
// log('Webhook resp: ’ + JSON.stringify(resp));
} catch (e) {
log('Webhook erro: ’ + e.toString());
}

No, I commented out the ext script, but the problem persists: it occurs when trying to retrieve more than 3 parameters.

Please enable debugging and repeat your testing and include the output from the debug yaml file

My previous script wasn’t efficient; after adjustments, I managed to fix it and add more parameters, although I don’t know how many more I can add. I’ll leave the updated code here in case anyone is interested. I’ll also include a screenshot of the interface I’m working with, showing the history of some data, for those who want to work with Genie. It’s really worth it.

// Script de Provisionamento Otimizado (Versão 2)
// Corrigido o erro TypeError: e.charCodeAt is not a function

// Função otimizada para buscar o Username
function getUsername() {
    for (let i = 1; i <= 10; i++) {    // Limite de WANConnectionDevice (ajuste se quiser)
        const path = `InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${i}.WANPPPConnection.1.Username`;
        const q = declare(path, { value: 1 });

        if (q.size > 0 && q.value[0]) {
            return q.value[0];
        }

    }
    return "";
}

// ------------------------------------------------------------------
// 1. Lista de todos os caminhos de parâmetros que você precisa
// NOTA: A busca em lote com array de paths pode estar causando o erro na sua versão do GenieACS.
// Para garantir a compatibilidade, vamos usar a busca individual, mas mantendo a estrutura
// de uma única requisição CWMP, que é o comportamento padrão do declare quando chamado em sequência.
// A solução ideal é usar a busca em lote, mas a individual é mais robusta contra bugs de versão.

// Declaração dos parâmetros individuais
const sinalQ = declare('InternetGatewayDevice.WANDevice.1.X_GponInterafceConfig.RXPower', { value: 1 });
const sinalTXQ = declare('InternetGatewayDevice.WANDevice.1.X_GponInterafceConfig.TXPower', { value: 1 });
const cpuQ = declare('InternetGatewayDevice.DeviceInfo.X_HW_CpuUsed', { value: 1 });
const ramQ = declare('InternetGatewayDevice.DeviceInfo.X_HW_MemUsed', { value: 1 });
const conQ = declare('InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.TotalAssociations', { value: 1 });
const con5Q = declare('InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.TotalAssociations', { value: 1 });
const conlanQ = declare('VirtualParameters.lanConnected', { value: 1 });
const downQ = declare('InternetGatewayDevice.WANDevice.1.X_HW_PonInterface.Stats.BytesReceived', { value: 1 });

// Função auxiliar para extrair o valor
function get1(q) {
    return q.size ? q.value[0] : '';
}

// 4. Atribuição dos valores
const user = getUsername();
const sinal = get1(sinalQ);
const sinalTX = get1(sinalTXQ);
const cpu = get1(cpuQ);
const ram = get1(ramQ);
const con = get1(conQ);
const con5 = get1(con5Q);
const conlan = get1(conlanQ);
const down = get1(downQ);
const key = 'AK4715091997';

// 5. Envio do payload
const payload = { source: 'genieacs', event: 'auto-reboot', user, sinal, sinalTX, con, con5, conlan, down, cpu, ram, key};
try {
    const resp = ext('events', 'send', JSON.stringify(payload));
// log('Webhook resp: ' + JSON.stringify(resp));
} catch (e) {
    log('Webhook erro: ' + e.toString());
}

Please take the time to understand how the timestamp parameter of the declare function works. You will save yourself a lot of problems. This script will only pull the value of the various parameters the first time the script is run. These are clearly parameters which change over time. You should change {value: 1} to {value: Date.now()} that will cause GenieACS to pull updated data from the CPE.

You’re right, there’s an information script that updates the parameters I want every 10 minutes. For this reason, this script tries to retrieve data only from the GenieACS memory, instead of directly from the CPE. This was done intentionally, and that’s why the graph data is as expected and constantly changing.