Files
FabledSteward/steward/templates/alerts/list.html
T
bvandeusenandClaude Opus 5.5 5569f9934e
CI / lint (push) Successful in 2s
CI / integration (push) Failing after 1m24s
CI / unit (push) Successful in 1m37s
CI / publish (push) Skipped
feat(anomalies): a metric out of its normal is an anomaly to review (#5740)
#5740 "A metric that departs from its normal is recorded as an anomaly to
review, and is findable after it ends", milestone 513.

- Every minute each learned key's last 15 minutes is judged against its
  hour's normal: above the usual hold x1.25 and by the metric's floor opens
  an occurrence, which ends when the level comes back.
- metric_anomalies holds one row per item to review; a repeat while it
  still waits joins it as an occurrence (metric_anomaly_spans).
- An ended row nobody reviews within anomalies.review_days (14, Settings ->
  Thresholds) lapses; an ongoing one never does.
- Learning skips every hour an occurrence covers unless its anomaly was
  marked normal: no normal is learned without review.
- Alerts -> Anomalies lists those to review first, then the reviewed and
  lapsed under day dividers; marking is operator/admin and audited.
- The Overview widget and get_overview warn of open ones and count those
  to review; the host page shows its own; the weekly report lists the
  week's and the lapsed; MCP list_anomalies and review_anomaly.
- Reviewed and lapsed rows are pruned at data.retention_days, and kept
  in backups like alert history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 13:41:57 -04:00

118 lines
6.4 KiB
HTML

{# alerts/list.html — the Alerts page (#5315): the verdict and what is active
(alerts/_active.html, polled), then every rule: what it is doing now and
when it last fired, what it fires on, and its History and Disable. The
whole row opens the rule (.row-link, its name is the link); deleting one is
on its own page, behind the confirm dialog. A rule covering hosts (#5464)
lists its per-host rules under it, closed behind its "N hosts" toggle
unless one of them isn't quiet (#5483); each opens its history. #}
{% extends "base.html" %}
{% block title %}Alerts — Steward{% endblock %}
{% from "_macros.html" import page_header, status_badge, empty_state %}
{% block content %}
{% set can_edit = session.user_role in ('operator', 'admin') %}
{% set rules_total = rules|length %}
{% set rules_off = rules|rejectattr("enabled")|list|length %}
{% call page_header("Alerts") %}
<a class="btn btn-ghost" href="/alerts/history">History</a>
<a class="btn btn-ghost" href="/alerts/anomalies">Anomalies</a>
<a class="btn btn-ghost" href="/alerts/maintenance">Maintenance</a>
{% if can_edit %}<a class="btn" href="/alerts/rules/new">New rule</a>{% endif %}
{% endcall %}
{# The verdict and Active section re-read themselves, so an alert that clears
or starts shows without a reload. #}
<div id="alerts-active" hx-get="/alerts/active" hx-trigger="every {{ poll_interval or 60 }}s" hx-swap="innerHTML">
{% include "alerts/_active.html" %}
</div>
<h2 class="section-title" style="margin:1.5rem 0 1rem;">Rules</h2>
{% if rules %}
<div class="card-flush">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Now</th>
<th>Fires when</th>
<th></th>
</tr>
</thead>
{% for rule in rules %}
{% set kids = (children or {}).get(rule.id, []) %}
{% set fired = (last_fired or {}).get(rule.id) %}
{% set restless = (uneasy or {}).get(rule.id, []) %}
<tbody>
<tr class="row-link{% if not rule.enabled %} row-off{% endif %}">
<td class="cell-name">
<a class="row-target" href="{{ ('/alerts/rules/' ~ rule.id ~ '/edit') if can_edit else ('/alerts/history?rule=' ~ rule.id) }}" title="{{ rule.name }}">{{ rule.name }}</a>
<div class="cell-sub">{{ source_label(rule.source_module) }}
{%- if rule.covers != "resource" %} · <button type="button" class="row-toggle row-inner"
aria-expanded="{{ 'true' if restless else 'false' }}" aria-controls="hosts-{{ rule.id }}"
onclick="toggleHosts(this)">{{ kids|length }} host{{ "s" if kids|length != 1 }}</button>{% endif %}</div>
</td>
<td>
{%- set now_label = (rule_state or {}).get(rule.id) %}
{%- if not rule.enabled %}<span class="tone-dim">off</span>
{%- elif now_label and now_label not in ('inactive', 'resolved') %}{{ status_badge(now_label) }}
{%- else %}<span class="tone-ok" title="Within its threshold">quiet</span>{% endif -%}
<div class="cell-sub">
{%- if restless %}on {{ restless|join(", ") }}
{%- elif fired %}last fired {{ fired|ago }}{% else %}never fired{% endif %}</div>
</td>
<td>
{% if rule.covers == "group" %}every host in {{ rule.cover_group }}{% elif rule.covers == "all_hosts" %}every host{% else %}{{ rule.resource_name }}{% endif %} · {{ rule_condition(rule) }}
<div class="cell-sub">
{%- set n_fire, n_ok = rule.consecutive_failures_required, rule.consecutive_ok_required %}
{%- if n_fire > 1 %}after {{ n_fire }} checks in a row{% else %}on the first check{% endif %}
{%- if n_ok > 1 %}; clears after {{ n_ok }} good ones{% endif -%}
</div>
</td>
<td class="td-actions">
{% if rule.covers == "resource" %}<a href="/alerts/history?rule={{ rule.id }}" class="btn btn-sm btn-ghost">History</a>{% endif %}
{% if can_edit %}
<form method="post" action="/alerts/rules/{{ rule.id }}/toggle" style="display:inline;">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-ghost">
{% if rule.enabled %}Disable{% else %}Enable{% endif %}
</button>
</form>
{% endif %}
</td>
</tr>
</tbody>
{% if kids %}
<tbody id="hosts-{{ rule.id }}" class="row-children"{% if not restless %} hidden{% endif %}>
{% for kid in kids %}
{% set kid_label = (rule_state or {}).get(kid.id) %}
{% set kid_fired = (last_fired or {}).get(kid.id) %}
<tr class="row-link row-child{% if not kid.enabled %} row-off{% endif %}">
<td class="cell-name">
<a class="row-target" href="/alerts/history?rule={{ kid.id }}" title="{{ kid.name }}">{{ kid.resource_name }}</a>
</td>
<td>
{%- if not kid.enabled %}<span class="tone-dim">off</span>
{%- elif kid_label and kid_label not in ('inactive', 'resolved') %}{{ status_badge(kid_label) }}
{%- else %}<span class="tone-ok" title="Within its threshold">quiet</span>{% endif -%}
<div class="cell-sub">{% if kid_fired %}last fired {{ kid_fired|ago }}{% else %}never fired{% endif %}</div>
</td>
<td class="tone-dim">as above</td>
<td class="td-actions"><a href="/alerts/history?rule={{ kid.id }}" class="btn btn-sm btn-ghost">History</a></td>
</tr>
{% endfor %}
</tbody>
{% endif %}
{% endfor %}
</table>
</div>
<script>
// A covering rule's hosts (#5483): closed unless one of them isn't quiet.
function toggleHosts(btn) {
var open = btn.getAttribute('aria-expanded') !== 'true';
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
document.getElementById(btn.getAttribute('aria-controls')).hidden = !open;
}
</script>
{% else %}
<div class="card">{{ empty_state("No alert rules yet.", "New rule" if can_edit else none, "/alerts/rules/new" if can_edit else none) }}</div>
{% endif %}
{% endblock %}