Find every network printer, poll it over SNMP, and generate a fleet report — models, page counts, and toner levels with low-supply flagging.
Stop discovering dead toner cartridges when a user calls angry. Run this monthly and reorder before it matters.
Zero third-party dependencies — includes a minimal stdlib-only SNMPv2c
client (snmp.py), so it runs anywhere Python runs.
The morning digest on demo data. Live demos: https://cnoteninja.github.io/Portfolio/
# Discover printers on the subnet, poll them, build the report
python printer_audit.py --subnet 192.168.1.0/24
# Or skip discovery and poll known hosts
python printer_audit.py --hosts 192.168.1.50 192.168.1.51 --community private
# Predict days-until-empty from accumulated history, with part numbers
python predict_toner.py
# One HTML digest for the morning coffee (audit + predictions + growers)
python morning_digest.py --hosts 192.168.1.50 192.168.1.51
# See it work in ~30 seconds with no printers and no network
python morning_digest.py --demo
# Readiness check: Python, config, demo data, printer reachability
python check_setup.pyOpen printers.html (or digest.html for the morning summary).
One file, one glance. Runs a fresh audit, pulls the toner predictions, and
writes digest.html with four sections:
- Printers needing attention — everything not OK, offline printers first, with per-cartridge status badges
- Offline printers — hosts that didn't answer SNMP
- Toner reorder list — cartridges at Critical / Order soon, with part
numbers from
cartridges.json - Top page-count growers — biggest page-count increases over the last
30 days (from
data/page_history.csv, built up automatically by each audit)
python morning_digest.py --subnet 192.168.1.0/24
python morning_digest.py --hosts 192.168.1.50 192.168.1.51 --community private
python morning_digest.py --demo --out sample-digest.htmlPass --mailto and the digest is sent as an HTML email via smtplib:
python morning_digest.py --hosts 192.168.1.50 --mailto you@example.com
python morning_digest.py --demo --mailto you@example.com # tests your SMTP setup, no printers neededEmail settings come from the smtp section of config.json (see
config.example.json; copy it to config.json). Credentials are never
hardcoded. Username and password may use ${ENV_VAR} expansion, and any
missing value falls back to environment variables:
| Setting | config.json | env fallback |
|---|---|---|
| SMTP host | smtp.host |
SMTP_HOST |
| SMTP port | smtp.port |
SMTP_PORT (default 587) |
| username | smtp.username |
SMTP_USERNAME |
| password | smtp.password |
SMTP_PASSWORD |
| From address | smtp.from |
SMTP_FROM |
| default recipients | smtp.to (list) |
— |
{
"smtp": {
"host": "smtp.gmail.com",
"port": 587,
"use_tls": true,
"username": "${SMTP_USERNAME}",
"password": "${SMTP_PASSWORD}",
"from": "${SMTP_FROM}",
"to": ["you@example.com"]
}
}With no --mailto addresses, the digest goes to smtp.to. config.json
is git-ignored, so credentials never end up in the repo.
Every printer and cartridge maps to one plain-English label — OK,
Order soon, or Critical. The mapping lives in one module
(status.py) so the audit report, the prediction script, and the digest
all use the same thresholds:
| Label | Meaning | Thresholds |
|---|---|---|
| Critical | reorder / fix now | level ≤ 10% · empty within 3 days · printer offline |
| Order soon | stock the replacement | level ≤ 25% · empty within 14 days |
| OK | nothing to do | everything else |
Labels are color-coded in terminal output (green / yellow / red) and appear as badges in every HTML report. A cartridge is "unknown"/"ok"/missing only when the printer gave no usable reading — that maps to OK, never an alarm.
No printers? No network? See the full output in ~30 seconds:
python morning_digest.py --demo--demo reads the bundled sample data (demo/sample_printers.json +
demo/sample_toner_history.csv — kept in demo/, separate from the
git-ignored data/ dir that holds your real fleet's history) and produces
a complete sample digest.html: a critical toner, an order-soon cartridge
flagged by its 12-day depletion projection, and an offline printer.
Plain-English PASS / FAIL / SKIP lines, never a traceback:
python check_setup.pyPASS Python 3.12.3 (>= 3.8)
SKIP no config.json — email disabled (copy config.example.json to config.json to enable it)
PASS demo bundle OK — 4 sample printers, 28 history rows (try: python morning_digest.py --demo)
SKIP no hosts in config.json — run python printer_audit.py --subnet 192.168.1.0/24 to discover
It checks the Python version, validates config.json if one exists (valid
JSON, smtp.host present when an smtp section is configured), verifies
the demo bundle parses, and tries a short-timeout TCP connection to port
9100 on each host listed under "hosts" in config.json — unreachable
printers are reported as FAIL lines, not crashes. Exits 0 when nothing
failed, 1 otherwise.
Every audit run appends one row per cartridge per printer to
data/toner_history.csv (timestamp, host, model, color, level %). That file
is local-only — data/ is git-ignored so your fleet's supply data never
leaves the machine. Run the audit on a schedule (weekly is plenty) and the
history gets more accurate.
predict_toner.py reads the history, fits a simple linear depletion rate
(level % vs time) per cartridge, and prints a reorder list:
python predict_toner.py # flag anything emptying within 14 days
python predict_toner.py --threshold 30 # ...within 30 days
python predict_toner.py --csv data/toner_history.csv --catalog cartridges.jsonExample output:
loaded 3 model(s) from cartridges.json
toner reorder list — 4 cartridge(s) tracked
Reorder now (<= 10% remaining):
192.168.1.52 Brother HL-L2390DW black 8% part: TN-760
192.168.1.53 Some Mystery Printer 9000 black 9% part: part number unknown
Projected empty within 14 days:
192.168.1.50 HP LaserJet M404dn black 20% ~10.0 days left part: CF258A
Notes:
- A cartridge needs at least 2 history points before a prediction is made.
- Flat or rising levels (fresh cartridge installed) are reported as not depleting — no false alarms.
- Part numbers come from
cartridges.json; models not listed showpart number unknowninstead of guessing.
Maps printer model → cartridge color → part number, so the reorder list tells you exactly what to buy:
{
"HP LaserJet M404dn": {
"black": "CF258A"
},
"HP Color LaserJet Pro MFP M479fdw": {
"black": "CF410A",
"cyan": "CF411A",
"magenta": "CF413A",
"yellow": "CF412A"
}
}- Model names must match the model strings printers report via SNMP
(check the model column in
printers.csvor the HTML report —predict_toner.pydoes exact matching). - Colors are lowercase:
black,cyan,magenta,yellow. Add your own models and colors freely — unknown models/colors fall back topart number unknown. - The file is committed to the repo as an editable template (the
.gitignorecarves out an exception for it), so edit it in place.
- Discovery — scans the subnet for port 9100 (JetDirect), which means "printer" with very few false positives
- SNMP poll — pulls model, serial, page count (
prtMarkerLifeCount), and every supply's description/level/capacity from the Printer MIB - History — appends per-cartridge levels to
data/toner_history.csvand page counts todata/page_history.csv(both local-only, git-ignored) - Report — HTML fleet cards with toner bars and status badges; supplies ≤10% counted up top
- Prediction —
predict_toner.pyfits a depletion rate per cartridge from history and prints a reorder list with part numbers - Digest —
morning_digest.pyrolls the audit, predictions, and page-count growers into onedigest.html, optionally emailed
| File | Purpose |
|---|---|
printer_audit.py |
Discovery + polling + HTML report + history logging |
predict_toner.py |
Days-until-empty prediction + reorder list |
morning_digest.py |
Morning coffee digest: audit + predictions + growers → digest.html, optional --mailto |
check_setup.py |
Readiness check: Python, config, demo data, printer reachability |
status.py |
One place for OK / Order soon / Critical labels + thresholds |
cartridges.json |
Model → {color: part number} catalog (edit me) |
config.example.json |
Template for config.json (SMTP + hosts; real file is git-ignored) |
snmp.py |
Minimal SNMPv2c GET client (stdlib only) |
demo/ |
Bundled sample data for --demo (tracked; separate from git-ignored data/) |
data/toner_history.csv |
Per-run cartridge levels (local-only, git-ignored) |
data/page_history.csv |
Per-run page counts (local-only, git-ignored) |
printers.csv / printers.html / digest.html |
Generated output (git-ignored) |
- Python 3.8+, no pip packages
- Printers must allow SNMP (community string, default
public) - Windows / Linux / macOS
MIT — use it on client jobs.
