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.md Ch. 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:

  1. Why does an SNMP WALK return .2 before .10 (and what breaks if you sort OIDs as strings)?
  2. How does an IPMI sensor reading become "OK / Warning / Critical"?

1. The real commands this models

This labReal-world equivalent
snmp_walk(agent, prefix)snmpwalk -v2c -c public <pdu> 1.3.6.1.4.1.9999.2.1
snmp_getnextsnmpgetnext
decode_trap(...)snmptrapd receiving a trap on UDP 162
ipmi_sensor_readingsipmitool -I lanplus -H <bmc> -U u -P p sdr list
decode_selipmitool ... 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)

  1. Point SNMP at snmpsim. pip install snmpsim, run snmpsimd with a recorded community, and replace the PDU_AGENT dict with real urllib/pysnmp GETNEXT calls. Your WALK logic stays the same.
  2. Parse real ipmitool output. Capture ipmitool sdr list / sel list text and write a parser that produces IpmiSensor/SEL records — real fleets often shell out to ipmitool (safely, via an arg list — Phase 02 Ch. 8) rather than speak the binary protocol directly.
  3. 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.
  4. SNMPv3. Add the USM concepts (auth + priv) and explain why v2c community strings are management-network-only.
  5. 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

  1. String-sorting OIDs.10 sorts before .2 as strings; WALK breaks. Sort by integer components.
  2. Reading without thresholds — "78°C" alone can't be classified; carry the SDR thresholds with the value.
  3. Trap-only or poll-only — traps can be lost (UDP, fire-and-forget); polling is slow. Production does both.
  4. v2c on an untrusted net — the community string is cleartext; it's mgmt-VLAN-only, and v3 where security matters.
  5. Per-protocol data shapes leaking upward — normalize to one Reading at 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.