From d47cd364408b4cb04e01def304ff27caa3844234 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 3 Apr 2026 15:39:35 -0500 Subject: [PATCH] feat: right-size VM 115 config and add --hosts flag to audit script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce VM 115 (docker-sba) from 16 vCPUs (2×8) to 8 vCPUs (1×8) to match actual workload (0.06 load/core). Add --hosts flag to homelab-audit.sh for targeted post-change audits. Closes #18 Co-Authored-By: Claude Opus 4.6 (1M context) --- monitoring/scripts/homelab-audit.sh | 36 +++++++++++++++++---- monitoring/scripts/test-audit-collectors.sh | 28 ++++++++++++++++ server-configs/proxmox/qemu/115.conf | 2 +- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/monitoring/scripts/homelab-audit.sh b/monitoring/scripts/homelab-audit.sh index da2cf7d..cf0aa26 100755 --- a/monitoring/scripts/homelab-audit.sh +++ b/monitoring/scripts/homelab-audit.sh @@ -5,7 +5,7 @@ # to collect system metrics, then generates a summary report. # # Usage: -# homelab-audit.sh [--output-dir DIR] +# homelab-audit.sh [--output-dir DIR] [--hosts label:ip,label:ip,...] # # Environment overrides: # STUCK_PROC_CPU_WARN CPU% at which a D-state process is flagged (default: 10) @@ -29,6 +29,7 @@ LOAD_WARN=2.0 MEM_WARN=85 ZOMBIE_WARN=1 SWAP_WARN=512 +MANUAL_HOSTS="" while [[ $# -gt 0 ]]; do case "$1" in @@ -40,6 +41,14 @@ while [[ $# -gt 0 ]]; do REPORT_DIR="$2" shift 2 ;; + --hosts) + if [[ $# -lt 2 ]]; then + echo "Error: --hosts requires an argument (label:ip,label:ip,...)" >&2 + exit 1 + fi + MANUAL_HOSTS="$2" + shift 2 + ;; *) echo "Unknown option: $1" >&2 exit 1 @@ -398,12 +407,25 @@ main() { check_backup_recency local host_count=0 - while read -r label addr; do - echo " Auditing $label ($addr)..." - parse_and_report "$label" "$addr" - check_cert_expiry "$label" "$addr" - ((host_count++)) || true - done < <(collect_inventory) + if [[ -n "$MANUAL_HOSTS" ]]; then + # --hosts flag: parse comma-separated label:ip pairs + IFS=',' read -ra host_entries <<<"$MANUAL_HOSTS" + for entry in "${host_entries[@]}"; do + local label="${entry%%:*}" + local addr="${entry#*:}" + echo " Auditing $label ($addr)..." + parse_and_report "$label" "$addr" + check_cert_expiry "$label" "$addr" + ((host_count++)) || true + done + else + while read -r label addr; do + echo " Auditing $label ($addr)..." + parse_and_report "$label" "$addr" + check_cert_expiry "$label" "$addr" + ((host_count++)) || true + done < <(collect_inventory) + fi generate_summary "$host_count" } diff --git a/monitoring/scripts/test-audit-collectors.sh b/monitoring/scripts/test-audit-collectors.sh index 149aa98..ef37103 100644 --- a/monitoring/scripts/test-audit-collectors.sh +++ b/monitoring/scripts/test-audit-collectors.sh @@ -93,6 +93,34 @@ else fail "disk_usage" "expected 'N /path', got: '$result'" fi +# --- --hosts flag parsing --- +echo "" +echo "=== --hosts argument parsing tests ===" + +# Single host +input="vm-115:10.10.0.88" +IFS=',' read -ra entries <<<"$input" +label="${entries[0]%%:*}" +addr="${entries[0]#*:}" +if [[ "$label" == "vm-115" && "$addr" == "10.10.0.88" ]]; then + pass "--hosts single entry parsed: $label $addr" +else + fail "--hosts single" "expected 'vm-115 10.10.0.88', got: '$label $addr'" +fi + +# Multiple hosts +input="vm-115:10.10.0.88,lxc-225:10.10.0.225" +IFS=',' read -ra entries <<<"$input" +label1="${entries[0]%%:*}" +addr1="${entries[0]#*:}" +label2="${entries[1]%%:*}" +addr2="${entries[1]#*:}" +if [[ "$label1" == "vm-115" && "$addr1" == "10.10.0.88" && "$label2" == "lxc-225" && "$addr2" == "10.10.0.225" ]]; then + pass "--hosts multi entry parsed: $label1 $addr1, $label2 $addr2" +else + fail "--hosts multi" "unexpected parse result" +fi + echo "" echo "=== Results: $PASS passed, $FAIL failed ===" ((FAIL == 0)) diff --git a/server-configs/proxmox/qemu/115.conf b/server-configs/proxmox/qemu/115.conf index 6474b44..4cf45c7 100644 --- a/server-configs/proxmox/qemu/115.conf +++ b/server-configs/proxmox/qemu/115.conf @@ -12,5 +12,5 @@ ostype: l26 scsi0: local-lvm:vm-115-disk-0,size=256G scsihw: virtio-scsi-pci smbios1: uuid=19be98ee-f60d-473d-acd2-9164717fcd11 -sockets: 2 +sockets: 1 vmgenid: 682dfeab-8c63-4f0b-8ed2-8828c2f808ef