markabrahams / node-net-snmp

JavaScript implementation of the Simple Network Management Protocol (SNMP)
206 stars 97 forks source link

tableAugments how to use ? Please provide any example #223

Closed ypzen closed 1 year ago

ypzen commented 1 year ago

.1.3.6.1.4.1.5333.2.3.2.1.1 .1.3.6.1.4.1.5333.2.3.2.1.2

.1.3.6.1.4.1.5333.2.3.2.2 .1.3.6.1.4.1.5333.2.3.2.2.1

using mib table i want above example dynamically device id like 1, 2

markabrahams commented 1 year ago

Hi @ypzen - you can learn about table augmentation here: https://www.rfc-editor.org/rfc/rfc2578.html#section-7.8

And I'd recommend looking in the interfaces MIB IF-MIB at ifTable and ifXTable to observe how ifXTable augments the base table ifTable as a simple example of table augmentation.

Here's a working example of table augmentation with this library. It implements cut-down versions of ifTable and ifXTable, but all of the indexing information is included to fully illustrate the use of table augmentation:

const snmp = require ("net-snmp");

const snmpOptions = {
    port: 1161
}

const callback = function (error, data) {
    if ( error ) {
        console.error (error);
    } else {
        console.log (JSON.stringify(data.pdu.varbinds, null, 2));
    }
};

const agent = snmp.createAgent(snmpOptions, callback);
const authorizer = agent.getAuthorizer ();
authorizer.addCommunity ("public");

const baseTableProvider = {
    name: "ifTable",
    type: snmp.MibProviderType.Table,
    oid: "1.3.6.1.2.1.2.2.1",
    tableColumns: [
        {
            number: 1,
            name: "ifIndex",
            type: snmp.ObjectType.Integer,
            maxAccess: snmp.MaxAccess['read-only']
        },
        {
            number: 2,
            name: "ifDescr",
            type: snmp.ObjectType.OctetString,
            maxAccess: snmp.MaxAccess['read-write']
        }
    ],
    tableIndex: [
        {
            columnName: "ifIndex"
        }
    ]
};
agent.registerProvider (baseTableProvider);

const augmentedTableProvider = {
    name: "ifXTable",
    type: snmp.MibProviderType.Table,
    oid: "1.3.6.1.2.1.31.1.1.1",
    tableColumns: [
        {
            number: 1,
            name: "ifName",
            type: snmp.ObjectType.OctetString,
            maxAccess: snmp.MaxAccess['read-write']
        }
    ],
    tableAugments: "ifTable"
}
agent.registerProvider (augmentedTableProvider);

const mib = agent.getMib ();

mib.addTableRow ("ifTable", [0, "lo"]);
mib.addTableRow ("ifTable", [2, "eth0"]);

mib.addTableRow ("ifXTable", [0, "Loopback"]);
mib.addTableRow ("ifXTable", [2, "LAN 1"]);

mib.dump ({
    leavesOnly: true,
    showProviders: true,
    showValues: true,
    showTypes: true
});
ypzen commented 1 year ago

Hi @markabrahams Thanks for about table augmentation ,

But i can't found solution using table augmentation for below example.

I need dynamic table tree.

root: 1.3.6.1.4.1.5333.2.3.2

first device - 1.3.6.1.4.1.5333.2.3.2.1 first detail first device - 1.3.6.1.4.1.5333.2.3.2.1.1 second detail first device - 1.3.6.1.4.1.5333.2.3.2.1.2

second device - 1.3.6.1.4.1.5333.2.3.2.2 first detail second device - 1.3.6.1.4.1.5333.2.3.2.2.1 second detail second device - 1.3.6.1.4.1.5333.2.3.2.2.2

n devices - 1.3.6.1.4.1.5333.2.3.2.n first detail n device - 1.3.6.1.4.1.5333.2.3.2.n.1 second detail n device - 1.3.6.1.4.1.5333.2.3.2.n.2

Please suggest appropriate example for above example