Interview Prep/Shell Scripting/Scenarios: health checks, monitoring and alerts

Your disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?

AdvancedScenarioScenarios: health checks, monitoring and alerts
Answer

Situation read → The value oscillates around a single threshold and every check sends a message: no deduplication, no hysteresis.

What I'd do →

  1. Deduplicate: store a state file per alert key (alerts/disk-var) with the time it fired; suppress repeats within a cooldown (for example, 1 hour).
  2. Hysteresis: fire at 85%, clear only below 80%.
    firing=$([[ -e $state ]] && echo 1 || echo 0)
    if (( pct >= 85 )) || (( firing && pct >= 80 )); then alert; elif (( firing )); then resolve; fi
    
  3. Duration: require N consecutive bad checks before alerting (keep a counter in the state file).
  4. Send resolved messages so people know when to stop looking.
  5. Separate warning (ticket or channel) from critical (page).

Why → Alert fatigue makes people mute channels, and then the real alert is missed.

Interview tip → Use the word "hysteresis". It is what Prometheus for: clauses and Alertmanager grouping solve in larger setups.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: health checks, monitoring and alerts