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.

mib-parser.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* eslint-disable no-unused-vars */
  2. var snmp = require ("../");
  3. var getopts = require ("getopts");
  4. var options = getopts(process.argv.slice(2));
  5. var providers;
  6. var mibDir = '/var/tmp/mibs/';
  7. var counter64 = function (num) {
  8. var buf = Buffer.alloc (4);
  9. buf.writeUInt32BE (num);
  10. return buf;
  11. };
  12. var snmpOptions = {
  13. disableAuthorization: options.n,
  14. port: options.p,
  15. engineID: options.e,
  16. debug: options.d
  17. };
  18. var callback = function (error, data) {
  19. if ( error ) {
  20. console.error (error);
  21. } else {
  22. console.log (data.pdu.varbinds[0].oid);
  23. }
  24. };
  25. var store = snmp.createModuleStore ();
  26. var agent = snmp.createAgent (snmpOptions, callback);
  27. var mib = agent.getMib ();
  28. var authorizer = agent.getAuthorizer ();
  29. authorizer.addCommunity ("public");
  30. // IF-MIB load and providers registration
  31. store.loadFromFile (mibDir + "IANAifType-MIB.mib");
  32. store.loadFromFile (mibDir + "IF-MIB.mib");
  33. providers = store.getProvidersForModule ("IF-MIB");
  34. mib.registerProviders (providers);
  35. // ifNumber
  36. // Scalar type - setScalarValue() and getScalarValue() are the entire API for these
  37. mib.setScalarValue ("ifNumber", 5);
  38. var ifNumberValue = mib.getScalarValue ("ifNumber", 5);
  39. // console.log (ifNumberValue);
  40. // ifEntry
  41. // Simplest table index - a single-column local index
  42. mib.addTableRow ("ifEntry", [1, "eth0", 6, 1500, 1000, "", 1, 1, 10, 1000, 100, 10, 0, 0, 0, 2000, 200, 20, 0, 0, 5, "0.0"]);
  43. mib.addTableRow ("ifEntry", [2, "eth1", 6, 1500, 1000, "", 1, 1, 10, 1000, 100, 10, 0, 0, 0, 2000, 200, 20, 0, 0, 5, "0.0"]);
  44. mib.setTableSingleCell ("ifEntry", 2, [1], "eth2");
  45. var ifEntryRow1 = mib.getTableRowCells ("ifEntry", [2]);
  46. // console.log (ifEntryRow1);
  47. // ifXEntry
  48. // AUGMENTS ifEntry - meaning a single integer foreign key
  49. mib.addTableRow ("ifXEntry", [1, "eth0", 10, 2, 20, 4, counter64(1000), counter64(100), counter64(50), counter64(20),
  50. counter64(2000), counter64(200), counter64(100), counter64(40), 1, 1000, 0, 1, "myeth0", 10]);
  51. var ifXEntryRow1 = mib.getTableRowCells ("ifXEntry", [1]);
  52. // console.log (ifXEntryRow1);
  53. var ifXEntryData1 = mib.getTableCells ("ifXEntry", false, false);
  54. var ifXEntryData2 = mib.getTableCells ("ifXEntry", true, false);
  55. var ifXEntryData3 = mib.getTableCells ("ifXEntry", false, true);
  56. var ifXEntryData4 = mib.getTableCells ("ifXEntry", true, true);
  57. mib.setTableSingleCell ("ifXEntry", 1, [1], "another0");
  58. // ifStackEntry
  59. // Composite index - two local columns
  60. mib.addTableRow ("ifStackEntry", [1, 2, 1]);
  61. mib.addTableRow ("ifStackEntry", [3, 4, 2]);
  62. //mib.deleteTableRow ("ifStackEntry", [2, 3]);
  63. // var data = mib.getTableCells ("ifStackEntry");
  64. var ifStackEntryColumn1 = mib.getTableColumnCells ("ifStackEntry", 3, true);
  65. var ifStackEntryData1 = mib.getTableCells ("ifStackEntry", false, false);
  66. var ifStackEntryData2 = mib.getTableCells ("ifStackEntry", true, false);
  67. var ifStackEntryData3 = mib.getTableCells ("ifStackEntry", false, true);
  68. var ifStackEntryData4 = mib.getTableCells ("ifStackEntry", true, true);
  69. var ifStackEntryRow1 = mib.getTableRowCells ("ifStackEntry", [3, 4]);
  70. var ifStackEntryCell1 = mib.getTableSingleCell ("ifStackEntry", 3, [1, 2]);
  71. // ifRcvAddressEntry
  72. // Composite index - one foreign integer column, one local string column
  73. mib.addTableRow ("ifRcvAddressEntry", [1, "24:41:8c:08:87:5c", 1, 6]);
  74. var ifRcvAddressEntryRow1 = mib.getTableRowCells ("ifRcvAddressEntry", [1, "24:41:8c:08:87:5c"]);
  75. var ifRcvAddressEntryCell1 = mib.getTableSingleCell ("ifRcvAddressEntry", 3, [1, "24:41:8c:08:87:5c"]);
  76. var ifRcvAddressEntryData1 = mib.getTableCells ("ifRcvAddressEntry", false, false);
  77. var ifRcvAddressEntryData2 = mib.getTableCells ("ifRcvAddressEntry", true, false);
  78. var ifRcvAddressEntryData3 = mib.getTableCells ("ifRcvAddressEntry", false, true);
  79. var ifRcvAddressEntryData4 = mib.getTableCells ("ifRcvAddressEntry", true, true);
  80. // SNMP-COMMUNITY-MIB
  81. store.loadFromFile (mibDir + "SNMP-FRAMEWORK-MIB.mib");
  82. store.loadFromFile (mibDir + "SNMP-TARGET-MIB.mib");
  83. store.loadFromFile (mibDir + "SNMP-COMMUNITY-MIB.mib");
  84. providers = store.getProvidersForModule ("SNMP-TARGET-MIB");
  85. mib.registerProviders (providers);
  86. providers = store.getProvidersForModule ("SNMP-COMMUNITY-MIB");
  87. mib.registerProviders (providers);
  88. mib.addTableRow ("snmpCommunityEntry", ["mark", "public", "publicsec", "80001234", "", "", 1, 1]);
  89. // SNMPv2-MIB - loaded as part of base module load
  90. // store.loadFromFile (mibDir + "SNMPv2-MIB.mib");
  91. providers = store.getProvidersForModule ("SNMPv2-MIB");
  92. mib.registerProviders (providers);
  93. mib.setScalarValue ("sysDescr", "The most powerful system you can think of");
  94. mib.setScalarValue ("sysName", "multiplied-by-six");
  95. mib.addTableRow ("sysOREntry", [1, "1.3.6.1.4.1.47491.42.43.44.45", "I've dreamed up this MIB", 20]);
  96. // agent.getMib ().dumpProviders ();
  97. // mib.dump ();
  98. var modules = store.getModules (true);
  99. var one = store.getModule ("SNMPv2-MIB");
  100. var names = store.getModuleNames (true);
  101. // console.log("All modules: ", JSON.stringify(modules, '', 2));
  102. console.log("Modules: ", names);
  103. console.log("Single module definition: ", JSON.stringify(one, '', 2));