poweroff-tool
Version:
This is application which power off a pc when it triggered
37 lines (31 loc) • 811 B
JavaScript
const snmp = require('net-snmp');
function SNMP(target, oids) {
this.target = target;
this.oids = oids;
this.session = snmp.createSession(target, 'public');
this.session.on('error', (error) => {
console.error(error);
})
this.get = get.bind(this);
return this;
};
function get(callback) {
console.time('snmp -get');
this.session.get(this.oids, function(error, varbinds) {
if (error) {
callback(error);
} else {
for (var i = 0; i < varbinds.length; i++) {
if (snmp.isVarbindError(varbinds[i])) {
callback('isVarbindError');
return;
} else {
console.log(varbinds[i].oid + ' = ' + varbinds[i].value);
}
}
console.timeEnd('snmp -get');
callback(null, varbinds);
}
});
}
module.exports = SNMP;