Skip to content

I cant get OID's with snmp-nodejs #21886

@mertonuryildirim

Description

@mertonuryildirim

i m trying to do this project ; get object names from my mib file ( i loaded it /resources/dl801.mib this path ) and check it every 1 minute . i can get object names but i cant get OID numbers (hierarchy like .1.3.6.... ) how can i get oid numbers ?
this code has output like ;

upsLowBatteryShutdown
buckOn
returnFromBuck
returnFromBoost
Parsed : [ 'enterprises', 935 ]

i want it to code will write upsLowBatteryShutdown : .1.3.6 like this thanks for helping

var snmp = require ("net-snmp");
var session = snmp.createSession ("127.0.0.1", "public");
var fs = require('fs');
var grammar = fs.readFileSync( __dirname + '/resources/dl801.mib').toString();
var asn2json = require('asn2json');
var util = require('util');
var asn = new asn2json();

var MIB = {
iso : {
'OBJECT IDENTIFIER': { '::=': [ 'root', 1 ] }
}
};
smi2json(MIB,grammar);

function fn60sec() {

    session.get ({oids:[]}, function (error, varbinds) {
        if (error) {
            console.error (error);
        } else {
            for (var i = 0; i < varbinds.length; i++)
                if (snmp.isVarbindError (varbinds[i]))
                    console.error (snmp.varbindError (varbinds[i]))
                else
                    console.log (varbinds[i].oid + " = " + varbinds[i].value);
        }
    });
}(60*1000);

 session.trap (snmp.TrapType.LinkDown, function (error) {
    if (error)
        console.error (error);
}); 
fn60sec();
setInterval(fn60sec, 60*1000);

function smi2json(mib,schema){

try{
    var Module = asn.parse(schema);
    var ModuleName  = Object.keys(Module)[0];
    var Definitions = Module[ModuleName].DEFINITIONS;
    var identifiers = Object.keys(Definitions);
        identifiers.forEach( function( ObjectId ){

            console.log(ObjectId);
            MIB[ObjectId] = Definitions[ObjectId];
        })
      console.log("Parsed :  " , mib.iso['OBJECT IDENTIFIER']['::=']);
}catch(e){
     console.log(mib, util.inspect(e, false, 10, true))
}  

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    wrong repoIssues that should be opened in another repository.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions