Skip to content

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.

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.

D.device.createSNMPSession({ version: '2c', community: 'public' });
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 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.

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
});
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).

WhatOID
sysDescr1.3.6.1.2.1.1.1.0
sysUpTime1.3.6.1.2.1.1.3.0
sysName1.3.6.1.2.1.1.5.0
ifTable1.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

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.