132 lines
2.9 KiB
Bash
Executable file
132 lines
2.9 KiB
Bash
Executable file
#!/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
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<title>${TITLE:?}</title>
|
|
<link rel="stylesheet" href="assets/main.css">
|
|
<link rel="stylesheet" href="assets/bootstrap-reboot.min.css">
|
|
<link rel="stylesheet" href="assets/bootstrap-grid.min.css">
|
|
</head>
|
|
<body>
|
|
<div id="header">
|
|
<img src="assets/cloud.svg" id="logo" />
|
|
<h1>${TITLE:?}</h1>
|
|
<p>This page reports the status of the <a
|
|
href="https://recycled.cloud">Recycled Cloud</a> infrastructure,
|
|
regenerated every minute.
|
|
</p>
|
|
<p>
|
|
States:
|
|
<span class="up">up</span>
|
|
<span class="down">down</span>
|
|
<span class="unknown">unknown</span>
|
|
</p>
|
|
<p>
|
|
Last refresh on <b>$(date)</b>.
|
|
</p>
|
|
</div>
|
|
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
|
|
<div class="location">
|
|
<hr />
|
|
<h2>$location</h2>
|
|
|
|
<div class="row">
|
|
<div class="col-4">
|
|
<h3>Upstreams</h3>
|
|
<ul>
|
|
<li>1 <span class="$upstream1">$upstream1</span></li>
|
|
<li>2 <span class="$upstream2">$upstream2</span></li>
|
|
</ul>
|
|
</div>
|
|
<div class="col-4">
|
|
<h3>Routers</h3>
|
|
<ul>
|
|
<li>edge1 <span class="$edge1">$edge1</span></li>
|
|
<li>edge2 <span class="$edge2">$edge2</span></li>
|
|
</ul>
|
|
</div>
|
|
<div class="col-4">
|
|
<h3>Canary VM</h3>
|
|
<ul>
|
|
<li>IPv6 <span class="$canary_v6">$canary_v6</span></li>
|
|
<li>IPv4 <span class="$canary_v4">$canary_v4</span></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
EOF
|
|
done
|
|
|
|
cat << EOF
|
|
<div id="footer">
|
|
Recycled Cloud Status Page - MIT Licensed - <a href="https://code.recycled.cloud/RecycledCloud/statuspage">Sources</a>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
EOF
|