From 69a5baeb8d3faa3c934007250149e36116dbb9b0 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 19 Apr 2026 15:08:11 -0400 Subject: [PATCH] Add VM info from bin/vm-info to status page --- cgi-bin/malp.rb | 53 +++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/cgi-bin/malp.rb b/cgi-bin/malp.rb index 7050b69..0240915 100755 --- a/cgi-bin/malp.rb +++ b/cgi-bin/malp.rb @@ -115,7 +115,7 @@ if cgi.params.key?("content") if vms.any? running = vms.count { |v| v["state"].to_s == "running" } - total = vms.size + total = vms.size hdr_cls = running == total ? "ok" : running == 0 ? "bad" : "warn" html << %(
) @@ -127,17 +127,18 @@ if cgi.params.key?("content") #{running} / #{total} Running
-
+
VM - Resources + OS + Resources Disk State
HTML vms.each do |vm| - name = CGI.escapeHTML(vm["name"].to_s) - os = vm["os"] ? CGI.escapeHTML(vm["os"]) : nil + name = CGI.escapeHTML(vm["name"].to_s) + os_name = vm["os_name"] ? CGI.escapeHTML(vm["os_name"]) : nil state = vm["state"].to_s state_cls = case state when "running" then "ok" @@ -151,10 +152,11 @@ if cgi.params.key?("content") mem_b = vm["memory"].to_i res = vcpus > 0 || mem_b > 0 ? "#{vcpus} CPU#{vcpus > 1 ? "s" : ""} · #{human_capacity(mem_b)}" : "—" - cap = vm["disk_total"].to_i - used = vm["disk_used"].to_i - dpct_f = cap > 0 ? (used * 100.0 / cap) : 0.0 - dpct = dpct_f.round + df = vm["df"] || [] + cap = df[0].to_i * 1024 + used = df[1].to_i * 1024 + dpct_f = cap > 0 ? (used * 100.0 / cap) : 0.0 + dpct = dpct_f.round disk_cls = dpct_f >= 90 ? "bad" : dpct_f >= 75 ? "warn" : "ok" disk_html = if cap > 0 @@ -166,22 +168,35 @@ if cgi.params.key?("content") %(
) end - os_html = os ? %(
#{os}
) : "" + os_html = os_name ? os_name : "" + + vm_stats = [] + if updates = vm["updates"] + cls = updates == 0 ? "ok" : "warn" + vm_stats << [cls, "#{updates} update#{updates == 1 ? "" : "s"}"] + end + if reboot = vm["reboot_pending"] + vm_stats << ["warn", "Reboot pending"] + end + vm_stats_html = vm_stats.map { |c, txt| + %(#{CGI.escapeHTML(txt)}) + }.join + vm_stats_block = vm_stats.empty? ? "" : + %(
#{vm_stats_html}
) html << <<~HTML
-
+
-
-
#{name}
- #{os_html} -
+
#{name}
-
#{CGI.escapeHTML(res)}
+
#{os_html}
+
#{CGI.escapeHTML(res)}
#{disk_html}
#{state_label}
+ #{vm_stats_block}
HTML end @@ -281,13 +296,13 @@ if cgi.params.key?("content") html << %() html << %(
) filesystems.each do |entry| - mount = CGI.escapeHTML(entry["mount"].to_s) + mount = CGI.escapeHTML(entry["mount"].to_s) source = CGI.escapeHTML(entry["source"].to_s) fstype = CGI.escapeHTML(entry["fstype"].to_s) size_b = entry["size"].to_i used_b = entry["used"].to_i - pct_f = size_b > 0 ? (used_b * 100.0 / size_b) : 0.0 - pct = pct_f.round + pct_f = size_b > 0 ? (used_b * 100.0 / size_b) : 0.0 + pct = pct_f.round space_cls = pct_f >= 90 ? "bad" : pct_f >= 75 ? "warn" : "ok" used_h = CGI.escapeHTML(human_capacity(used_b)) size_h = CGI.escapeHTML(human_capacity(size_b))