run-demo.sh opens a 2x2 tmux grid: egress-IP table looping in a netshoot pod, kubectl get px watch, and both create scripts running with COUNT (default 4) proxies. show-egress-ips-table.sh is the pane-sized one-line-per-proxy variant used by the driver. Co-Authored-By: Claude <noreply@anthropic.com>
76 lines
2.5 KiB
Bash
Executable File
76 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Demo: condensed-table variant of show-egress-ips.sh, made to fit a small
|
|
# tmux pane. One line per proxy: which proxy the request goes through, its
|
|
# endpoint, location (zone/geo attribute), and the egress IP the IP-echo
|
|
# site saw — or unhealthy/FAILED.
|
|
#
|
|
# Usage:
|
|
# ./show-egress-ips-table.sh <BASE_URL> e.g. ./show-egress-ips-table.sh localhost:8090
|
|
#
|
|
# Optional environment:
|
|
# TOKEN bearer token for the discovery API (see docs/api.md)
|
|
# IP_ECHO_URL site that returns the caller's IP as JSON with an "ip" field
|
|
# (default: https://api.ipify.org?format=json)
|
|
set -euo pipefail
|
|
|
|
if [ $# -ne 1 ]; then
|
|
echo "usage: $(basename "$0") <BASE_URL> (e.g. localhost:8090)" >&2
|
|
exit 1
|
|
fi
|
|
BASE_URL="$1"
|
|
IP_ECHO_URL="${IP_ECHO_URL:-https://api.ipify.org?format=json}"
|
|
|
|
for tool in curl jq; do
|
|
if ! command -v "${tool}" &> /dev/null; then
|
|
echo "ERROR: ${tool} is required but not installed" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
auth_args=()
|
|
if [ -n "${TOKEN:-}" ]; then
|
|
auth_args=(-H "Authorization: Bearer ${TOKEN}")
|
|
fi
|
|
|
|
if ! proxies_json=$(curl -sS --fail "${auth_args[@]}" "${BASE_URL}/v1/proxies") \
|
|
|| ! echo "${proxies_json}" | jq -e . > /dev/null 2>&1; then
|
|
echo "ERROR: could not fetch proxy list from ${BASE_URL}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
total=$(echo "${proxies_json}" | jq -r '.count')
|
|
fmt="%-31s %-21s %-21s %s\n"
|
|
|
|
echo "${total} proxies @ $(date +%H:%M:%S)"
|
|
# shellcheck disable=SC2059
|
|
printf "${fmt}" "PROXY" "ENDPOINT" "LOCATION" "EGRESS-IP"
|
|
|
|
probed=0
|
|
skipped=0
|
|
failed=0
|
|
while IFS= read -r proxy; do
|
|
id=$(echo "${proxy}" | jq -r '.id')
|
|
endpoint=$(echo "${proxy}" | jq -r '"\(.ip):\(.port)"')
|
|
location=$(echo "${proxy}" | jq -r '.attributes.zone // .attributes.geo // "-"')
|
|
healthy=$(echo "${proxy}" | jq -r '.healthy')
|
|
|
|
if [ "${healthy}" != "true" ]; then
|
|
# shellcheck disable=SC2059
|
|
printf "${fmt}" "${id}" "${endpoint}" "${location}" "(unhealthy)"
|
|
skipped=$((skipped + 1))
|
|
continue
|
|
fi
|
|
|
|
if response=$(curl -sS --max-time 10 -x "http://${endpoint}" "${IP_ECHO_URL}" 2> /dev/null); then
|
|
egress=$(echo "${response}" | jq -r '.ip // "?"' 2> /dev/null || echo "?")
|
|
probed=$((probed + 1))
|
|
else
|
|
egress="FAILED"
|
|
failed=$((failed + 1))
|
|
fi
|
|
# shellcheck disable=SC2059
|
|
printf "${fmt}" "${id}" "${endpoint}" "${location}" "${egress}"
|
|
done < <(echo "${proxies_json}" | jq -c '.proxies[]')
|
|
|
|
echo "-- ${probed} probed, ${skipped} unhealthy, ${failed} failed --"
|