snmp2otel periodically sends SNMPv2c GET requests to a given agent and forwards the values it gets back as OpenTelemetry metrics - a bridge between the old world of network monitoring (SNMP) and a modern observability stack (OTEL).
It only cares about scalar OIDs (the ones ending in .0) - typically counters and gauges from the agent’s MIB, not whole subtrees.
The Simple Network Management Protocol is a standard from the early nineties that is still used to read data from routers, switches, printers or UPS units. If there is a chart of a company link’s load hanging somewhere, chances are the data behind it came over SNMP.
1.3.6.1.2.1.1.3.0 is the device’s uptime.GetRequest with a list of OIDs over UDP and the agent answers with the same structure filled in with the values.The .0 suffix of an OID means a scalar value, that is one specific number, not a table. The program deliberately handles only these - tables would require walking a subtree, which is a different task.
OpenTelemetry is an open, vendor-neutral standard for collecting telemetry - metrics, traces and logs. It solves the situation where every monitoring tool had its own format and its own agent, and moving elsewhere meant redoing the instrumentation of the whole application.
So why build a bridge: devices speaking SNMP are everywhere and will not disappear any time soon, but a modern observability stack speaks OTLP. The exporter is a translator between those two worlds.
The input is the agent’s address and a file with a list of OIDs (one per line, comments with #); the output is the JSON request body that the program sends to the collector’s OTLP/HTTP endpoint:
./snmp2otel -t 127.0.0.1 -o ./oids.txt \
-e http://127.0.0.1:4318/v1/metrics -p 1161 -v
# oids.txt:
1.3.6.1.2.1.1.3.0
1.3.6.1.4.1.9999.1.1.0
1.3.6.1.4.1.9999.1.2.0
1.3.6.1.4.1.9999.1.3.0{
"resourceMetrics": [{
"resource": { "attributes": [
{ "key": "service.name",
"value": { "stringValue": "snmp2otel" } }
]},
"scopeMetrics": [{
"scope": { "name": "snmp2otel" },
"metrics": [{
"name": "snmp.1.3.6.1.2.1.1.3.0",
"unit": "",
"gauge": { "dataPoints": [{
"timeUnixNano": "1732820000000000000",
"asDouble": 483920
}]}
}]
}]
}]
}cli.hpp) reads the target, community string, port, timeout and interval.ber.cpp) builds the SNMPv2c GetRequest packet - no external SNMP library.VarBind values (Integer, OctetString, OID, Counter32, Gauge32, TimeTicks, Counter64…).cpp-httplib.-i seconds for as long as the program runs.The project keeps headers in include/ and the implementation in src/. Each pair corresponds to one layer on the way from the command line to the HTTP request sent:
| Module | Responsibility |
|---|---|
| ber | ASN.1/BER encoding and decoding — lengths, integers, octet strings, OIDs, reading TLV elements |
| cli | Processing options into the Options structure, printing usage |
| snmp | Building GetRequest, parsing GetResponse, UDP round trip with retries |
| otel | Parsing the endpoint URL, building OTLP JSON, sending it over HTTP |
| vlog | Verbose logging through a single global switch |
| main | Reading the OID file and the main polling loop |
| tests/ | Tests for ber, snmp and otel (GoogleTest) |
| third_party/ | cpp-httplib and googletest |
The order is not random: ber does not know SNMP, snmp does not know OTEL and otel does not know where the values came from. Dependencies point one way, so each layer can be tested on its own.
| Structure | Role |
|---|---|
| ber::Bytes | Alias for a byte vector — the raw content of a packet |
| ber::TLV | One element read as [tag][length][value], including the range of the value in the buffer |
| ber::ber_error | Exception for corrupted or unexpected encoding |
| snmp::VarBindValue | Typed value — Integer, OctetString, OID, Counter32, Gauge32, TimeTicks, Counter64 |
| snmp::VarBind | A pair of an OID and its value |
| snmp::PDU | The response body: request-id, error-status, error-index and a list of VarBinds |
| Options | Configuration assembled from the command-line arguments |
| ParsedUrl | The parsed endpoint — scheme, host, port and path |
It is worth noting that you will find almost no classes here - just plain structures and free functions in namespaces. That is intentional: the program has no multiple implementations of the same interface to choose between at run time. It is a straight pipe from one end to the other, and for that a class hierarchy is dead weight. In IPK, where four protocols really do take turns behind a common interface, it came out exactly the other way round.
The tests (GoogleTest, the tests/ folder) cover BER encoding and decoding, building and parsing SNMP PDUs and parsing the export endpoint URL.