markabrahams / node-net-snmp

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

Session methods dont do anything #190

Closed outta1space closed 2 years ago

outta1space commented 2 years ago

Hi, i cant get started with node-net-snmp. I tried replicating the basic example from README.md, theres no error and a callback function is never called. I checked with Wireshark and theres no packets sent/recieved.

Its a single js file with package.json and only net-snmp installed:

var snmp = require('net-snmp');
var session = snmp.createSession ("172.17.19.75", "public");

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

session.get (oids, function (error, varbinds) {
    console.log('---');
    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);
            }
        }
    }
    session.close ();
});

console.log('end')
session.close();

Heres the result: image

Same result when using other methods like walk or set. The destination host is accessible:

support@office:~$ snmpget -v 1 -c public 172.17.19.75 1.3.6.1.2.1.1.5.0
iso.3.6.1.2.1.1.5.0 = ""

Please tell me if you need any additional info.

markabrahams commented 2 years ago

Hi @outta1space - your problem is that you've added this final line to the README.md example code: session.close();

which will be closing down the session before the callback runs. Remove that final line to align with the example code and fix your problem.