feat: alert rules and active alerts UI

This commit is contained in:
2026-03-17 19:57:53 -04:00
parent 3f3f55b83f
commit 75b0233c94
4 changed files with 245 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
{% extends "base.html" %}
{% block title %}Alerts — FabledNetMon{% endblock %}
{% block content %}
<h1 style="color:#c0c0ff;margin-bottom:1.5rem;">Alerts</h1>
{% if active %}
<h2 style="color:#8080ff;margin-bottom:1rem;font-size:1rem;">Active</h2>
<div class="card" style="padding:0;margin-bottom:2rem;">
<table style="width:100%;border-collapse:collapse;">
<thead>
<tr style="border-bottom:1px solid #2a2a4a;">
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">State</th>
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Rule</th>
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Resource</th>
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Metric</th>
<th style="padding:0.75rem 1rem;"></th>
</tr>
</thead>
<tbody>
{% for state, rule in active %}
<tr style="border-bottom:1px solid #1a1a3a;">
<td style="padding:0.75rem 1rem;">
{% if state.state.value == 'firing' %}
<span style="color:#ff6060;font-weight:bold;">FIRING</span>
{% elif state.state.value == 'acknowledged' %}
<span style="color:#ffa040;">ACK</span>
{% else %}
<span style="color:#a0a0a0;">PENDING</span>
{% endif %}
</td>
<td style="padding:0.75rem 1rem;">{{ rule.name }}</td>
<td style="padding:0.75rem 1rem;color:#a0a0c0;">{{ rule.resource_name }}</td>
<td style="padding:0.75rem 1rem;color:#a0a0c0;">{{ rule.metric_name }} {{ rule.operator.value }} {{ rule.threshold }}</td>
<td style="padding:0.75rem 1rem;text-align:right;">
{% if state.state.value == 'firing' %}
<form method="post" action="/alerts/{{ rule.id }}/acknowledge" style="display:inline;">
<button type="submit" class="btn" style="background:#605010;">Acknowledge</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p style="color:#606080;margin-bottom:2rem;">No active alerts.</p>
{% endif %}
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:1rem;">
<h2 style="color:#8080ff;font-size:1rem;">Rules</h2>
<a class="btn" href="/alerts/rules/new">New Rule</a>
</div>
{% if rules %}
<div class="card" style="padding:0;">
<table style="width:100%;border-collapse:collapse;">
<thead>
<tr style="border-bottom:1px solid #2a2a4a;">
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Name</th>
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Condition</th>
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Consec.</th>
<th style="text-align:left;padding:0.75rem 1rem;color:#8080a0;font-weight:normal;">Enabled</th>
<th style="padding:0.75rem 1rem;"></th>
</tr>
</thead>
<tbody>
{% for rule in rules %}
<tr style="border-bottom:1px solid #1a1a3a;">
<td style="padding:0.75rem 1rem;">{{ rule.name }}</td>
<td style="padding:0.75rem 1rem;color:#a0a0c0;">
{{ rule.source_module }}/{{ rule.resource_name }}:{{ rule.metric_name }}
{{ rule.operator.value }} {{ rule.threshold }}
</td>
<td style="padding:0.75rem 1rem;color:#a0a0c0;">{{ rule.consecutive_failures_required }}</td>
<td style="padding:0.75rem 1rem;">
{% if rule.enabled %}<span style="color:#60c060;">yes</span>{% else %}<span style="color:#606060;">no</span>{% endif %}
</td>
<td style="padding:0.75rem 1rem;text-align:right;">
<form method="post" action="/alerts/rules/{{ rule.id }}/delete" style="display:inline;">
<button type="submit" style="background:none;border:none;color:#ff6060;cursor:pointer;"
onclick="return confirm('Delete rule {{ rule.name }}?')">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p style="color:#606080;">No alert rules configured.</p>
{% endif %}
{% endblock %}
@@ -0,0 +1,49 @@
{% extends "base.html" %}
{% block title %}New Alert Rule — FabledNetMon{% endblock %}
{% block content %}
<div style="max-width:560px;margin:2rem auto;">
<h1 style="color:#c0c0ff;margin-bottom:1.5rem;">New Alert Rule</h1>
<div class="card">
<form method="post" action="/alerts/rules">
<div class="form-group">
<label>Rule Name</label>
<input type="text" name="name" required autofocus placeholder="e.g. Home server down">
</div>
<div class="form-group">
<label>Source Module</label>
<input type="text" name="source_module" required placeholder="ping, dns, traefik, ...">
</div>
<div class="form-group">
<label>Resource Name</label>
<input type="text" name="resource_name" required placeholder="host name, router name, ...">
</div>
<div class="form-group">
<label>Metric Name</label>
<input type="text" name="metric_name" required placeholder="up, response_time_ms, ...">
</div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;">
<div class="form-group">
<label>Operator</label>
<select name="operator" style="width:100%;padding:0.5rem 0.75rem;background:#0f0f1e;border:1px solid #3a3a5a;border-radius:4px;color:#e0e0e0;">
{% for val, label in operators %}
<option value="{{ val }}">{{ label }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>Threshold</label>
<input type="number" name="threshold" step="any" required placeholder="0.5">
</div>
</div>
<div class="form-group">
<label>Consecutive failures required before FIRING (default: 1)</label>
<input type="number" name="consecutive_failures_required" value="1" min="1">
</div>
<div style="display:flex;gap:1rem;margin-top:1.5rem;">
<button type="submit">Create Rule</button>
<a href="/alerts/" style="padding:0.5rem 1rem;color:#a0a0c0;text-decoration:none;">Cancel</a>
</div>
</form>
</div>
</div>
{% endblock %}