SNMP
The sandbox exposes a session-based SNMP client. Open a session via D.device.createSNMPSession(), reuse it for get / walk / getRaw, then close it.
Quick shape
Section titled “Quick shape”function get_status() { var session = D.device.createSNMPSession({ version: '2c', community: 'public' }); session.get(['1.3.6.1.2.1.1.5.0', '1.3.6.1.2.1.1.3.0'], function (error, varbinds) { if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE); var hostname = varbinds[0].value.toString(); var uptime = varbinds[1].value; session.close(); D.success([ D.createVariable('host', 'Hostname', hostname, '', D.valueType.STRING), D.createVariable('uptime', 'Uptime', uptime, 'ticks', D.valueType.NUMBER) ]); });}Each varbind in the callback is { oid, type, value }. The value comes as a Buffer for OCTET STRING — call .toString() to get text.
Versions
Section titled “Versions”v1 / v2c — community-based
Section titled “v1 / v2c — community-based”D.device.createSNMPSession({ version: '2c', community: 'public' });v3 — user-based security
Section titled “v3 — user-based security”D.device.createSNMPSession({ version: '3', user: { name: 'monitoring', authProtocol: 'SHA', authKey: 'authPassphrase', privProtocol: 'AES', privKey: 'privPassphrase' }});If the device is noAuthNoPriv, omit authProtocol / privProtocol entirely. If authNoPriv, supply only authProtocol + authKey.
Walk (subtree)
Section titled “Walk (subtree)”walk returns every OID under a subtree:
session.walk('1.3.6.1.2.1.2.2.1.2', function (error, varbinds) { if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE); var ifaces = D.createTable('Interfaces', [{ label: 'Name' }]); varbinds.forEach(function (vb, idx) { ifaces.insertRecord('if' + idx, [vb.value.toString()]); }); session.close(); D.success(ifaces);});Walks can be expensive on devices with large MIBs. Pass a specific root OID, not the tree root.
Raw (single OID, raw bytes)
Section titled “Raw (single OID, raw bytes)”Use getRaw when you need the unparsed bytes — for counter64 values, or vendor-specific encodings:
session.getRaw('1.3.6.1.2.1.31.1.1.1.10.1', function (error, raw) { if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE); // raw is the Buffer exactly as received});Set (write)
Section titled “Set (write)”session.set([ { oid: '1.3.6.1.2.1.1.5.0', type: 'OctetString', value: 'new-hostname' }], function (error, varbinds) { if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE);});Type constants are exposed on session.objectType (for example session.objectType.OctetString).
Common OIDs
Section titled “Common OIDs”| What | OID |
|---|---|
| sysDescr | 1.3.6.1.2.1.1.1.0 |
| sysUpTime | 1.3.6.1.2.1.1.3.0 |
| sysName | 1.3.6.1.2.1.1.5.0 |
| ifTable | 1.3.6.1.2.1.2.2 |
| ifDescr (walk) | 1.3.6.1.2.1.2.2.1.2 |
| ifInOctets (walk) | 1.3.6.1.2.1.2.2.1.10 |
| hrProcessorLoad (walk) | 1.3.6.1.2.1.25.3.3.1.2 |
Closing the session
Section titled “Closing the session”Always call session.close() when done, even on the error path. Leaked sessions accumulate across ticks and will eventually exhaust the collector’s SNMP pool.