"Sumarize" API query

Hi guys!

It is possible to “sumarize” device search query by ExternalIPAddress parameter from API?

Almost devices uses InternetGatewayDevice.WANDevice.1.WANConnectionDevice.X.WANIPConnection.1.ExternalIPAddress to show their IP external address, but some devices uses InternetGatewayDevice.WANDevice.2.WANConnectionDevice.X.WANIPConnection.1.ExternalIPAddress.

I have tried {“InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.ExternalIPAddress”: “1.2.3.4”} query but it doesn’t works.

Thanks!

Your best bet is a virtual parameter.

let keys = [
    'Device.PPP.Interface.*.IPCP.LocalIPAddress',
    'InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.ExternalIPAddress'
];

let result = getParameterValue(keys);

return {writable: false, value: [result, "xsd:string"]};

function getParameterValue(keys) {
    for (let key of keys) {
        let d = declare(key, {path: Date.now() - (120 * 1000), value: Date.now()});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return '';
}
1 Like

Your tip worked perfectly for my purpose!

Thanks @akcoder!

You are welcome. VParams do not auto-refresh. And sadly, there is no event code a CPE is required to send when it connects to the interwebs. So you will need to periodically refresh the value. I would create two presets. One that has 0 BOOT as the event and refreshes the vparam. And another more general purpose preset which periodically refreshes values you need.

Here is a script I wrote which refreshes DSL stats. You are welcome to take the script in whole or in part. This script refreshes DSL info every 18 hours, and interface stats every 6 hours.

let oneDay = 24 * (60 * 60) * 1000;
let dslRefreshInterval = Date.now() - (oneDay * 1.5);
let statsRefreshInterval = Date.now() - (oneDay * 0.25);

let paramNames = [
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.ModulationType",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamCurrRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamCurrRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamMaxRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamMaxRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamNoiseMargin",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamNoiseMargin",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamAttenuation",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamAttenuation",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamPower",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamPower",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.LinkEncapsulationUsed",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.LineNumber",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.X_BROADCOM_COM_BondingLineNumber",
    "Device.DSL.Channel.*.UpstreamCurrRate",
    "Device.DSL.Channel.*.DownstreamCurrRate",
    "Device.DSL.Channel.*.UpstreamMaxBitRate",
    "Device.DSL.Channel.*.DownstreamMaxBitRate",
    "Device.DSL.Channel.*.LinkEncapsulationUsed",
    "Device.DSL.Line.*.UpstreamNoiseMargin",
    "Device.DSL.Line.*.DownstreamNoiseMargin",
    "Device.DSL.Line.*.UpstreamAttenuation",
    "Device.DSL.Line.*.DownstreamAttenuation",
    "Device.DSL.Line.*.UpstreamPower",
    "Device.DSL.Line.*.DownstreamPower",
    "Device.DSL.Line.*.LineNumber",
    "Device.DSL.Line.*.X_ZYXEL_BondingLineNumber",
    "Device.DSL.ChannelNumberOfEntries",
    "Device.DSL.LineNumberOfEntries",
];

for(let key of paramNames) {
    declare(key, {path: oneDay * 2, value: dslRefreshInterval});
}

declare("InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.Stats.*.*", {path: oneDay * 2, value: statsRefreshInterval});
declare("Device.DSL.Line.*.Stats.*.*", {path: oneDay * 2, value: statsRefreshInterval});
declare("Device.DSL.Channel.*.Stats.*.*", {path: oneDay * 2, value: statsRefreshInterval});
2 Likes