statuspage/generate.sh

133 lines
2.9 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"
}
2024-12-19 15:50:01 +01:00
get_router_state () {
2021-04-07 09:49:38 +02:00
location=$1
2024-12-19 15:50:01 +01:00
router=$2
2021-04-07 09:49:38 +02:00
2024-12-19 15:50:01 +01:00
instance="$router.$location.recycled.cloud"
2024-04-05 15:25:28 +02:00
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
2024-12-19 15:50:01 +01:00
upstream1=$(get_router_state "$location" 'upstream1')
upstream2=$(get_router_state "$location" 'upstream2')
edge1=$(get_router_state "$location" 'edge1')
edge2=$(get_router_state "$location" 'edge2')
2021-04-07 09:49:38 +02:00
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">
2024-12-19 15:50:01 +01:00
<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">
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>
2024-12-19 15:50:01 +01:00
<div class="col-4">
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