Skip to content

SNMP

Walk and set SNMP v1/v2c/v3 OIDs.

See SNMP driver examples on GitHub.


Executes SNMP Get for a list of OIDs towards the device

Signature

D.device.snmpSession.get(oids, snmpCallback)

Parameters

oids · `Array.`
A list of OID strings to execute an SNMP Get towards.
snmpCallback · `function`
Called with `(error, varbinds)` when the SNMP operation completes.
snmpCallback.output · `Object.` · optional
The output object from the snmp query execution as a key-value pair for each oid and it corresponding value
snmpCallback.error · `ErrorResult` · optional
Will be present if the snmp query resulted in an error.

Returns

  • void

Example

D.device.createSNMPSession().get(['1.3.6.1.2.1.1.5.0', '1.3.6.1.2.1.1.7.0'], cb)

Executes SNMP Get for a list of OIDs towards the device and returns raw data without type conversion. This method provides access to both the SNMP object type and the raw value, allowing for custom parsing logic. The type values returned are the same constants available via the session.objectType property for easy comparison.

Signature

D.device.snmpSession.getRaw(oids, snmpCallback)

Parameters

oids · `Array.`
A list of OID strings to execute an SNMP Get towards.
snmpCallback · `function`
Callback function to handle the results
snmpCallback.output · `Object.` · optional
The output object from the snmp query execution as a key-value pair for each OID and a RawSNMPOutput object
snmpCallback.output.oid.type · `number` · optional
The SNMP object type. These are the same constants exposed via the objectType property. Values correspond to SNMP BER encoding and can be compared using session.objectType constants: - 0x02 (session.objectType.Integer): 32-bit signed integer - 0x04 (session.objectType.OctetString): Binary or text data as Buffer - 0x05 (session.objectType.Null): Null value - 0x06 (session.objectType.ObjectIdentifier): Object identifier string - 0x30 (session.objectType.Sequence): Sequence of values - 0x40 (session.objectType.IpAddress): IP address as 4-byte Buffer - 0x41 (session.objectType.Counter): 32-bit unsigned counter - 0x42 (session.objectType.Gauge): 32-bit unsigned gauge - 0x43 (session.objectType.TimeTicks): Time in centiseconds as Number - 0x44 (session.objectType.Opaque): Opaque binary data as Buffer - 0x45 (session.objectType.NsapAddress): NSAP address as Buffer - 0x46 (session.objectType.Counter64): 64-bit counter as Buffer - 0x80 (session.objectType.NoSuchObject): Error: object does not exist - 0x81 (session.objectType.NoSuchInstance): Error: instance does not exist - 0x82 (session.objectType.EndOfMibView): Error: end of MIB view reached - 0xA0 (session.objectType.PDUBase): PDU base type
snmpCallback.output.oid.value · `*` · optional
The raw value without type conversion. Type varies: - Number: for Integer, Counter, Gauge, TimeTicks - Buffer: for OctetString, Opaque, IpAddress, NsapAddress, Counter64 - String: for ObjectIdentifier - null: for Null - Object: for Sequence, error types
snmpCallback.error · `ErrorResult` · optional
Will be present if the snmp query resulted in an error.

Returns

  • void

Example

const session = D.device.createSNMPSession();
session.getRaw(['1.3.6.1.2.1.1.5.0', '1.3.6.1.2.1.1.7.0'], function(output, error) {
if (!error) {
for (const oid in output) {
const {type, value} = output[oid];
switch(type) {
case session.objectType.Integer:
console.log(`${oid}: Integer value = ${value}`);
break;
case session.objectType.OctetString:
console.log(`${oid}: String value = ${value.toString()}`);
break;
case session.objectType.IpAddress:
console.log(`${oid}: IP Address = ${Array.from(value).join('.')}`);
break;
case session.objectType.Counter64:
console.log(`${oid}: Counter64 = ${value.toString('hex')}`);
break;
default:
console.log(`${oid}: Type ${type.toString(16)}, Value:`, value);
}
}
}
});

SNMP Object Type constants for comparison with type values returned by getRaw method. These constants correspond to SNMP BER encoding types and can be used to identify the data type of values returned in SNMP operations.

