Node-Red configuration
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

option-parser.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var snmp = require ("../");
  2. var getopts = require ("getopts");
  3. var options = getopts(process.argv.slice(2), {
  4. string: ["e"]
  5. });
  6. var community;
  7. var user;
  8. var session;
  9. var nonRepeaters;
  10. var maxRepetitions;
  11. var oids;
  12. var varbinds;
  13. var columns;
  14. var snmpOptions = {};
  15. if ( ! options.v ) {
  16. options.v = snmp.Version1;
  17. }
  18. snmpOptions.version = snmp.Version[options.v];
  19. snmpOptions.debug = options.d;
  20. snmpOptions.transport = options.t;
  21. if ( snmpOptions.version == snmp.Version3 ) {
  22. if ( options.e ) {
  23. snmpOptions.engineID = options.e.toString();
  24. }
  25. user = {
  26. name: options.u,
  27. level: snmp.SecurityLevel[options.l]
  28. };
  29. if ( options.a ) {
  30. user.authProtocol = snmp.AuthProtocols[options.a.toLowerCase()];
  31. user.authKey = options.A;
  32. }
  33. if ( options.x ) {
  34. user.privProtocol = snmp.PrivProtocols[options.x.toLowerCase()];
  35. user.privKey = options.X;
  36. }
  37. snmpOptions.context = options.n;
  38. } else {
  39. community = options.c;
  40. }
  41. nonRepeaters = options.o;
  42. maxRepetitions = options.r;
  43. if (options._.length < 2) {
  44. console.log ("usage: " + process.argv[1] + " [<options>] <target> <oid>");
  45. process.exit (1);
  46. }
  47. var target = options._[0];
  48. var command = process.argv[1].split('/').slice(-1)[0];
  49. if ( command.includes('snmp-set') ) {
  50. varbinds = [{
  51. oid: options._[1],
  52. type: snmp.ObjectType[options._[2]],
  53. value: options._[3]
  54. }];
  55. } else if ( command.includes('snmp-table-columns') ) {
  56. oids = [options._[1]];
  57. columns = [];
  58. for (var i = 1; i < options._.length; i++) {
  59. columns.push (options._[i]);
  60. }
  61. } else {
  62. oids = [];
  63. for (var j = 1; j < options._.length; j++) {
  64. oids.push (options._[j]);
  65. }
  66. }
  67. if ( command.includes('snmp-trap') || command.includes('snmp-inform') || command.includes('snmp-receiver') ) {
  68. snmpOptions.trapPort = options.p;
  69. } else {
  70. snmpOptions.port = options.p;
  71. }
  72. if ( snmpOptions.version == snmp.Version3 ) {
  73. session = snmp.createV3Session (target, user, snmpOptions);
  74. } else {
  75. session = snmp.createSession (target, community, snmpOptions);
  76. }
  77. exports.session = session;
  78. exports.oids = oids;
  79. exports.varbinds = varbinds;
  80. exports.nonRepeaters = nonRepeaters;
  81. exports.maxRepetitions = maxRepetitions;
  82. exports.columns = columns;