← All Automations
Flow details

Api Health Check

Comprehensive API health monitoring with endpoint validation

v1.0.0 by cluka schedule */15 * * * * Lobster workflow available
apimonitoringdevops

What this flow does

  1. **Checks endpoints** - Sends HTTP requests to configured API endpoints every 15 minutes
  2. **Tracks state** - Remembers previous health status to detect transitions
  3. **Alerts on changes** - Notifies when endpoints go down or recover
  4. **Measures latency** - Captures response times for each endpoint

How it runs

1. load-state
storage
2. check-endpoints
http
3. ep.name || ep.url
evaluate
4. save-state
storage
5. alert
notify

Inputs & configuration

endpoints
JSON array of endpoint configs [{url, method, expected_status, name}] · required
timeout_ms
Request timeout in milliseconds · default: 5000
state_file
File to track health history · default: api-health-state.json

README configuration

config:
  endpoints: '[{"url": "https://api.example.com/health", "name": "My API"}]'
  timeout_ms: 5000
  state_file: "api-health-state.json"

Schedule & output

Cron: */15 * * * *

Every 15 minutes: */15 * * * *

Lobster workflow

Lobster workflow: api health check Monitors API endpoint health with status codes and latency tracking Usage:

1. load-state
2. check-endpoints
3. analyze
4. save-state
5. report
View workflow YAML
# Lobster workflow: api-health-check
# Monitors API endpoint health with status codes and latency tracking
#
# Usage:
#   lobster run --file workflow.yaml --args-json '{"endpoints":"https://api.example.com,https://other.api/health"}'
#
# Requires: jq, curl

name: api-health-check
description: Comprehensive API health monitoring with endpoint validation

args:
  endpoints:
    description: "Comma-separated endpoint URLs to check"
  timeout:
    description: "Request timeout in seconds"
    default: "5"
  state_file:
    default: "/tmp/clawflows-api-health-state.json"

steps:
  - id: load-state
    command: cat "${state_file}" 2>/dev/null || echo '{}'

  - id: check-endpoints
    command: |
      tmpf=$(mktemp)
      echo '[]' > "$tmpf"
      for url in $(echo "${endpoints}" | tr ',' ' '); do
        url=$(echo "$url" | xargs)
        [ -z "$url" ] && continue
        result=$(curl -o /dev/null -s -w '%{http_code} %{time_total}' \
          --max-time ${timeout} "$url" 2>/dev/null) || result="000 0.000"
        code=$(echo "$result" | awk '{print $1}')
        latency=$(echo "$result" | awk '{print $2}')
        healthy="false"
        if [ "$code" -ge 200 ] && [ "$code" -lt 300 ] 2>/dev/null; then
          healthy="true"
        fi
        jq -nc --arg url "$url" --arg code "$code" --arg latency "$latency" --argjson healthy "$healthy" \
          '{url:$url, status:($code|tonumber), latency:$latency, healthy:$healthy}' > /tmp/lb_ep.json
        jq -sc '.[0]+[.[1]]' "$tmpf" /tmp/lb_ep.json > /tmp/lb_ep_merged.json
        mv /tmp/lb_ep_merged.json "$tmpf"
      done
      cat "$tmpf"
      rm -f "$tmpf" /tmp/lb_ep.json

  - id: analyze
    stdin: $check-endpoints.stdout
    command: |
      cat > /tmp/lb_health_results.json
      prev=$(cat "${state_file}" 2>/dev/null || echo '{}')
      echo "$prev" > /tmp/lb_health_prev.json
      jq -c --slurpfile prev /tmp/lb_health_prev.json '
        ($prev[0] // {}) as $old |
        [.[] | . + {
          was_healthy: (if $old[.url] then $old[.url].healthy else true end),
          alert: (
            ($old[.url] // null) as $prev_entry |
            ($prev_entry | if . == null then true else .healthy end) as $prev_healthy |
            if .healthy and ($prev_healthy | not) then "recovered"
            elif (.healthy | not) and $prev_healthy then "down"
            else null end
          )
        }] |
        {
          results: .,
          alerts: [.[] | select(.alert != null)],
          healthy_count: ([.[] | select(.healthy)] | length),
          total_count: length,
          all_healthy: (all(.healthy))
        }
      ' /tmp/lb_health_results.json
      rm -f /tmp/lb_health_results.json /tmp/lb_health_prev.json

  - id: save-state
    stdin: $analyze.stdout
    command: |
      cat > /tmp/lb_health_analysis.json
      jq '{results: [.results[] | {(.url): {healthy: .healthy, status: .status, last_check: now}}]} | .results | add // {}' \
        /tmp/lb_health_analysis.json > "${state_file}"
      cat /tmp/lb_health_analysis.json
      rm -f /tmp/lb_health_analysis.json

  - id: report
    stdin: $save-state.stdout
    command: |
      jq -r '
        "🏥 API Health Check — \(.healthy_count)/\(.total_count) healthy\n" +
        (.results | map(
          (if .healthy then "🟢" else "🔴" end) +
          " \(.url) — HTTP \(.status) (\(.latency)s)"
        ) | join("\n")) +
        if (.alerts | length) > 0 then
          "\n\n⚠️ Alerts:\n" +
          (.alerts | map(
            if .alert == "down" then "🔴 DOWN: \(.url) — HTTP \(.status)"
            else "🟢 RECOVERED: \(.url)" end
          ) | join("\n"))
        else "" end
      '

README details

Comprehensive API health monitoring with endpoint validation, latency tracking, and state-change alerts.

What It Does

  1. **Checks endpoints** - Sends HTTP requests to configured API endpoints every 15 minutes
  2. **Tracks state** - Remembers previous health status to detect transitions
  3. **Alerts on changes** - Notifies when endpoints go down or recover
  4. **Measures latency** - Captures response times for each endpoint

Requirements

CapabilityExample Skills
`exec`http requests

Configuration

config:
  endpoints: '[{"url": "https://api.example.com/health", "name": "My API"}]'
  timeout_ms: 5000
  state_file: "api-health-state.json"

Schedule

Every 15 minutes: */15 * * * *

Author

Created by Cluka 🦞