Write an environmental alert that ignores spikes and catches trends

short · 40 min · Objective 3.2

Task

Write a monitoring check for server room conditions that alerts when inlet temperature stays outside the recommended range for several readings in a row, or humidity leaves its band, and stays quiet for a single spike. Test it against three data sets whose correct answers you decide in advance: normal, a brief spike, and a cooling failure.

Steps

  1. Create lab/env/normal.csv, lab/env/spike.csv and lab/env/failure.csv, each with header minute,inlet_c,humidity_pct and 30 rows. Normal stays in range; spike has one reading at 29; failure climbs steadily from 24 to 35 from minute 10.
  2. Write lab/env/check.sh that reads a file and prints ALERT temperature if the inlet is above 27 for five consecutive readings, ALERT humidity if humidity is outside 40 to 60 for five consecutive readings, and OK otherwise.
  3. Record in lab/env/expected.txt the result you expect for each file, as normal: OK, and so on, before running anything.
  4. Run the check on each file and save the results to lab/env/results.txt in the same format.
  5. Record in lab/env/response.txt what staff should do in the first ten minutes after the temperature alert, in order.

Verify

These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.

wc -l < lab/env/failure.csv
diff lab/env/expected.txt lab/env/results.txt && echo results match expectations
grep -c 'spike: OK' lab/env/results.txt
grep -c 'failure: ALERT temperature' lab/env/results.txt
grep -Eic 'cooling|shut|load|door|unit' lab/env/response.txt

The results match what you predicted: the spike does not alert and the cooling failure does. An alert that fired on the spike would train staff to ignore it; one that missed the climb would have let the room overheat. Testing against all three is what shows the rule has both properties.

Notes

Real environmental monitoring also watches the rate of change: a room gaining a degree a minute is an emergency long before it crosses the threshold, which is a useful second rule to add.

This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.