Signature

D.device.snmpSession.objectType

Properties

Integer · `number`
0x02 - 32-bit signed integer
Integer32 · `number`
0x02 - 32-bit signed integer (alias)
OctetString · `number`
0x04 - Binary or text data
Null · `number`
0x05 - Null value
ObjectIdentifier · `number`
0x06 - Object identifier
Sequence · `number`
0x30 - Sequence of values
IpAddress · `number`
0x40 - IP address (4 bytes)
Counter · `number`
0x41 - 32-bit unsigned counter
Counter32 · `number`
0x41 - 32-bit unsigned counter (alias)
Gauge · `number`
0x42 - 32-bit unsigned gauge
Gauge32 · `number`
0x42 - 32-bit unsigned gauge (alias)
TimeTicks · `number`
0x43 - Time in centiseconds
Opaque · `number`
0x44 - Opaque binary data
NsapAddress · `number`
0x45 - NSAP address
Counter64 · `number`
0x46 - 64-bit counter
NoSuchObject · `number`
0x80 - Error: object does not exist
NoSuchInstance · `number`
0x81 - Error: instance does not exist
EndOfMibView · `number`
0x82 - Error: end of MIB view reached
PDUBase · `number`
0xA0 - PDU base type

Returns

  • object — A map of SNMP type constants (OctetString, Integer, Counter64, …) usable as the type field in session.set(...) varbinds.

Example

const session = D.device.createSNMPSession();
session.getRaw(['1.3.6.1.2.1.1.5.0'], function(output, error) {
if (!error) {
for (const oid in output) {
const {type, value} = output[oid];
if (type === session.objectType.Integer) {
console.log('Integer value:', value);
} else if (type === session.objectType.OctetString) {
console.log('String value:', value.toString());
} else if (type === session.objectType.Counter64) {
console.log('Counter64 value:', value.toString('hex'));
}
}
}
});

Executes SNMP Set for an OID with its respective value and OID type defined.

Signature

D.device.snmpSession.set(oid, value, snmpCallback)

Parameters

oid · `string`
The OID to perform the snmp set for. Must be writable.
value · `string` | `int`
The new value to set on that OID
snmpCallback · `function`
Called with `(error, varbinds)` when the SNMP operation completes.
snmpCallback.output · `Object.` · optional
The output object from the snmp query execution as a key-value pair for each oid and its corresponding value
snmpCallback.error · `ErrorResult` · optional
Will be present if the snmp query resulted in an error.

Returns

  • void

Example

D.device.createSNMPSession().set('1.3.6.1.2.1.1.5.0', 'new-snmp-name', cb)

Executes an SNMP Walk for an OID towards the device

Signature

D.device.snmpSession.walk(oid, snmpCallback)

Parameters

oid · `string`
The OID to perform the snmp walk for.
snmpCallback · `function`
Called with `(error, varbinds)` when the SNMP operation completes.
snmpCallback.output · `Object.` · optional
The output object from the snmp query execution as a key-value pair for each oid and it corresponding value
snmpCallback.error · `ErrorResult` · optional
Will be present if the snmp query resulted in an error.

Returns

  • void

Example

D.device.createSNMPSession().walk('1.3.6.1.2.1.1', cb)

Starts an SNMP session with the device.

Signature

D.device.createSNMPSession(options)

Parameters

options · `Object`
The SNMP Session Options
options.port · `integer` · optional, default `161`
UDP port to send requests to
options.timeout · `integer` · optional, default `5000`
The time the snmp session queries will persist for (in milisenconds).
options.maxRepetitions · `integer` · optional, default `24`
How many rows of a table are to be retrieved in a single GetBulk operation. Used in SNMP Walk
options.version · `integer` · optional, default `2`
SNMP Version to use. Possible values are 1, 2, or 3. Default is 2.
options.context · `string` · optional
The SNMP Context to use (only for SNMP v3)

Returns

  • D.device.snmpSession

Example

// returns an snmpSession object to use for snmp related queries
D.device.createSNMPSession()