Polish: phone alert cards, quieter badges, footer, small layout fixes #48

Merged
jared merged 1 commits from polish into main 2026-11-18 01:49:35 -05:00
6 changed files with 87 additions and 35 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ Ping-only (no node_exporter): **pbs** (10.10.10.3)
Served by `GET /api/attention` (`attention.py`) and refreshed with the rest of the page.
- Device search (see Device pages below)
- Active alerts table with severity, target, consecutive failures, ticket link
- WAN / Fiber panel: WAN and PON state, Rx/Tx power, optics temperature, throughput, errors, gateway uptime and last restart, a 24 hour internet health strip from UniFi, 7-day Rx trend, recent WAN outages
- WAN / Fiber panel: WAN and PON state, Rx/Tx power, optics temperature, throughput, errors, gateway uptime and last restart (just the last restart when the gateway doesn't report uptime), a 24 hour internet health strip from UniFi, 7-day Rx trend, recent WAN outages
- Hosts with per-NIC link state; NICs marked unused fold into a "+N unused" line
- UniFi devices as a compact list (name and model; offline ones turn red with a suppress button)
- Recently resolved alerts, folded until opened
+22 -12
View File
@@ -363,6 +363,16 @@ function _modemLastRestart(history) {
return `restarted ${_modemWhen(last.at)}${last.by ? ` by ${last.by}` : ''}`;
}
function _modemUptimeStat(data) {
if (data.uptime_s !== null && data.uptime_s !== undefined) {
return _modemStat('Uptime', _modemUptime(data.uptime_s), '', _modemLastRestart(data.wan_history));
}
const restarts = (data.wan_history && data.wan_history.restarts) || [];
if (!restarts.length) return '';
const last = restarts[restarts.length - 1];
return _modemStat('Last restart', _modemWhen(last.at), '', last.by ? `by ${last.by}` : '');
}
function _modemDuration(seconds) {
if (seconds < 60) return `${Math.round(seconds)}s`;
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${Math.round(seconds % 60)}s`;
@@ -467,7 +477,7 @@ function updateModem(data) {
${_modemOptic('Optics temp', optics.temperature, status.temperature, '°C')}
${_modemStat('Throughput', `↓ ${_modemRate(rates.rx_bytes)}`, '', `↑ ${_modemRate(rates.tx_bytes)}`)}
${_modemStat('Errors / drops', `${errs} / ${drops}`, errs ? 'lt-text-amber' : '', 'since modem reboot')}
${_modemStat('Uptime', _modemUptime(data.uptime_s), '', _modemLastRestart(data.wan_history))}
${_modemUptimeStat(data)}
</div>
${_modemQuality(data.wan_quality)}
${_modemChart(data.history)}
@@ -526,16 +536,16 @@ function updateEventsTable(events, totalActive) {
: '';
return `
<tr class="row-${e.severity}${e.is_suppressed ? ' row-suppressed' : ''}">
<td><span class="lt-badge badge-${e.severity}">${e.severity}</span>${supBadge}${staleBadge}${closedBadge}</td>
<td>${lt.escHtml(e.event_type.replace(/_/g,' '))}</td>
<td><strong>${lt.escHtml(e.target_name)}</strong></td>
<td>${lt.escHtml(e.target_detail || '-')}</td>
<td class="desc-cell" title="${lt.escHtml(e.description || '')}">${lt.escHtml((e.description||'').substring(0,60))}${(e.description||'').length>60?'…':''}</td>
<td class="ts-cell" title="${lt.escHtml(e.first_seen||'')}">${lt.time.ago(_toIso(e.first_seen))}</td>
<td class="ts-cell" title="${lt.escHtml(e.last_seen||'')}">${lt.time.ago(_toIso(e.last_seen))}</td>
<td>${e.consecutive_failures}</td>
<td>${ticket}</td>
<td>
<td data-label="Sev"><span class="lt-badge badge-${e.severity}">${e.severity}</span>${supBadge}${staleBadge}${closedBadge}</td>
<td data-label="Type">${lt.escHtml(e.event_type.replace(/_/g,' '))}</td>
<td data-label="Target"><strong>${lt.escHtml(e.target_name)}</strong></td>
<td data-label="Detail">${lt.escHtml(e.target_detail || '-')}</td>
<td data-label="Description" class="desc-cell" title="${lt.escHtml(e.description || '')}">${lt.escHtml((e.description||'').substring(0,60))}${(e.description||'').length>60?'…':''}</td>
<td data-label="First seen" class="ts-cell" title="${lt.escHtml(e.first_seen||'')}">${lt.time.ago(_toIso(e.first_seen))}</td>
<td data-label="Last seen" class="ts-cell" title="${lt.escHtml(e.last_seen||'')}">${lt.time.ago(_toIso(e.last_seen))}</td>
<td data-label="Failures">${e.consecutive_failures}</td>
<td data-label="Ticket">${ticket}</td>
<td data-label="Actions">
<button class="lt-btn lt-btn-ghost lt-btn-sm btn-suppress"
data-sup-type="${lt.escHtml(supType)}"
data-sup-name="${lt.escHtml(e.target_name)}"
@@ -548,7 +558,7 @@ function updateEventsTable(events, totalActive) {
wrap.innerHTML = `
${countNotice}
<div class="lt-table-wrap">
<table class="lt-table" id="events-table">
<table class="lt-table lt-table-responsive" id="events-table">
<caption class="lt-sr-only">Active network alerts</caption>
<thead>
<tr>
+1
View File
@@ -488,6 +488,7 @@
const date = value instanceof Date ? value : new Date(value);
if (isNaN(date)) return '-';
const diff = Math.floor((Date.now() - date.getTime()) / 1000);
if (diff < 5) return 'just now'; // also a clock a little ahead of this browser's
if (diff < 60) return diff + 's ago';
if (diff < 3600) return Math.floor(diff / 60) + 'm ago';
if (diff < 86400) return Math.floor(diff / 3600) + 'h ago';
+30 -8
View File
@@ -177,13 +177,18 @@
text-transform: uppercase;
letter-spacing: .08em;
}
/* A count. Neutral by default; red only where it counts problems (active alerts, follow-ups). */
.g-section-badge {
font-size: .72em;
font-weight: bold;
color: var(--accent-red);
border: 1px solid var(--accent-red);
color: var(--text-muted);
border: 1px solid var(--border-color);
padding: 1px 7px;
}
.g-section-badge-alert {
color: var(--accent-red);
border-color: var(--accent-red);
}
.g-section-badge-resolved {
font-size: .68em;
color: var(--text-muted);
@@ -330,7 +335,6 @@
letter-spacing: .04em;
font-weight: bold;
}
.source-prometheus { color: var(--orange); border-color: var(--orange-dim); }
.source-ping { color: var(--cyan); border-color: var(--cyan-dim); }
.iface-list { border-top: 1px solid var(--border-color); padding-top: 6px; margin-bottom: 8px; }
.iface-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
@@ -345,8 +349,9 @@
/* ── Form layout helpers (used in suppressions.html form grids) ───── */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.form-row-align { align-items: flex-end; }
.form-row > .lt-form-group { flex: 1 1 220px; }
.form-group-wide { flex: 3; }
.form-group-submit { flex: 0 0 auto; min-width: unset; }
.form-group-submit, .form-row > .form-group-submit { flex: 0 0 auto; min-width: unset; }
.required { color: var(--red); }
/* ── Duration pills ───────────────────────────────────────────────── */
@@ -914,10 +919,6 @@ a.device-link:hover { color: var(--text-accent); border-bottom-color: current
.device-table th, .device-table td { padding-left: 6px; padding-right: 6px; }
}
.device-search-row.is-active { box-shadow: inset 3px 0 0 var(--terminal-cyan, #0ff); }
@media (max-width: 700px) {
/* Scroll inside the wrapper rather than squeezing every column to a few letters */
#events-table { min-width: 760px; }
}
/* ── Port inspector on the device page ────────────────────────────── */
.device-inspector { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px 16px; align-items: start; }
@@ -1827,3 +1828,24 @@ body.fp-marks-off .fp-svg .fp-mark { display: none; }
.lt-header-user, .lt-cmd-hint-btn, .lt-header-right [data-action="start-maintenance"] { display: none; }
}
.g-drawer-action { background: none; border: 0; width: 100%; text-align: left; font: inherit; cursor: pointer; }
/* ── Footer: the CFG and HELP buttons read like the keyboard hints beside them ── */
button.lt-footer-hint {
background: none; border: 0; padding: 0; margin: 0;
font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer;
}
button.lt-footer-hint:hover, button.lt-footer-hint:focus-visible { color: var(--accent-cyan, var(--cyan)); }
/* ── Footer at the bottom of the window on short pages, not halfway up ── */
body { display: flex; flex-direction: column; }
body > .lt-main { flex: 1 0 auto; width: 100%; }
body > .lt-footer { flex-shrink: 0; }
/* ── Active alerts: room for the filter's hint; full-width cards on phones ── */
#events-search { min-width: 300px; }
@media (max-width: 767px) {
#events-search { min-width: 0; }
#events-table, #events-table tbody { display: block; width: 100%; }
#events-table td { max-width: none; }
#events-table td.desc-cell { white-space: normal; text-align: right; }
}
+14 -14
View File
@@ -53,7 +53,7 @@
<section class="g-section">
<div class="g-section-header">
<h2 class="g-section-title">Active Alerts</h2>
<span class="g-section-badge" id="alert-count-badge"
<span class="g-section-badge g-section-badge-alert" id="alert-count-badge"
{% if not summary.critical and not summary.warning %}style="display:none"{% endif %}>{{ (summary.critical or 0) + (summary.warning or 0) }}</span>
</div>
<div class="lt-toolbar">
@@ -80,7 +80,7 @@
<div class="pagination-notice">Showing {{ events|length }} of {{ total_active }} active alerts. Use the search box to filter, or <a href="/api/events?limit=1000" target="_blank" rel="noopener">export all as JSON</a></div>
{% endif %}
<div class="lt-table-wrap">
<table class="lt-table" id="events-table">
<table class="lt-table lt-table-responsive" id="events-table">
<caption class="lt-sr-only">Active network alerts</caption>
<thead>
<tr>
@@ -100,30 +100,30 @@
{% for e in events %}
{% if e.severity != 'info' %}
<tr class="row-{{ e.severity }}{% if e.is_suppressed %} row-suppressed{% endif %}">
<td>
<td data-label="Sev">
<span class="lt-badge badge-{{ e.severity }}">{{ e.severity }}</span>
{% if e.is_suppressed %}<span class="lt-badge badge-suppressed" title="Alert suppressed">🔕 sup</span>{% endif %}
{% if e.stale_days is not none %}<span class="lt-badge badge-stale" title="Active for {{ e.stale_days }} days with no fix yet">⏳ {{ e.stale_days }}d</span>{% endif %}
{% if e.ticket_closed %}<span class="lt-badge badge-ticket-closed" title="Ticket #{{ e.ticket_id }} was closed in Tinker, but this alert is still active">ticket closed</span>{% endif %}
</td>
<td>{{ e.event_type | replace('_', ' ') }}</td>
<td><strong>{{ e.target_name }}</strong></td>
<td>{{ e.target_detail or '-' }}</td>
<td class="desc-cell" title="{{ e.description | e }}">{{ e.description | truncate(60) }}</td>
<td class="ts-cell" title="{{ e.first_seen }}">
<td data-label="Type">{{ e.event_type | replace('_', ' ') }}</td>
<td data-label="Target"><strong>{{ e.target_name }}</strong></td>
<td data-label="Detail">{{ e.target_detail or '-' }}</td>
<td data-label="Description" class="desc-cell" title="{{ e.description | e }}">{{ e.description | truncate(60) }}</td>
<td data-label="First seen" class="ts-cell" title="{{ e.first_seen }}">
<span class="event-age" data-ts="{{ e.first_seen }}">{{ e.first_seen }}</span>
</td>
<td class="ts-cell" title="{{ e.last_seen }}">
<td data-label="Last seen" class="ts-cell" title="{{ e.last_seen }}">
<span class="event-age" data-ts="{{ e.last_seen }}">{{ e.last_seen }}</span>
</td>
<td>{{ e.consecutive_failures }}</td>
<td>
<td data-label="Failures">{{ e.consecutive_failures }}</td>
<td data-label="Ticket">
{% if e.ticket_id %}
<a href="{{ config.ticket_api.web_url }}{{ e.ticket_id }}" target="_blank"
class="ticket-link">#{{ e.ticket_id }}</a>
{% else %}-{% endif %}
</td>
<td>
<td data-label="Actions">
<button class="lt-btn lt-btn-ghost lt-btn-sm btn-suppress"
data-sup-type="{{ 'unifi_device' if e.event_type == 'unifi_device_offline' else 'interface' if e.event_type == 'interface_down' else 'host' }}"
data-sup-name="{{ e.target_name }}"
@@ -157,7 +157,7 @@
<section class="g-section" id="followup"{% if not stale_tickets %} hidden{% endif %}>
<div class="g-section-header">
<h2 class="g-section-title">Needs Follow-up</h2>
<span class="g-section-badge" id="followup-badge">{{ stale_tickets | length }}</span>
<span class="g-section-badge g-section-badge-alert" id="followup-badge">{{ stale_tickets | length }}</span>
</div>
<p class="followup-intro">These tickets are still open in Tinker, but their alert cleared over a day ago. Close them if the problem is fixed.</p>
<div class="lt-frame">
@@ -212,7 +212,7 @@
</div>
<div class="host-meta">
<span class="host-ip">{{ host.ip }}</span>
<span class="host-source source-{{ host.source }}">{{ host.source }}</span>
{% if host.source != 'prometheus' %}<span class="host-source source-{{ host.source }}">{{ host.source }}</span>{% endif %}
</div>
</div>
+19
View File
@@ -850,6 +850,25 @@ class TestCalmDashboard:
assert '>eth0<' in html and '>eth1<' not in html
assert '+2 unused' in html
def test_source_tag_only_for_hosts_without_node_exporter(self, client):
snap = json.dumps({'hosts': {
'large1': {'ip': '10.0.0.2', 'status': 'up', 'source': 'prometheus', 'interfaces': {'eth0': 'up'}},
'pbs': {'ip': '10.0.0.3', 'status': 'up', 'source': 'ping', 'interfaces': {}}}, 'unifi': []})
state = dict(STATE, network_snapshot=snap)
with patch.object(gandalf.db, 'get_state', side_effect=lambda k, d=None: state.get(k, d)):
html = client.get('/', headers=AUTH).get_data(as_text=True)
assert 'source-prometheus' not in html
assert '<span class="host-source source-ping">ping</span>' in html
def test_alert_table_turns_into_cards_on_phones(self, client):
ev = {'id': 1, 'event_type': 'host_down', 'severity': 'critical', 'target_name': 'pbs',
'target_detail': '', 'description': 'pbs is down', 'consecutive_failures': 3,
'first_seen': '2026-11-15 01:00:00', 'last_seen': '2026-11-15 02:00:00'}
with patch.object(gandalf.db, 'get_active_events', return_value=[ev]):
html = client.get('/', headers=AUTH).get_data(as_text=True)
assert 'class="lt-table lt-table-responsive" id="events-table"' in html
assert 'data-label="Target"><strong>pbs</strong>' in html
def test_resolved_alerts_are_folded(self, client):
ev = {'target_name': 'large1', 'target_detail': '', 'severity': 'warning', 'event_type': 'host_down',
'first_seen': '2026-11-15 01:00:00 UTC', 'resolved_at': '2026-11-15 02:00:00 UTC'}