I am sending error messages to a specific host identifier before I do this, so that I can verify that the session was created successfully, so I can send error messages.
main.js
var snmp = require("net-snmp"); var msg = require('./event.js'); var dns = require('dns'); var os = require('os'); function process (msg) { var host = msg.event.body.snmp.trapHost; //Create snmp Session var session = snmp.createSession(host,"public",sessionOptions); var options = {upTime: 1000}; try { dns.lookup (os.hostname (), function (error, host) { if (error) { console.error(error); } else { session.trap(trapOid, varbinds, options, function (error) { if (error) console.log(error); else console.log('SNMP successfully delivered'); }); } }); } catch (e) { console.log("SNMP processing error: " + e); } }; process(msg);
source share