statuspage/generate.sh

123 lines
2.6 KiB
Bash
Raw Normal View History

2021-04-07 09:49:38 +02:00
#!/bin/sh
TITLE="Recycled Cloud Status"
2024-04-05 12:05:16 +02:00
LOCATIONS="swdn.ch"
2021-04-07 09:49:38 +02:00
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
2024-04-05 15:25:28 +02:00
instance="edge$edge.$location.recycled.cloud"
job="blackbox-external-icmpv6"
2021-04-07 09:49:38 +02:00
result=$(query $EXTERNAL_PROMETHEUS_ADDR \
2024-04-05 15:25:28 +02:00
"probe_success{instance=\"$instance\", job=\"$job\"}")
2021-04-07 09:49:38 +02:00
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
canary_v6=$(get_canary_state "$location" 6)
canary_v4=$(get_canary_state "$location" 4)
2024-04-05 15:25:28 +02:00
edge1=$(get_edge_state "$location" 1)
edge2=$(get_edge_state "$location" 2)
2021-04-07 09:49:38 +02:00
cat <<- EOF
<div class="location">
<hr />
<h2>$location</h2>
<div class="row">
<div class="col-6">
2024-04-05 15:25:28 +02:00
<h3>Routers</h3>
2021-04-07 09:49:38 +02:00
<ul>
2024-04-05 15:25:28 +02:00
<li>edge1 <span class="$edge1">$edge1</span></li>
<li>edge2 <span class="$edge2">$edge2</span></li>
2021-04-07 09:49:38 +02:00
</ul>
</div>
<div class="col-6">
2024-04-05 15:25:28 +02:00
<h3>Canary VM</h3>
2021-04-07 09:49:38 +02:00
<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
2021-04-07 09:57:30 +02:00
<div id="footer">
Recycled Cloud Status Page - MIT Licensed - <a href="https://code.recycled.cloud/RecycledCloud/statuspage">Sources</a>
2021-04-07 09:57:30 +02:00
</div>
2021-04-07 09:49:38 +02:00
</body>
</html>
EOF