I am trying to listen for snmp traps on the standard UDP 162 port and then parse and output them.
I have looked at snmpjs and snmp-native plugins for node and they both seem to major on the generation of agents. What I would like to do is listen and decode traps and informs that are forwarded to my localhost (maybe even acknowledge informs). I know I could spend quite some time with dgram and ASN.1BER but would prefer to use already written snmp code.
var dgram = require('dgram');
//var snmp = require('snmpjs');
var snmp = require('snmp-native');
var server = dgram.createSocket("udp4");
server.on("listening", function() {
var addr = server.address();
console.log("Server listening "+ addr.address + ":" + addr.port);
});
server.on("message", function (msg, rinfo) {
console.log("From " + rinfo.address + ":" + rinfo.port);
console.log("server got: " + msg);
//console.log("Parse: " + snmp.parseMessage({raw:msg}));
console.log("Parse: " + snmp.parse(msg));
});
server.bind(162);
Both snmp parse functions cause errors, the first is parseMessage not defined, and it's not clear in the snmpjs documents how to create the correct object http://wesolows.github.com/node-snmpjs/protocol.html#parseMessage(arg). And I can't use the snmpjs agent as there is no on message event.
The second parse from snmp-native, I get an error that the buffer is not an int....
Error: Buffer 06082b06010603010105 does not appear to be an Integer
at Object.parseInteger (/usr/share/node/node_modules/snmp-native/lib/asn1ber.js:318:15)
Any pointers would be great, thanks.