Add Proxmox platform detection, preserve expanded card state across auto-refresh
All checks were successful
Build-Publish / build (linux/amd64) (push) Successful in 5s
Build-Publish / build (linux/arm64) (push) Successful in 12s
Build-Publish / create-manifest (push) Successful in 2s
Build-Publish / publish-template (push) Successful in 15s

This commit is contained in:
j
2026-03-08 15:06:54 +13:00
parent 5d7afbcde2
commit ba1da58230
2 changed files with 42 additions and 7 deletions

View File

@@ -2,6 +2,9 @@
# Gather system information from a remote server
# Output format: [section] headers followed by key=value pairs
# Ensure sbin paths are available (not always in PATH for non-root users)
export PATH="$PATH:/usr/sbin:/usr/local/sbin:/sbin"
echo "[system]"
echo "hostname=$(hostname)"
if [ -f /etc/os-release ]; then
@@ -14,6 +17,13 @@ echo "kernel=$(uname -r)"
echo "arch=$(uname -m)"
echo "uptime_seconds=$(cut -d' ' -f1 /proc/uptime 2>/dev/null | cut -d. -f1)"
# Detect hypervisor platform
if [ -f /etc/pve/.version ] || command -v pveversion &>/dev/null || [ -d /etc/pve ]; then
pve_ver=$(pveversion 2>/dev/null | sed 's|pve-manager/||;s| .*||')
echo "platform=proxmox"
echo "platform_version=${pve_ver:-unknown}"
fi
# Motherboard (readable without root on most systems)
echo "board_vendor=$(cat /sys/class/dmi/id/board_vendor 2>/dev/null || echo 'Unknown')"
echo "board_name=$(cat /sys/class/dmi/id/board_name 2>/dev/null || echo 'Unknown')"
@@ -28,9 +38,9 @@ echo "sockets=$(lscpu 2>/dev/null | grep 'Socket(s)' | awk '{print $2}')"
echo "threads_per_core=$(lscpu 2>/dev/null | grep 'Thread(s) per core' | awk '{print $2}')"
# CPU usage - sample /proc/stat with 1 second interval
read -r label user1 nice1 system1 idle1 iowait1 irq1 softirq1 steal1 < /proc/stat
read -r label user1 nice1 system1 idle1 iowait1 irq1 softirq1 steal1 _ < /proc/stat
sleep 1
read -r label user2 nice2 system2 idle2 iowait2 irq2 softirq2 steal2 < /proc/stat
read -r label user2 nice2 system2 idle2 iowait2 irq2 softirq2 steal2 _ < /proc/stat
total1=$((user1 + nice1 + system1 + idle1 + iowait1 + irq1 + softirq1 + steal1))
total2=$((user2 + nice2 + system2 + idle2 + iowait2 + irq2 + softirq2 + steal2))
@@ -196,9 +206,6 @@ gather_container_stats() {
[ -n "$uptime_s" ] && echo "uptime_seconds=$uptime_s"
}
# Ensure sbin paths are available (not always in PATH for non-root users)
export PATH="$PATH:/usr/sbin:/usr/local/sbin:/sbin"
# Use sudo if available and needed (infmap user won't have direct access)
_sudo() {
if [ "$(id -u)" -eq 0 ]; then

View File

@@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="60">
<title>Infrastructure Map</title>
<link rel="stylesheet" href="/static/style.css">
</head>
@@ -44,6 +43,7 @@
{% endif %}
<div class="server-card {% if not server.is_online %}offline{% endif %}"
data-server-id="{{ server.id }}"
onclick="toggleDetails(this)">
<div class="card-summary">
<div class="card-header">
@@ -54,7 +54,7 @@
{% endif %}
</div>
<div class="server-ip">{{ server.primary_ip or 'No IP' }}</div>
<div class="server-os">{{ sys.get('os_pretty', '') }}</div>
<div class="server-os">{% if sys.get('platform') %}{{ sys.get('platform')|capitalize }} {{ sys.get('platform_version', '') }} / {% endif %}{{ sys.get('os_pretty', '') }}</div>
{% if server.is_online and (cpu.get('model') or mem.get('total_mb')) %}
<div class="server-hw">
{%- if cpu.get('model') %}{{ cpu.get('model') }}{% endif %}
@@ -117,6 +117,9 @@
<table>
<tr><td>Hostname</td><td>{{ sys.get('hostname', '-') }}</td></tr>
<tr><td>OS</td><td>{{ sys.get('os_pretty', '-') }}</td></tr>
{% if sys.get('platform') %}
<tr><td>Platform</td><td>{{ sys.get('platform')|capitalize }} {{ sys.get('platform_version', '') }}</td></tr>
{% endif %}
<tr><td>Kernel</td><td>{{ sys.get('kernel', '-') }}</td></tr>
<tr><td>Arch</td><td>{{ sys.get('arch', '-') }}</td></tr>
<tr><td>Uptime</td><td>{{ sys.get('uptime_seconds', '')|format_uptime }}</td></tr>
@@ -355,9 +358,12 @@
if (!isOpen) {
details.style.display = 'block';
card.classList.add('expanded');
location.hash = card.dataset.serverId;
// Auto-resize notes textarea
const ta = details.querySelector('.notes-input');
if (ta) autoResizeNotes(ta);
} else {
history.replaceState(null, '', location.pathname);
}
}
@@ -381,6 +387,28 @@
body: JSON.stringify({notes: ta.value})
});
}
// Restore expanded card from URL hash after reload
function restoreExpanded() {
const id = location.hash.slice(1);
if (!id) return;
const card = document.querySelector('.server-card[data-server-id="' + id + '"]');
if (card) toggleDetails(card);
}
// Auto-refresh without full page reload if a card is expanded,
// otherwise do a simple reload
setInterval(function() {
if (document.querySelector('.server-card.expanded')) {
// A card is open - reload page preserving hash
location.reload();
} else {
location.reload();
}
}, 60000);
// Restore state on load
restoreExpanded();
</script>
</body>
</html>