90 lines
5.2 KiB
PHP
90 lines
5.2 KiB
PHP
<?= $this->extend('layouts/main') ?>
|
|
|
|
<?= $this->section('content') ?>
|
|
<header class="cb-page-header">
|
|
<div>
|
|
<a href="<?= base_url('alert') ?>" class="text-decoration-none small d-inline-block mb-1" style="color: var(--text-secondary);">← Back to alerts</a>
|
|
<h1 class="cb-page-title">Edit alert</h1>
|
|
<p class="cb-page-subtitle mb-0">Update thresholds, schedule, and notification channels.</p>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="cb-page-body">
|
|
<?php $errs = session()->getFlashdata('errors'); ?>
|
|
<?php if ($errs): ?>
|
|
<div class="alert alert-danger">
|
|
<?php foreach ($errs as $msg): ?>
|
|
<div><?= esc(is_array($msg) ? implode(' ', $msg) : $msg) ?></div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (session()->getFlashdata('error')): ?>
|
|
<div class="alert alert-danger"><?= esc(session()->getFlashdata('error')) ?></div>
|
|
<?php endif; ?>
|
|
<?php if (session()->getFlashdata('success')): ?>
|
|
<div class="alert alert-success"><?= esc(session()->getFlashdata('success')) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<form action="<?= base_url('alert/update/' . (int) $alert['id']) ?>" method="post">
|
|
<?= csrf_field() ?>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold">Name</label>
|
|
<input type="text" name="name" class="form-control" value="<?= esc(old('name', (string) $alert['name'])) ?>" required maxlength="200">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold">Chart</label>
|
|
<select name="chart_id" class="form-select" required>
|
|
<?php foreach ($charts as $c): ?>
|
|
<option value="<?= (int) $c['id'] ?>" <?= (string) (old('chart_id', (string) $alert['chart_id'])) === (string) $c['id'] ? 'selected' : '' ?>><?= esc($c['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold">Metric column</label>
|
|
<input type="text" name="metric_field" class="form-control" value="<?= esc(old('metric_field', (string) $alert['metric_field'])) ?>" required maxlength="150">
|
|
</div>
|
|
<div class="row g-3 mb-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label fw-semibold">Condition</label>
|
|
<select name="condition" class="form-select">
|
|
<?php
|
|
$cur = old('condition', (string) $alert['condition']);
|
|
foreach (['gt' => 'Greater than', 'lt' => 'Less than', 'eq' => 'Equals', 'gte' => 'Greater or equal', 'lte' => 'Less or equal'] as $k => $lab): ?>
|
|
<option value="<?= esc($k) ?>" <?= $cur === $k ? 'selected' : '' ?>><?= esc($lab) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label fw-semibold">Threshold</label>
|
|
<input type="text" name="threshold" class="form-control" value="<?= esc(old('threshold', (string) $alert['threshold'])) ?>" required inputmode="decimal">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label fw-semibold">Check every (minutes)</label>
|
|
<input type="number" name="check_interval" class="form-control" value="<?= esc(old('check_interval', (string) $alert['check_interval'])) ?>" min="1" max="1440">
|
|
</div>
|
|
</div>
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" name="is_active" value="1" id="ia" <?= (int) old('is_active', (string) $alert['is_active']) === 1 ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="ia">Alert enabled</label>
|
|
</div>
|
|
<div class="border rounded-3 p-3 mb-3">
|
|
<div class="form-check mb-2">
|
|
<input class="form-check-input" type="checkbox" name="notify_email" value="1" id="ne" <?= (int) old('notify_email', (string) ($alert['notify_email'] ?? 0)) === 1 ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="ne">Email</label>
|
|
</div>
|
|
<input type="text" name="email_addresses" class="form-control form-control-sm" value="<?= esc(old('email_addresses', (string) ($alert['email_addresses'] ?? ''))) ?>">
|
|
<div class="form-check mt-3 mb-2">
|
|
<input class="form-check-input" type="checkbox" name="notify_slack" value="1" id="ns" <?= (int) old('notify_slack', (string) ($alert['notify_slack'] ?? 0)) === 1 ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="ns">Slack webhook</label>
|
|
</div>
|
|
<input type="url" name="slack_webhook" class="form-control form-control-sm" value="<?= esc(old('slack_webhook', (string) ($alert['slack_webhook'] ?? ''))) ?>">
|
|
</div>
|
|
<button type="submit" class="btn btn-dark">Save changes</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?= $this->endSection() ?>
|