Terminal Widget showing API health status

Script

API Health Check

by Brett Terpstra

Poll a JSON health endpoint and show a green check or red error icon in Terminal Widget based on the response status.

Script (api-health-check.sh)

#!/usr/bin/env bash
set -euo pipefail

HEALTH_URL="https://billing.markedapp.com/api/health"

status="$(
  curl -fsS "$HEALTH_URL" | jq -r '.status // empty'
)"

if [[ "$status" == "ok" ]]; then
  terminal-widget \
    --target billingstatus \
    --icon checkmark.seal.fill \
    --background "#639992" \
    --foreground "#ffffff" \
    --text "Billing Server Healthy"
else
  terminal-widget \
    --target billingstatus \
    --icon xmark.seal.fill \
    --background "#ad343e" \
    --foreground "#ffffff" \
    --text "Billing Server Error"
fi

Download script

← All recipes