net-snmp
A JavaScript implementation of SNMPv1, v2c, and v3 for polling network devices, sending traps and informs, and building SNMP agents in Node.js.
Repository Health
Technical Analysis
net-snmp is a pure-JavaScript implementation of the Simple Network Management Protocol covering versions 1, 2c, and 3, built for Node.js applications that need to poll, monitor, or manage network-attached devices such as routers, switches, and printers. It exposes session-based APIs for the standard SNMP operations (Get, GetNext, GetBulk, Set) plus convenience helpers for walking OID subtrees and collecting table data, alongside trap and inform generation and a notification receiver for the reverse direction.
Beyond the client side, the library also implements the less common half of the protocol: a full SNMP agent with MIB-backed scalar and tabular data management, RowStatus-based table row creation, an SNMP proxy forwarder, and an AgentX subagent implementation for integrating with a master agent like net-snmp’s C counterpart. SNMPv3 support includes USM authentication (MD5/SHA family) and privacy (DES/AES family) with RFC 3414-compliant authentication-failure handling, making it usable for both simple monitoring scripts and more complete network-management tooling.
What You Get
- Session-based client API (
createSession,createV3Session) supporting Get, GetNext, GetBulk, Set, Trap, and Inform operations - Convenience walkers for OID subtrees, MIB table collection, and table-column collection so callers don’t hand-roll GetNext/GetBulk loops
- A notification receiver (
createReceiver) for accepting inbound traps and informs from remote agents - A full SNMP agent (
createAgent) with a MIB provider store, scalar and tabular data support, and RowStatus-driven row creation/deletion - An AgentX subagent (
createSubagent) and SNMP proxy forwarder for integrating with master agents - SNMPv3 USM security: MD5/SHA/SHA-224/256/384/512 authentication and DES/AES/AES-256 privacy, with RFC 3414 §3.2 authentication-failure Report PDUs
Common Use Cases
- Polling routers, switches, UPSes, or printers for interface counters and health metrics from a Node.js monitoring service
- Receiving and reacting to SNMP traps/informs raised by network hardware (link down/up, cold/warm start, vendor enterprise traps)
- Exposing custom manageable data from a Node.js process as an SNMP agent for existing NMS tooling to poll
- Bridging a Node.js subagent into an existing AgentX master agent alongside other SNMP subagents
- Building CLI utilities (get/walk/bulk/set/trap) for ad-hoc network device inspection
Under The Hood
Architecture
The library is organized as a single large index.js (~6,900 lines) that defines the whole protocol stack: PDU classes (GetRequestPdu, GetBulkRequestPdu, TrapV2Pdu, etc.) built via util.inherits on a common SimplePdu/SimpleResponsePdu base, a Session class extending events.EventEmitter that owns a UDP socket and dispatches responses back to per-request callbacks by request ID, and parallel Agent/Subagent/Receiver classes that mirror the same event-driven request/response pattern for the server side of the protocol. MIB parsing and the module store live in a separate lib/mib.js, and DES support is isolated in lib/des.js/lib/des-ecb.js. The design favors one flat, deeply-featured file per protocol role over a layered module structure, so understanding any one operation means reading a large but internally consistent file rather than following code across many small modules.
Tech Stack
The runtime dependency surface is deliberately small: asn1-ber handles BER/DER encoding and decoding of SNMP’s ASN.1 wire format, and smart-buffer provides structured buffer reads/writes; everything else (dgram for UDP transport, net for AgentX’s TCP transport, crypto for USM auth/privacy, events for the emitter-based session/agent model) comes from Node’s standard library. There’s no build step or bundler — the package ships plain CommonJS index.js directly — and no TypeScript, so consumers get untyped callback-based APIs. Development tooling is ESLint (flat config) and Mocha for tests, with getopts used only in the CLI examples.
Code Quality
Tests live under test/*.test.js and run via Mocha (node --openssl-legacy-provider ./node_modules/mocha/bin/mocha.js), covering crypto/USM behavior, MIB parsing, object-type encoding, integer-range casting rules, and — per a dedicated test/README-test-coverage.md — an explicit RFC 3414 §3.2 compliance suite for SNMPv3 authentication-failure handling with itemized coverage of Report PDU generation, USM statistics counters, and reportable-flag semantics. ESLint is configured and run as the sole CI check declared in .travis.yaml, though that Travis config is legacy and no GitHub Actions workflow currently runs the suite on push. Error handling uses purpose-built error types (ResponseInvalidError, RequestFailedError, RequestTimedOutError) inheriting from Error rather than swallowing failures, but the codebase predates TypeScript adoption and carries no static type checking.
API Design
The public surface is a set of create* factory functions (createSession, createAgent, createReceiver, createSubagent, createModuleStore) returning EventEmitter-based objects with Node-idiomatic (error, result) callbacks — familiar to anyone who has used pre-Promise Node networking APIs, though there’s no Promise or async/await variant offered. Constants for versions, error statuses, object types, trap types, and security levels are all exported as named objects, and the README documents essentially the entire API surface at length, including copy-pasteable examples for every major operation (get, walk, bulk, trap, inform, agent, proxy, subagent). The tradeoff is a callback-only, single-file API that is comprehensive but not modernized to current JS idioms.
Used by 2 apps in this directory
OneUptime
Monitoring
The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.
Uptime Kuma
Monitoring
Self-hosted monitoring for every service you run — 23 monitor types, 95 notification channels, live dashboards, and public status pages with no vendor lock-in.