Files
Varaverk/Plugin/unraid/include/vms.php
T
Gmer4Lfe fb051b60c1 Varaverk: FallBack + Watchdog tabs; plugin path restructure to Plugin/unraid/
- FallBack tab: per-node tier inventory + active fallback card with duration, tier, handback strikes, running container status
- Watchdog tab: live system health (RAM bar + thresholds, load, uptime, daemon), docker watchdog strikes + skip list + restart history, stability strikes + reboot log, resource pressure alert card, config inventory (mem limits, required, pause/stop lists)
- Swapped partnership/arrs tab order; FallBack between partnership and watchdog
- Plugin source tree moved from Plugin/usr/local/emhttp/plugins/varaverk/ to Plugin/unraid/
- Deployment/ conf templates added
2026-05-28 22:24:50 -04:00

47 lines
1.8 KiB
PHP

<?php
function vv_get_vms(): array {
if (!file_exists('/usr/bin/virsh')) return ['available' => false, 'vms' => []];
exec('virsh list --all --name 2>/dev/null', $names, $rc);
if ($rc !== 0) return ['available' => false, 'vms' => []];
$vms = [];
foreach ($names as $raw) {
$name = trim($raw);
if ($name === '') continue;
$state = trim(shell_exec('virsh domstate ' . escapeshellarg($name) . ' 2>/dev/null') ?? 'unknown');
$vcpus = null;
$memMb = null;
if ($state === 'running') {
$info = shell_exec('virsh dominfo ' . escapeshellarg($name) . ' 2>/dev/null') ?? '';
if (preg_match('/CPU\(s\)\s*:\s*(\d+)/i', $info, $m)) $vcpus = (int)$m[1];
if (preg_match('/Used memory\s*:\s*(\d+)/i', $info, $m)) $memMb = (int)round((int)$m[1] / 1024);
}
// OS detection from libvirt XML
$os = 'linux';
$xmlPath = '/etc/libvirt/qemu/' . $name . '.xml';
if (file_exists($xmlPath)) {
$xml = @file_get_contents($xmlPath) ?: '';
if (stripos($xml, 'windows') !== false || stripos($xml, 'win10') !== false || stripos($xml, 'win11') !== false) $os = 'windows';
elseif (stripos($xml, 'darwin') !== false || stripos($xml, 'macos') !== false) $os = 'macos';
}
$nl = strtolower($name);
if (str_contains($nl, 'win')) $os = 'windows';
elseif (str_contains($nl, 'mac') || str_contains($nl, 'osx')) $os = 'macos';
elseif (str_contains($nl, 'bsd') || str_contains($nl, 'freebsd')) $os = 'bsd';
$vms[] = [
'name' => $name,
'state' => $state,
'os' => $os,
'vcpus' => $vcpus,
'mem_mb' => $memMb,
];
}
return ['available' => true, 'vms' => $vms];
}