Alerts must go to Slack for warnings, and to PagerDuty plus Slack for critical. How do you structure that in shell?
IntermediateScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → Keep routing in one alert script; checks only state severity.
What I'd do →
- A single
alertcommand taking-s severity -t title -k key message. - Route by severity:
case $severity in critical) send_slack; send_pagerduty ;; warning) send_slack ;; info) log only ;; esac - PagerDuty Events API v2 with a
dedup_keyequal to the alert key, so repeats update one incident and"event_action": "resolve"closes it. - Build every payload with
jq -n --arg, usecurl --max-time 10 --retry 3, and log delivery failures without failing the check.
Why → Central routing means changing escalation policy is one edit, not fifty.
Interview tip → Mention using the same key for dedupe in your state file and in PagerDuty's dedup_key.
More on Scenarios: health checks, monitoring and alerts
You are asked for a host health-check script covering disk, memory, systemd services and an HTTP endpoint. How do you design it?IntermediateYour disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?AdvancedA server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?BeginnerAlert when any certificate under `/etc/letsencrypt/live` expires within 21 days.IntermediateA developer wrote a Bash loop that restarts the app whenever its process disappears. What do you suggest instead?IntermediateYou suspect a memory leak in a service. How do you collect evidence with a script before involving developers?Advanced