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

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 →

  1. A single alert command taking -s severity -t title -k key message.
  2. Route by severity:
    case $severity in
      critical) send_slack; send_pagerduty ;;
      warning)  send_slack ;;
      info)     log only ;;
    esac
    
  3. PagerDuty Events API v2 with a dedup_key equal to the alert key, so repeats update one incident and "event_action": "resolve" closes it.
  4. Build every payload with jq -n --arg, use curl --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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: health checks, monitoring and alerts