Im have a list of about 50 IP addresses (ip.array_agg) to poll in a loop. Problem is that the async nature of the module means that the returning results come back at random times in any order so I need to track the sessions somehow. How can I link the outgoing snmp get session requests with the returning results in the callback so that I can associate the varbinds (results) with the associated IP address? Is there an session id or something I can use to tag the sessions? Maybe it is possible via dgram? A code example would be great.
var snmp = require ("net-snmp");
var community = 'terminal';
var oids = ["1.3.6.1.4.1.2509.8.22.2.1.1.5.4","1.3.6.1.4.1.2509.8.22.2.1.1.5.1"];
for( var i = 0; i < ips.array_agg.length; i++){
var ip = ips.array_agg[i];
var session = snmp.createSession ( ip, community);
console.log(session);
session.get (oids, function (error, varbinds) {
if (error) {
console.error ('session get error:', ip, error);
} else {
for (var i = 0; i < varbinds.length; i++)
if (snmp.isVarbindError (varbinds[i]))
console.error (snmp.varbindError (varbinds[i]))
else
console.log ( ip, varbinds[i].oid + " = " + varbinds[i].value/100);
}
});
}