Level 0 / Project 13 - Alarm Message Generator¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 30 minutes
Focus¶
- template strings and alert text building
Why this project exists¶
Parse pipe-delimited alarm records, sort them by severity, and generate formatted notification messages. You will learn delimiter parsing, priority ordering with a lookup dict, and template-based text generation.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-0/13-alarm-message-generator
python project.py --input data/sample_input.txt
pytest -q
Expected terminal output¶
=== Alarm Notifications ===
[CRITICAL] web-server-01: CPU usage above 95%
[WARNING] db-primary: Replication lag 30 seconds
[INFO] load-balancer: Health check passed
Summary: 1 critical, 1 warning, 1 info
Output written to data/output.json
5 passed
Expected artifacts¶
data/output.json- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--severityfilter flag that shows only alarms at or above a given severity level. - Add timestamps to each alarm notification (use a hardcoded time for reproducibility).
- Re-run script and tests.
Break it (required) — Core¶
- Add a line with an unknown severity like
unknown|server01|disk full-- doesparse_alarm()reject it? - Add a line with missing fields like
critical|-- does it crash or handle gracefully? - Add a line with extra pipe characters -- does the parser split correctly?
Fix it (required) — Core¶
- Ensure
parse_alarm()validates severity against the allowed list (critical, warning, info). - Handle lines with fewer than 3 pipe-delimited fields by raising
ValueError. - Add a test for the unknown-severity edge case.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why does
sort_by_severity()use a priority dict{"critical": 0, "warning": 1, "info": 2}instead of alphabetical sorting? - What does the pipe
|delimiter offer over commas when data might contain commas? - Why does
alarm_summary()count by severity level instead of just total count? - Where would alarm formatting appear in real software (monitoring dashboards, PagerDuty, incident management)?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|