How to use the net-snmp.createSession function in net-snmp

To help you get started, we’ve selected a few net-snmp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github netdata / netdata / collectors / node.d.plugin / snmp / snmp.node.js View on Github external
if(__DEBUG === true)
                service.error('no OIDs to process.');

            callback(null);
            return;
        }

        if(typeof service.snmp_session === 'undefined' || service.snmp_session === null) {
            // no SNMP session has been created for this service
            // the SNMP session is just the initialization of NET-SNMP

            if(__DEBUG === true)
                netdata.debug(service.module.name + ': ' + service.name + ': opening ' + this.name + ' session on ' + service.request.hostname + ' community ' + service.request.community + ' options ' + netdata.stringify(service.request.options));

            // create the SNMP session
            service.snmp_session = net_snmp.createSession (service.request.hostname, service.request.community, service.request.options);

            if(__DEBUG === true)
                netdata.debug(service.module.name + ': ' + service.name + ': got ' + this.name + ' session: ' + netdata.stringify(service.snmp_session));

            // if we later need traps, this is how to do it:
            //service.snmp_session.trap(net_snmp.TrapType.LinkDown, function(error) {
            //  if(error) console.error('trap error: ' + netdata.stringify(error));
            //});
        }

        // do it, get the SNMP values for the sessions we need
        this.getdata(service, 0, 0, 0, callback);
    }
};
github davibaltar / snmp-fiberhome / src / pack-fiberhome.js View on Github external
return new Promise((resolve, reject) => {
        var options = { ...defaultOptions, ...opt }
        var session = snmp.createSession(options.ip || options.host, options.community, options)
        session.get(oids, function (error, varbinds) {
            if (error) {
                return reject(error)
            } else {
                return resolve(varbinds)
            }
            // If done, close the session
            session.close()
        })
    })
}
github node-red / node-red-nodes / io / snmp / snmp.js View on Github external
function getSession(host, community, version, timeout) {
        var sessionKey = host + ":" + community + ":" + version;
        var port = 161;
        if (host.indexOf(":") !== -1) {
            port = host.split(":")[1];
            host = host.split(":")[0];
        }
        if (!(sessionKey in sessions)) {
            sessions[sessionKey] = snmp.createSession(host, community, { port:port, version:version, timeout:(timeout || 5000) });
        }
        return sessions[sessionKey];
    }
github glenmurphy / route / modules / snmp_dev / snmp.js View on Github external
function SNMP(data) {
  this.host = data.host;
  this.traps = data.traps;
  this.session = snmp.createSession ("127.0.0.1", "public");


  var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];

  this.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);          
        }
      }
    }
github davibaltar / snmp-fiberhome / src / pack-fiberhome.js View on Github external
return new Promise((resolve, reject) => {
        var options = { ...defaultOptions, ...opt }
        var aVarbinds = []
        var session = snmp.createSession(options.ip || options.host, options.community, options)
        session.subtree(oid, options.maxRepetitions, function feedCb(varbinds) {
            aVarbinds.push(...varbinds)
        }, function doneCb(error) {
            if (error)
                return reject(error.toString())
            else
                return resolve(aVarbinds)
        })
    })
}

net-snmp

JavaScript implementation of the Simple Network Management Protocol (SNMP)

MIT
Latest version published 30 days ago

Package Health Score

73 / 100
Full package analysis