From 16f88d4401019eeedb1ba11b740edd7222a66177 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 20 Apr 2026 22:57:31 -0400 Subject: [PATCH] Combine file systems into one card --- cgi-bin/malp.rb | 74 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/cgi-bin/malp.rb b/cgi-bin/malp.rb index 8be0289..c9a4cdc 100755 --- a/cgi-bin/malp.rb +++ b/cgi-bin/malp.rb @@ -182,16 +182,20 @@ if cgi.params.key?("content") end if filesystems.any? - html << %(
File Systems
) - html << %(
) - filesystems.each do |entry| - mount = CGI.escapeHTML(entry["mount"].to_s) + total_size = filesystems.sum { |e| e["size"].to_i } + total_used = filesystems.sum { |e| e["used"].to_i } + total_pct_f = total_size > 0 ? (total_used * 100.0 / total_size) : 0.0 + total_pct = total_pct_f.round + total_cls = total_pct_f >= 90 ? "bad" : total_pct_f >= 75 ? "warn" : "ok" + + fs_rows = filesystems.map do |entry| + 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)) @@ -207,30 +211,62 @@ if cgi.params.key?("content") fs_stats << ["warn", "READ-ONLY"] if entry["readonly"] severities = [space_cls, inode_cls] - card_cls = severities.include?("bad") ? "bad" : - severities.include?("warn") ? "warn" : "ok" + row_cls = severities.include?("bad") ? "bad" : + severities.include?("warn") ? "warn" : "ok" stats_html = fs_stats.map { |c, txt| %(#{CGI.escapeHTML(txt)}) }.join stats_block = fs_stats.empty? ? "" : - %(
#{stats_html}
) + %(
#{stats_html}
) - html << <<~HTML -
-
- #{mount} #{fstype} - #{pct}% + row_html = <<~HTML +
+
+
+
+ #{mount} · #{source} + #{fstype} +
+ #{pct}% · #{used_h} / #{size_h}
-
- #{source} - #{used_h} / #{size_h} -
-
+
#{stats_block}
HTML + + [row_html, row_cls] end + + severities = fs_rows.map { |_, c| c } + card_cls = severities.include?("bad") ? "bad" : + severities.include?("warn") ? "warn" : "ok" + + total_used_h = CGI.escapeHTML(human_capacity(total_used)) + total_size_h = CGI.escapeHTML(human_capacity(total_size)) + + html << %() + html << <<~HTML +
+
+ File Systems + #{total_pct}% +
+
+ HTML + + fs_rows.each { |row_html, _| html << row_html } + + html << %(
) + html << <<~HTML +
+
+ Total + #{total_pct}% · #{total_used_h} / #{total_size_h} +
+
+
+ HTML html << %(
) end