Node-Red configuration
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

snmp-receiver.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var snmp = require ("../");
  2. var getopts = require ("getopts");
  3. var options = getopts(process.argv.slice(2));
  4. var verbose = options.v;
  5. var snmpOptions = {
  6. disableAuthorization: options.n,
  7. port: options.p,
  8. transport: options.t,
  9. engineID: options.e,
  10. includeAuthentication: options.a
  11. };
  12. var cb = function(error, trap) {
  13. var now = new Date().toLocaleString();
  14. var trapType;
  15. if (error) {
  16. console.log(now + ": " + error.message);
  17. } else {
  18. trapType = snmp.PduType[trap.pdu.type] || "Unknown";
  19. if ( verbose ) {
  20. console.log (now + ": " + trapType + " received:");
  21. console.log (JSON.stringify(trap, null, 2));
  22. } else {
  23. if (trap.pdu.type == snmp.PduType.Trap ) {
  24. console.log (now + ": " + trapType + ": " + trap.rinfo.address + " : " + trap.pdu.enterprise);
  25. } else {
  26. for (var i = 0; i < trap.pdu.varbinds.length; i++) {
  27. console.log (now + ": " + trapType + ": " + trap.rinfo.address + " : " + trap.pdu.varbinds[i].oid + " -> " + trap.pdu.varbinds[i].value);
  28. }
  29. }
  30. }
  31. }
  32. };
  33. var receiver = snmp.createReceiver(snmpOptions, cb);
  34. var authorizer = receiver.getAuthorizer ();
  35. authorizer.addCommunity ("public");
  36. authorizer.addUser ({
  37. name: "fred",
  38. level: snmp.SecurityLevel.noAuthNoPriv
  39. });
  40. authorizer.addUser ({
  41. name: "betty",
  42. level: snmp.SecurityLevel.authNoPriv,
  43. authProtocol: snmp.AuthProtocols.sha,
  44. authKey: "illhavesomeauth"
  45. });
  46. authorizer.addUser ({
  47. name: "wilma",
  48. level: snmp.SecurityLevel.authPriv,
  49. authProtocol: snmp.AuthProtocols.sha,
  50. authKey: "illhavesomeauth",
  51. privProtocol: snmp.PrivProtocols.des,
  52. privKey: "andsomepriv"
  53. });
  54. authorizer.addUser ({
  55. name: "barney",
  56. level: snmp.SecurityLevel.authPriv,
  57. authProtocol: snmp.AuthProtocols.sha,
  58. authKey: "illhavesomeauth",
  59. privProtocol: snmp.PrivProtocols.aes,
  60. privKey: "andsomepriv"
  61. });