Files
weval-l99/v131_broken_badge.py
2026-04-24 04:38:58 +02:00

32 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""V131 - Broken badge in dashboards counter: shows 'N broken' in red if HTTP status != 200
Registry fetches HTTP status for each dashboard (V117-HTTP-BADGES already does this).
Add aggregate display in the counter area.
"""
path = "/var/www/html/all-ia-hub.html"
with open(path, "r", encoding="utf-8") as f:
c = f.read()
if "V131-BROKEN-COUNT" in c:
print("ALREADY")
exit(0)
# Find the count display line in renderDashGrid + augment with broken count
old = """ if (countEl) countEl.textContent = filtered.length + ' / ' + items.length + ' tuiles' + (pinned.size ? ' (' + pinned.size + ' pin' + (pinned.size>1?'s':'') + ')' : '');"""
new = """ /* V131-BROKEN-COUNT: aggregate status from registry */
const brokenCount = items.filter(e => e.http_status && e.http_status >= 400).length;
if (countEl) {
const brokenSuffix = brokenCount > 0
? ' <span style=\"color:#ef4444;margin-left:6px;font-weight:600\" title=\"Broken dashboards (HTTP &gt;= 400)\">&#9679; ' + brokenCount + ' broken</span>'
: ' <span style=\"color:#10b981;margin-left:6px;font-weight:600\" title=\"All dashboards healthy\">&#9679; all OK</span>';
countEl.innerHTML = filtered.length + ' / ' + items.length + ' tuiles' + (pinned.size ? ' (' + pinned.size + ' pin' + (pinned.size>1?'s':'') + ')' : '') + brokenSuffix;
}"""
assert old in c, "count anchor missing"
c = c.replace(old, new, 1)
with open(path, "w", encoding="utf-8") as f:
f.write(c)
print(f"PATCHED size={len(c)}")