net-snmp 3.21.0 → 3.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
 - package/example/snmp-agent-snmpv2mib.js +44 -0
 - package/example/snmp-agent.js +1 -1
 - package/index.js +19 -13
 - package/package.json +1 -1
 - package/test/mib.test.js +1 -1
 
    
        package/README.md
    CHANGED
    
    | 
         @@ -3521,6 +3521,14 @@ Example programs are included under the module's `example` directory. 
     | 
|
| 
       3521 
3521 
     | 
    
         | 
| 
       3522 
3522 
     | 
    
         
             
             * Add AgentX subagent mib and mibOptions on initialization
         
     | 
| 
       3523 
3523 
     | 
    
         | 
| 
      
 3524 
     | 
    
         
            +
            # Version 3.21.1 - 26/04/2025
         
     | 
| 
      
 3525 
     | 
    
         
            +
             
     | 
| 
      
 3526 
     | 
    
         
            +
             * Add better defval type handling, improved debug handling and simple agent example
         
     | 
| 
      
 3527 
     | 
    
         
            +
             
     | 
| 
      
 3528 
     | 
    
         
            +
            # Version 3.21.2 - 27/04/2025
         
     | 
| 
      
 3529 
     | 
    
         
            +
             
     | 
| 
      
 3530 
     | 
    
         
            +
             * Add custom base module list
         
     | 
| 
      
 3531 
     | 
    
         
            +
             
     | 
| 
       3524 
3532 
     | 
    
         
             
            # License
         
     | 
| 
       3525 
3533 
     | 
    
         | 
| 
       3526 
3534 
     | 
    
         
             
            Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
         
     | 
| 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const snmp = require ("..");
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            // Create a module store, which contains SNMPv2-MIB and other modules
         
     | 
| 
      
 4 
     | 
    
         
            +
            const store = snmp.createModuleStore ();
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            // Fetch MIB providers for SNMPv2-MIB, create an agent, and register the providers with the agent's MIB
         
     | 
| 
      
 7 
     | 
    
         
            +
            const providers = store.getProvidersForModule ("SNMPv2-MIB");
         
     | 
| 
      
 8 
     | 
    
         
            +
            const agentOptions = {
         
     | 
| 
      
 9 
     | 
    
         
            +
                port: 1161
         
     | 
| 
      
 10 
     | 
    
         
            +
            };
         
     | 
| 
      
 11 
     | 
    
         
            +
            const agentCallback = function (error, data) {
         
     | 
| 
      
 12 
     | 
    
         
            +
                if ( error ) {
         
     | 
| 
      
 13 
     | 
    
         
            +
                    console.error (error);
         
     | 
| 
      
 14 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 15 
     | 
    
         
            +
                    console.log (JSON.stringify(data, null, 2));
         
     | 
| 
      
 16 
     | 
    
         
            +
                }
         
     | 
| 
      
 17 
     | 
    
         
            +
            };
         
     | 
| 
      
 18 
     | 
    
         
            +
            const agent = snmp.createAgent ( agentOptions, agentCallback );
         
     | 
| 
      
 19 
     | 
    
         
            +
            const mib = agent.getMib ();
         
     | 
| 
      
 20 
     | 
    
         
            +
            mib.registerProviders (providers);
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            // Add community and user to agent's authorizer
         
     | 
| 
      
 23 
     | 
    
         
            +
            const authorizer = agent.getAuthorizer ();
         
     | 
| 
      
 24 
     | 
    
         
            +
            authorizer.addCommunity ("private");
         
     | 
| 
      
 25 
     | 
    
         
            +
            authorizer.addUser ({
         
     | 
| 
      
 26 
     | 
    
         
            +
                name: "wilma",
         
     | 
| 
      
 27 
     | 
    
         
            +
                level: snmp.SecurityLevel.authPriv,
         
     | 
| 
      
 28 
     | 
    
         
            +
                authProtocol: snmp.AuthProtocols.sha,
         
     | 
| 
      
 29 
     | 
    
         
            +
                authKey: "illhavesomeauth",
         
     | 
| 
      
 30 
     | 
    
         
            +
                privProtocol: snmp.PrivProtocols.aes,
         
     | 
| 
      
 31 
     | 
    
         
            +
                privKey: "andsomepriv"
         
     | 
| 
      
 32 
     | 
    
         
            +
            });
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            // Start adding data to the MIB through the registered providers using the `Mib` API calls
         
     | 
| 
      
 35 
     | 
    
         
            +
            mib.setScalarValue ("sysDescr", "The most powerful system you can think of");
         
     | 
