#!/bin/bash # server-health-check.sh — Argento health monitoring # Checks: SMART disk health, ZFS pool status, disk space # Outputs plain text to stdout by default, or sends an HTML email with --email. # Use --error-only to suppress output when everything is healthy. # # Usage: # ./server-health-check.sh # full report to stdout # ./server-health-check.sh --error-only # only print errors (silent if healthy) # ./server-health-check.sh --email # full report to email # ./server-health-check.sh --error-only --email # email errors (no email if healthy) # # Install: # chmod +x /opt/server-health-check.sh # crontab -e: # 0 6 * * * /opt/server-health-check.sh --error-only --email # daily alert # 0 8 * * 1 /opt/server-health-check.sh --email # weekly report # # Dependencies: smartmontools, zfs, msmtp (as sendmail) set -uo pipefail MAILTO="timothykim@fastmail.fm" HOSTNAME=$(hostname) SPACE_THRESHOLD=85 # percent used — alert above this ZFS_CAP_THRESHOLD=80 # ZFS write performance degrades on nearly-full pools QUOTA_THRESHOLD=85 # percent of dataset quota — alert above this ERROR_ONLY=false USE_EMAIL=false for arg in "$@"; do case "$arg" in --error-only) ERROR_ONLY=true ;; --email) USE_EMAIL=true ;; *) echo "Unknown option: $arg" >&2; exit 1 ;; esac done PROBLEMS="" STATUS="" # HTML table rows for the email body, built alongside the plain-text STATUS. # Styles are inlined on every element because most mail clients strip #