#!/bin/sh TITLE="Recycled Cloud Status" LOCATIONS="swdn.ch" EXTERNAL_PROMETHEUS_ADDR=http://localhost:9090 query () { endpoint="$1/api/v1/query" query=$2 curl "$endpoint" --data-urlencode "query=$query" | jq --raw-output .data.result[].value[1] } get_state () { case "$1" in 0) echo "down" ;; 1) echo "up" ;; *) echo "unknown" ;; esac } get_canary_state () { location=$1 inet=$2 instance="canary.$location.recycled.cloud" job="blackbox-external-v$inet" result=$(query $EXTERNAL_PROMETHEUS_ADDR \ "probe_success{instance=\"$instance\", job=\"$job\"}") get_state "$result" } get_edge_state () { location=$1 edge=$2 instance="edge$edge-$(echo "$location" | cut -d. -f1).transfer.recycled.cloud" result=$(query $EXTERNAL_PROMETHEUS_ADDR \ "probe_success{instance=\"$instance\"}") get_state "$result" } cat << EOF ${TITLE:?} EOF for location in $LOCATIONS; do canary_v6=$(get_canary_state "$location" 6) canary_v4=$(get_canary_state "$location" 4) edge1_transfer=$(get_edge_state "$location" 1) edge2_transfer=$(get_edge_state "$location" 2) cat <<- EOF

$location

Routers

  • edge1 $edge1_transfer
  • edge2 $edge2_transfer

Canary VM

  • IPv6 $canary_v6
  • IPv4 $canary_v4
EOF done cat << EOF EOF