Node-Red configuration
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

agentx-subagent.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var snmp = require ("../");
  2. var getopts = require ("getopts");
  3. var options = getopts(process.argv.slice(2));
  4. var snmpOptions = {
  5. debug: options.d,
  6. master: options.m,
  7. port: options.p
  8. };
  9. var agent = snmp.createSubagent(snmpOptions);
  10. var stringProvider = {
  11. name: "scalarString",
  12. type: snmp.MibProviderType.Scalar,
  13. oid: "1.3.6.1.4.1.8072.9999.9999.1",
  14. scalarType: snmp.ObjectType.OctetString
  15. };
  16. var intProvider = {
  17. name: "scalarInt",
  18. type: snmp.MibProviderType.Scalar,
  19. oid: "1.3.6.1.4.1.8072.9999.9999.3",
  20. scalarType: snmp.ObjectType.Integer
  21. };
  22. var tableProvider = {
  23. name: "smallIfTable",
  24. type: snmp.MibProviderType.Table,
  25. oid: "1.3.6.1.4.1.8072.9999.9999.2",
  26. tableColumns: [
  27. {
  28. number: 1,
  29. name: "ifIndex",
  30. type: snmp.ObjectType.Integer
  31. },
  32. {
  33. number: 2,
  34. name: "ifDescr",
  35. type: snmp.ObjectType.OctetString
  36. },
  37. {
  38. number: 3,
  39. name: "ifType",
  40. type: snmp.ObjectType.Integer
  41. }
  42. ],
  43. tableIndex: [
  44. {
  45. columnName: "ifIndex"
  46. }
  47. ],
  48. handler: function (mibRequest) {
  49. // e.g. can update the table before responding to the request here
  50. mibRequest.done ();
  51. }
  52. };
  53. agent.open(function (error, data) {
  54. if ( error ) {
  55. console.error (error);
  56. } else {
  57. agent.registerProvider (stringProvider, null);
  58. agent.getMib ().setScalarValue ("scalarString", "Rage inside the machine!");
  59. agent.registerProvider (intProvider, null);
  60. agent.getMib ().setScalarValue ("scalarInt", 2000);
  61. agent.registerProvider (tableProvider, null);
  62. agent.getMib ().addTableRow ("smallIfTable", [1, "lo", 24]);
  63. agent.getMib ().addTableRow ("smallIfTable", [2, "eth0", 6]);
  64. }
  65. });
  66. // setTimeout( function() {
  67. // agent.open();
  68. // agent.close();
  69. // agent.unregisterProvider (intProvider.name, null);
  70. // agent.addAgentCaps ("1.3.6.1.4.1.8072.9999.9999", "Marks funk");
  71. // agent.removeAgentCaps ("1.3.6.1.4.1.8072.9999.9999");
  72. // agent.ping (function(error, pdu) {
  73. // console.log("Received ping response:");
  74. // console.log(pdu);
  75. // });
  76. // agent.notify(snmp.TrapType.ColdStart);
  77. // }, 5000);