#!/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_router_state () { location=$1 router=$2 instance="$router.$location.recycled.cloud" job="blackbox-external-icmpv6" result=$(query $EXTERNAL_PROMETHEUS_ADDR \ "probe_success{instance=\"$instance\", job=\"$job\"}") get_state "$result" } cat << EOF ${TITLE:?} EOF for location in $LOCATIONS; do upstream1=$(get_router_state "$location" 'upstream1') upstream2=$(get_router_state "$location" 'upstream2') edge1=$(get_router_state "$location" 'edge1') edge2=$(get_router_state "$location" 'edge2') canary_v6=$(get_canary_state "$location" 6) canary_v4=$(get_canary_state "$location" 4) cat <<- EOF

$location

Upstreams

  • 1 $upstream1
  • 2 $upstream2

Routers

  • edge1 $edge1
  • edge2 $edge2

Canary VM

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