commit 3413ffe2a9cb7111e5c9e0fc62dba6c1559d58ae
parent de5fb8b954f589825f5843b2a9db1e3022dc6a9c
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Sat, 29 Nov 2025 00:19:25 +0100
feat: report cpu temp to gatus
Diffstat:
3 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/bootstrap.sh b/bootstrap.sh
@@ -86,3 +86,62 @@ resize_rootfs: noblock
# Disable network configuration
network: {config: disabled}
EOF
+
+# Install script to report CPU temp
+# https://github.com/TwiN/gatus?tab=readme-ov-file#external-endpoints
+cat <<EOF > /usr/local/bin/gatus-report-cpu-temp.sh
+#!/usr/bin/env bash
+
+# Check CPU temperature
+# https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal
+
+TOKEN=$GATUS_EXTERNAL_ENDPOINT_TOKEN
+ENDPOINT=infra_cputemp-$(hostname)
+
+EOF
+# don't interpret the variables in the rest of the script
+cat <<'EOF' >> /usr/local/bin/gatus-report-cpu-temp.sh
+if [[ $(cat /sys/class/thermal/thermal_zone0/temp) -gt 60000 ]]
+then
+ echo "❌cpu temperature is above 60°C"
+ curl -s -H "Authorization: Bearer $TOKEN" \
+ -XPOST "https://up.in0rdr.ch/api/v1/endpoints/$ENDPOINT/external?success=false"
+else
+ echo "✔ all fine, cpu temperature is below 60°C"
+ curl -s -H "Authorization: Bearer $TOKEN" \
+ -XPOST "https://up.in0rdr.ch/api/v1/endpoints/$ENDPOINT/external?success=true"
+fi
+EOF
+
+chmod +x /usr/local/bin/gatus-report-cpu-temp.sh
+
+cat <<EOF > /etc/systemd/system/gatus-report-cpu-temp.timer
+[Unit]
+Description=Report CPU temp to Gatus
+
+[Timer]
+Unit=gatus-report-cpu-temp.service
+# run 5min after unit started
+OnActiveSec=1min
+# afterwards, run timer every 45min
+OnUnitActiveSec=5min
+
+[Install]
+WantedBy=timers.target
+EOF
+
+cat <<EOF > /etc/systemd/system/gatus-report-cpu-temp.service
+[Unit]
+Description=Report CPU temp to Gatus
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c '/usr/local/bin/gatus-report-cpu-temp.sh'
+
+[Install]
+WantedBy=multi-user.target
+EOF
+
+systemctl daemon-reload
+systemctl enable gatus-report-cpu-temp.timer
+systemctl start gatus-report-cpu-temp.timer
diff --git a/debian_postinstall.sh b/debian_postinstall.sh
@@ -217,3 +217,4 @@ EOF
systemctl daemon-reload
systemctl enable lxc-snapshot.timer
+systemctl start lxc-snapshot.timer
diff --git a/hashi-pi.pkr.hcl b/hashi-pi.pkr.hcl
@@ -134,6 +134,10 @@ variable "architecture" {
default = "arm64"
}
+variable "gatus_external_endpoint_token" {
+ type = string
+}
+
packer {
required_plugins {
qemu = {
@@ -206,6 +210,7 @@ build {
script = "bootstrap.sh"
environment_vars = [
"ARCHITECTURE=${var.architecture}",
+ "GATUS_EXTERNAL_ENDPOINT_TOKEN=${var.gatus_external_endpoint_token}",
"HOSTNAME=${var.hostname}",
"USERNAME=${var.username}",
"AUTHORIZED_KEYS=${var.authorized_keys}",