137 lines
8.2 KiB
PHP
137 lines
8.2 KiB
PHP
<?= $this->extend('layouts/main') ?>
|
|
|
|
<?= $this->section('content') ?>
|
|
<header class="cb-page-header cb-page-header--center">
|
|
<div>
|
|
<h1 class="cb-page-title">Alerts</h1>
|
|
<p class="cb-page-subtitle">Threshold notifications on chart metrics.</p>
|
|
</div>
|
|
<a href="<?= base_url('alert/create') ?>" class="btn cb-page-primary-btn">+ New alert</a>
|
|
</header>
|
|
|
|
<div class="cb-page-body">
|
|
<?php if (session()->getFlashdata('success')): ?>
|
|
<div class="alert alert-success"><?= esc(session()->getFlashdata('success')) ?></div>
|
|
<?php endif; ?>
|
|
<?php if (session()->getFlashdata('error')): ?>
|
|
<div class="alert alert-danger"><?= esc(session()->getFlashdata('error')) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row g-4">
|
|
<div class="col-lg-4">
|
|
<div class="cb-alert-panel">
|
|
<p class="cb-alert-panel-title mb-0">Recent triggers</p>
|
|
<?php if ($recent === []): ?>
|
|
<p class="cb-alert-empty-text">No recent notifications.</p>
|
|
<?php else: ?>
|
|
<ul class="list-group list-group-flush mt-2">
|
|
<?php foreach ($recent as $r): ?>
|
|
<li class="list-group-item px-0 border-start-0 border-end-0">
|
|
<div class="small fw-semibold"><?= esc($r['alert_name'] ?? '') ?></div>
|
|
<div class="text-muted" style="font-size:11px;"><?= esc($r['chart_name'] ?? '') ?></div>
|
|
<div class="small">Value <code><?= esc((string) ($r['metric_value'] ?? '')) ?></code></div>
|
|
<div class="text-muted" style="font-size:10px;"><?= esc($r['triggered_at'] ?? '') ?></div>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-8">
|
|
<?php if ($alerts === []): ?>
|
|
<div class="cb-alert-empty-panel">
|
|
<div>
|
|
<span class="material-symbols-outlined cb-alert-empty-icon d-block">notifications_active</span>
|
|
<p class="cb-alert-empty-msg">No alerts yet. Create one to get notified when a metric crosses a threshold.</p>
|
|
<a href="<?= base_url('alert/create') ?>" class="btn cb-alert-create-btn">Create alert</a>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="cb-table-shell table-responsive">
|
|
<table class="table cb-data-table align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Chart</th>
|
|
<th>Rule</th>
|
|
<th>Status</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($alerts as $a): ?>
|
|
<?php
|
|
$mutedUntil = $a['is_muted_until'] ?? null;
|
|
$isMuted = $mutedUntil && strtotime((string) $mutedUntil) > time();
|
|
$lastTrig = $a['last_triggered_at'] ?? null;
|
|
$recentTrig = $lastTrig && (time() - strtotime((string) $lastTrig)) < 86400;
|
|
?>
|
|
<tr>
|
|
<td class="fw-semibold"><?= esc($a['name']) ?></td>
|
|
<td class="small"><?= esc($a['chart_name'] ?? '') ?></td>
|
|
<td class="small"><code><?= esc($a['metric_field']) ?></code> <?= esc($a['condition']) ?> <?= esc((string) $a['threshold']) ?></td>
|
|
<td>
|
|
<?php if (! (int) ($a['is_active'] ?? 1)): ?>
|
|
<span class="badge bg-secondary">Off</span>
|
|
<?php elseif ($isMuted): ?>
|
|
<span class="badge bg-warning text-dark">Muted</span>
|
|
<?php elseif ($recentTrig): ?>
|
|
<span class="badge bg-danger">Triggered</span>
|
|
<?php else: ?>
|
|
<span class="badge bg-success">OK</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-end">
|
|
<div class="cb-table-actions flex-wrap justify-content-end">
|
|
<a href="<?= base_url('alert/edit/' . (int) $a['id']) ?>" class="cb-action-btn cb-action-btn--edit">Edit</a>
|
|
<a href="<?= base_url('alert/history/' . (int) $a['id']) ?>" class="cb-action-btn cb-action-btn--ghost">History</a>
|
|
<div class="dropdown d-inline-block">
|
|
<button class="cb-action-btn cb-action-btn--ghost dropdown-toggle" type="button" data-bs-toggle="dropdown">Mute</button>
|
|
<ul class="dropdown-menu dropdown-menu-end">
|
|
<li>
|
|
<form action="<?= base_url('alert/mute/' . (int) $a['id']) ?>" method="post">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="hours" value="1">
|
|
<button type="submit" class="dropdown-item">1 hour</button>
|
|
</form>
|
|
</li>
|
|
<li>
|
|
<form action="<?= base_url('alert/mute/' . (int) $a['id']) ?>" method="post">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="hours" value="4">
|
|
<button type="submit" class="dropdown-item">4 hours</button>
|
|
</form>
|
|
</li>
|
|
<li>
|
|
<form action="<?= base_url('alert/mute/' . (int) $a['id']) ?>" method="post">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="hours" value="24">
|
|
<button type="submit" class="dropdown-item">24 hours</button>
|
|
</form>
|
|
</li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li>
|
|
<form action="<?= base_url('alert/unmute/' . (int) $a['id']) ?>" method="post">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" class="dropdown-item">Clear mute</button>
|
|
</form>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<form action="<?= base_url('alert/delete/' . (int) $a['id']) ?>" method="post" class="d-inline m-0" onsubmit="return confirm('Delete this alert?');">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" class="cb-action-btn cb-action-btn--delete">Delete</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?= $this->endSection() ?>
|