Lab 02 — SNMP Poller/Trap Receiver + IPMI Sensors
Phase: 03 — Management Protocols | Difficulty: ⭐⭐⭐☆☆ | Time: 4–6 hours Language: Python 3 (stdlib only) | Hardware: none (simulated agents)
Concept primer:
../WARMUP.mdCh. 5 (IPMI) & Ch. 6 (SNMP),../HITCHHIKERS-GUIDE.md§3–§4.
Run
python3 solution.py # SNMP WALK + trap decode + IPMI SDR/SEL + unified view
0. The mission
Learn the two legacy protocols by implementing their semantics: a lexicographic SNMP
WALK, an IPMI SDR sensor with real thresholds and a health verdict, a SEL decode, and —
the senior part — normalizing all of it into one Reading model so the rest of your
system doesn't care whether a temperature came from Redfish, IPMI, or SNMP.
Two questions you must answer at the end:
- Why does an SNMP WALK return
.2before.10(and what breaks if you sort OIDs as strings)? - How does an IPMI sensor reading become "OK / Warning / Critical"?
1. The real commands this models
| This lab | Real-world equivalent |
|---|---|
snmp_walk(agent, prefix) | snmpwalk -v2c -c public <pdu> 1.3.6.1.4.1.9999.2.1 |
snmp_getnext | snmpgetnext |
decode_trap(...) | snmptrapd receiving a trap on UDP 162 |
ipmi_sensor_readings | ipmitool -I lanplus -H <bmc> -U u -P p sdr list |
decode_sel | ipmitool ... sel list |
2. The two ideas that matter
Lexicographic OID ordering — OIDs sort numerically per component, so ...2.1.2 comes
before ...2.1.10. Sorting OIDs as plain strings is a classic bug (you'd get .1, .10, .2).
_oid_key splits on . and compares integer lists; WALK then collects a subtree in the
order a real agent returns it. This is why snmpwalk output is predictably ordered.
IPMI threshold health — a sensor reading is meaningless without its thresholds. Each
IpmiSensor carries lnr/lc/lnc (lower non-recoverable/critical/non-critical) and
unc/uc/unr (upper). health() walks them from most to least severe and returns
OK/Warning/Critical — exactly how the hardware intends a reading to be interpreted. The
"Accel0 Temp 92°C → Warning" line is the upper-non-critical band in action.
3. What the run shows
A WALK in correct numeric order, a decoded PSU-failure trap, IPMI sensors classified by threshold (note the hot accelerator flagged Warning), the SEL hardware-event log decoded to human strings, and finally 9 readings from two protocols collapsed into one model with a health histogram — the seed of the Phase 07 telemetry pipeline.
4. Extension exercises (do them — this is the lab)
- Point SNMP at
snmpsim.pip install snmpsim, runsnmpsimdwith a recorded community, and replace thePDU_AGENTdict with realurllib/pysnmpGETNEXT calls. Your WALK logic stays the same. - Parse real
ipmitooloutput. Captureipmitool sdr list/sel listtext and write a parser that producesIpmiSensor/SEL records — real fleets often shell out toipmitool(safely, via an arg list — Phase 02 Ch. 8) rather than speak the binary protocol directly. - A real trap receiver. Bind a UDP socket on 162 (or a high port) and decode incoming
SNMP trap PDUs; integrate with
decode_trap. Discuss trap loss and why you still poll. - SNMPv3. Add the USM concepts (auth + priv) and explain why v2c community strings are management-network-only.
- Emit Prometheus. Render
unified_view()in Prometheus exposition format (pdu_outlet_power_watts{outlet="1"} 410) — the literal bridge to the Phase 07 exporter.
5. Common pitfalls
- String-sorting OIDs —
.10sorts before.2as strings; WALK breaks. Sort by integer components. - Reading without thresholds — "78°C" alone can't be classified; carry the SDR thresholds with the value.
- Trap-only or poll-only — traps can be lost (UDP, fire-and-forget); polling is slow. Production does both.
- v2c on an untrusted net — the community string is cleartext; it's mgmt-VLAN-only, and v3 where security matters.
- Per-protocol data shapes leaking upward — normalize to one
Readingat the driver boundary so callers (alerting, dashboards) stay protocol-agnostic.
6. What this lab proves about you
You understand the protocols a heterogeneous fleet actually speaks, down to the WALK ordering and the threshold model — and you can fuse them into one coherent telemetry view. In an interview, "how do you monitor a PDU and an old IPMI BMC alongside Redfish nodes?" becomes a clear answer: per-protocol drivers, threshold-aware health, traps + polling, and one unified model — which is exactly the pipeline you build in Phase 07 and the capstone.