| 
      
 36 
     | 
    
         
            +
            mib.setScalarValue ("sysObjectID", "1.3.6.1.4.1.8072.3.2.10");
         
     | 
| 
      
 37 
     | 
    
         
            +
            mib.setScalarValue ("sysContact", "You");
         
     | 
| 
      
 38 
     | 
    
         
            +
            mib.setScalarValue ("sysName", "megamind");
         
     | 
| 
      
 39 
     | 
    
         
            +
            mib.setScalarValue ("sysLocation", "Yours");
         
     | 
| 
      
 40 
     | 
    
         
            +
            mib.setScalarValue ("sysORLastChange", 710);
         
     | 
| 
      
 41 
     | 
    
         
            +
            mib.addTableRow ("sysOREntry", [1, "1.3.6.1.4.1.47491.42.43.44.45", "I've dreamed up this MIB", 20]);
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            // Dump the resulting MIB to the console
         
     | 
| 
      
 44 
     | 
    
         
            +
            mib.dump ();
         
     | 
    
        package/example/snmp-agent.js
    CHANGED
    
    | 
         @@ -264,7 +264,7 @@ mib.dump ({ 
     | 
|
| 
       264 
264 
     | 
    
         
             
            // var data = mib.getTableColumnCells ("ifTable", 2);
         
     | 
| 
       265 
265 
     | 
    
         
             
            // var data = mib.getTableRowCells ("ifTable", [1]);
         
     | 
| 
       266 
266 
     | 
    
         
             
            // mib.setTableSingleCell ("ifTable", 2, [2], "changed!");
         
     | 
| 
       267 
     | 
    
         
            -
            mib.setTableSingleCell ("ifTable", 3, [2],  
     | 
| 
      
 267 
     | 
    
         
            +
            mib.setTableSingleCell ("ifTable", 3, [2], 24);
         
     | 
| 
       268 
268 
     | 
    
         
             
            var data = mib.getTableSingleCell ("ifTable", 3, [2]);
         
     | 
| 
       269 
269 
     | 
    
         
             
            // var data = mib.getScalarValue ("sysDescr");
         
     | 
| 
       270 
270 
     | 
    
         | 
    
        package/index.js
    CHANGED
    
    | 
         @@ -21,9 +21,13 @@ const MAX_UNSIGNED_INT64 = 18446744073709551615; 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
            const DES_IMPLEMENTATION = 'library';
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
            // Use test harness trace or debug functions falling back to console.debug in normal mode.
         
     | 
| 
      
 25 
     | 
    
         
            +
            // eslint-disable-next-line no-undef
         
     | 
| 
      
 26 
     | 
    
         
            +
            var debugfn = typeof(global.debug) === 'function'? global.trace ?? global.debug : console.debug;
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            function debug () {
         
     | 
| 
       25 
29 
     | 
    
         
             
            	if ( DEBUG ) {
         
     | 
| 
       26 
     | 
    
         
            -
            		 
     | 
| 
      
 30 
     | 
    
         
            +
            		debugfn.apply (this, arguments);
         
     | 
| 
       27 
31 
     | 
    
         
             
            	}
         
     | 
| 
       28 
32 
     | 
    
         
             
            }
         
     | 
| 
       29 
33 
     | 
    
         | 
| 
         @@ -2031,7 +2035,7 @@ var Session = function (target, authenticator, options) { 
     | 
|
| 
       2031 
2035 
     | 
    
         
             
                        ? options.reportOidMismatchErrors
         
     | 
| 
       2032 
2036 
     | 
    
         
             
                        : false;
         
     | 
| 
       2033 
2037 
     | 
    
         | 
| 
       2034 
     | 
    
         
            -
            	DEBUG  
     | 
| 
      
 2038 
     | 
    
         
            +
            	DEBUG |= options.debug;
         
     | 
| 
       2035 
2039 
     | 
    
         | 
| 
       2036 
2040 
     | 
    
         
             
            	this.engine = new Engine ({
         
     | 
| 
       2037 
2041 
     | 
    
         
             
            		engineId: options.engineID
         
     | 
| 
         @@ -3348,7 +3352,7 @@ SimpleAccessControlModel.prototype.isAccessAllowed = function (securityModel, se 
     | 
|
| 
       3348 
3352 
     | 
    
         
             
             **/
         
     | 
| 
       3349 
3353 
     | 
    
         | 
| 
       3350 
3354 
     | 
    
         
             
            var Receiver = function (options, callback) {
         
     | 
| 
       3351 
     | 
    
         
            -
            	DEBUG  
     | 
| 
      
 3355 
     | 
    
         
            +
            	DEBUG |= options.debug;
         
     | 
| 
       3352 
3356 
     | 
    
         
             
            	this.authorizer = new Authorizer (options);
         
     | 
| 
       3353 
3357 
     | 
    
         
             
            	this.engine = new Engine ({
         
     | 
| 
       3354 
3358 
     | 
    
         
             
            		engineId: options.engineID
         
     | 
| 
         @@ -3451,7 +3455,8 @@ Receiver.create = function (options, callback) { 
     | 
|
| 
       3451 
3455 
     | 
    
         
             
            	return receiver;
         
     | 
| 
       3452 
3456 
     | 
    
         
             
            };
         
     | 
| 
       3453 
3457 
     | 
    
         | 
| 
       3454 
     | 
    
         
            -
            var ModuleStore = function () {
         
     | 
| 
      
 3458 
     | 
    
         
            +
            var ModuleStore = function (baseModules) {
         
     | 
| 
      
 3459 
     | 
    
         
            +
            	this.baseModules = baseModules ?? ModuleStore.BASE_MODULES;
         
     | 
| 
       3455 
3460 
     | 
    
         
             
            	this.parser = mibparser ();
         
     | 
| 
       3456 
3461 
     | 
    
         
             
            	this.translations = {
         
     | 
| 
       3457 
3462 
     | 
    
         
             
            		oidToPath: {},
         
     | 
| 
         @@ -3541,7 +3546,7 @@ ModuleStore.prototype.getModule = function (moduleName) { 
     | 
|
| 
       3541 
3546 
     | 
    
         
             
            ModuleStore.prototype.getModules = function (includeBase) {
         
     | 
| 
       3542 
3547 
     | 
    
         
             
            	var modules = {};
         
     | 
| 
       3543 
3548 
     | 
    
         
             
            	for ( var moduleName of Object.keys(this.parser.Modules) ) {
         
     | 
| 
       3544 
     | 
    
         
            -
            		if ( includeBase ||  
     | 
| 
      
 3549 
     | 
    
         
            +
            		if ( includeBase || this.baseModules.indexOf (moduleName) == -1 ) {
         
     | 
| 
       3545 
3550 
     | 
    
         
             
            			modules[moduleName] = this.parser.Modules[moduleName];
         
     | 
| 
       3546 
3551 
     | 
    
         
             
            		}
         
     | 
| 
       3547 
3552 
     | 
    
         
             
            	}
         
     | 
| 
         @@ -3551,7 +3556,7 @@ ModuleStore.prototype.getModules = function (includeBase) { 
     | 
|
| 
       3551 
3556 
     | 
    
         
             
            ModuleStore.prototype.getModuleNames = function (includeBase) {
         
     | 
| 
       3552 
3557 
     | 
    
         
             
            	var modules = [];
         
     | 
| 
       3553 
3558 
     | 
    
         
             
            	for ( var moduleName of Object.keys(this.parser.Modules) ) {
         
     | 
| 
       3554 
     | 
    
         
            -
            		if ( includeBase ||  
     | 
| 
      
 3559 
     | 
    
         
            +
            		if ( includeBase || this.baseModules.indexOf (moduleName) == -1 ) {
         
     | 
| 
       3555 
3560 
     | 
    
         
             
            			modules.push (moduleName);
         
     | 
| 
       3556 
3561 
     | 
    
         
             
            		}
         
     | 
| 
       3557 
3562 
     | 
    
         
             
            	}
         
     | 
| 
         @@ -3725,7 +3730,7 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) { 
     | 
|
| 
       3725 
3730 
     | 
    
         
             
            };
         
     | 
| 
       3726 
3731 
     | 
    
         | 
| 
       3727 
3732 
     | 
    
         
             
            ModuleStore.prototype.loadBaseModules = function () {
         
     | 
| 
       3728 
     | 
    
         
            -
            	for ( var mibModule of  
     | 
| 
      
 3733 
     | 
    
         
            +
            	for ( var mibModule of this.baseModules ) {
         
     | 
| 
       3729 
3734 
     | 
    
         
             
            		this.parser.Import (__dirname + "/lib/mibs/" + mibModule + ".mib");
         
     | 
| 
       3730 
3735 
     | 
    
         
             
            	}
         
     | 
| 
       3731 
3736 
     | 
    
         
             
            	this.parser.Serialize ();
         
     | 
| 
         @@ -3809,8 +3814,8 @@ ModuleStore.prototype.translate = function (name, destinationFormat) { 
     | 
|
| 
       3809 
3814 
     | 
    
         
             
            	}
         
     | 
| 
       3810 
3815 
     | 
    
         
             
            };
         
     | 
| 
       3811 
3816 
     | 
    
         | 
| 
       3812 
     | 
    
         
            -
            ModuleStore.create = function () {
         
     | 
| 
       3813 
     | 
    
         
            -
            	 
     | 
| 
      
 3817 
     | 
    
         
            +
            ModuleStore.create = function (options) {
         
     | 
| 
      
 3818 
     | 
    
         
            +
            	const store = new ModuleStore (options?.baseModules ?? ModuleStore.BASE_MODULES);
         
     | 
| 
       3814 
3819 
     | 
    
         
             
            	store.loadBaseModules ();
         
     | 
| 
       3815 
3820 
     | 
    
         
             
            	return store;
         
     | 
| 
       3816 
3821 
     | 
    
         
             
            };
         
     | 
| 
         @@ -4272,7 +4277,8 @@ Mib.prototype.registerProvider = function (provider) { 
     | 
|
| 
       4272 
4277 
     | 
    
         
             
            			if ( provider.constraints?.enumeration ) {
         
     | 
| 
       4273 
4278 
     | 
    
         
             
            				scalarValue = ObjectTypeUtil.getEnumerationNumberFromName (provider.constraints.enumeration, provider.defVal);
         
     | 
| 
       4274 
4279 
     | 
    
         
             
            			} else {
         
     | 
| 
       4275 
     | 
    
         
            -
            				 
     | 
| 
      
 4280 
     | 
    
         
            +
            				// Remove quotes from strings and resolve numeric strings to integers
         
     | 
| 
      
 4281 
     | 
    
         
            +
            				scalarValue = JSON.parse(provider.defVal);
         
     | 
| 
       4276 
4282 
     | 
    
         
             
            			}
         
     | 
| 
       4277 
4283 
     | 
    
         
             
            			this.setScalarValue (provider.name, scalarValue);
         
     | 
| 
       4278 
4284 
     | 
    
         
             
            		}
         
     | 
| 
         @@ -4865,7 +4871,7 @@ MibRequest.prototype.isTabular = function () { 
     | 
|
| 
       4865 
4871 
     | 
    
         
             
            };
         
     | 
| 
       4866 
4872 
     | 
    
         | 
| 
       4867 
4873 
     | 
    
         
             
            var Agent = function (options, callback, mib) {
         
     | 
| 
       4868 
     | 
    
         
            -
            	DEBUG  
     | 
| 
      
 4874 
     | 
    
         
            +
            	DEBUG |= options.debug;
         
     | 
| 
       4869 
4875 
     | 
    
         
             
            	this.listener = new Listener (options, this);
         
     | 
| 
       4870 
4876 
     | 
    
         
             
            	this.engine = new Engine ({
         
     | 
| 
       4871 
4877 
     | 
    
         
             
            		engineId: options.engineID
         
     | 
| 
         @@ -4986,7 +4992,7 @@ Agent.prototype.onMsg = function (socket, buffer, rinfo) { 
     | 
|
| 
       4986 
4992 
     | 
    
         
             
            	}
         
     | 
| 
       4987 
4993 
     | 
    
         | 
| 
       4988 
4994 
     | 
    
         
             
            	// Request processing
         
     | 
| 
       4989 
     | 
    
         
            -
            	 
     | 
| 
      
 4995 
     | 
    
         
            +
            	debug (message.pdu);
         
     | 
| 
       4990 
4996 
     | 
    
         
             
            	if ( message.pdu.contextName && message.pdu.contextName != "" ) {
         
     | 
| 
       4991 
4997 
     | 
    
         
             
            		this.onProxyRequest (socket, message, rinfo);
         
     | 
| 
       4992 
4998 
     | 
    
         
             
            	} else if ( message.pdu.type == PduType.GetRequest ) {
         
     | 
    
        package/package.json
    CHANGED
    
    
    
        package/test/mib.test.js
    CHANGED
    
    | 
         @@ -122,7 +122,7 @@ describe('MIB', function () { 
     | 
|
| 
       122 
122 
     | 
    
         
             
                        };
         
     | 
| 
       123 
123 
     | 
    
         
             
                        mib = snmp.createMib(options);
         
     | 
| 
       124 
124 
     | 
    
         
             
                        mib.registerProviders(mibProviders);
         
     | 
| 
       125 
     | 
    
         
            -
                        assert. 
     | 
| 
      
 125 
     | 
    
         
            +
                        assert.strictEqual(mib.getScalarValue('testScalarIntegerDefval'), 49);
         
     | 
| 
       126 
126 
     | 
    
         
             
                    });
         
     | 
| 
       127 
127 
     | 
    
         
             
                });
         
     | 
| 
       128 
128 
     | 
    
         |