Files
2026-10-30 16:35:46 +02:00

472 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings — DB Monitor</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/css/style.css">
<style>
.settings-container {
max-width: 900px;
margin: 40px auto;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
backdrop-filter: blur(12px);
overflow: hidden;
}
.settings-header {
display: flex;
align-items: center;
padding: 24px 32px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.settings-header h2 {
font-size: 1.25rem;
display: flex;
align-items: center;
gap: 12px;
}
.settings-header h2 svg {
color: var(--accent);
}
.back-btn {
display: flex;
align-items: center;
gap: 8px;
color: var(--text-muted);
text-decoration: none;
font-size: 0.9rem;
font-weight: 500;
margin-right: auto;
transition: color 0.2s;
}
.back-btn:hover {
color: var(--accent-light);
}
/* Tabs */
.tabs {
display: flex;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
background: rgba(0, 0, 0, 0.2);
}
.tab-btn {
padding: 16px 32px;
background: none;
border: none;
color: var(--text-muted);
font-family: var(--font);
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
border-bottom: 2px solid transparent;
transition: all 0.2s;
}
.tab-btn:hover {
color: var(--text-primary);
}
.tab-btn.active {
color: var(--accent-light);
border-bottom-color: var(--accent);
background: rgba(99, 102, 241, 0.05);
}
/* Content panels */
.tab-content {
display: none;
padding: 32px;
}
.tab-content.active {
display: block;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Forms & Inputs */
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
font-size: 0.85rem;
font-weight: 500;
color: var(--text-secondary);
margin-bottom: 8px;
}
.form-control {
width: 100%;
background: var(--bg-secondary);
border: 1px solid var(--border);
color: var(--text-primary);
padding: 12px 16px;
border-radius: 8px;
font-family: var(--font);
font-size: 0.9rem;
transition: all 0.2s;
}
.form-control:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-row {
display: flex;
gap: 16px;
}
.form-row .form-group {
flex: 1;
}
/* Buttons */
.btn {
background: var(--bg-secondary);
color: var(--text-primary);
border: 1px solid var(--border);
padding: 10px 20px;
border-radius: 8px;
font-family: var(--font);
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: inline-flex;
align-items: center;
gap: 8px;
justify-content: center;
}
.btn:hover {
border-color: var(--text-muted);
background: rgba(255, 255, 255, 0.05);
}
.btn-primary {
background: var(--accent);
color: white;
border-color: transparent;
}
.btn-primary:hover {
background: var(--accent-light);
box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-danger {
background: rgba(239, 68, 68, 0.1);
color: var(--red);
border-color: transparent;
}
.btn-danger:hover {
background: var(--red);
color: white;
box-shadow: 0 2px 10px var(--red-glow);
}
/* Lists / Tables */
.item-list {
margin-top: 32px;
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 8px;
overflow: hidden;
}
.item-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
background: rgba(255, 255, 255, 0.01);
}
.item-row:last-child {
border-bottom: none;
}
.item-info {
flex: 1;
}
.item-title {
font-weight: 600;
font-size: 0.95rem;
margin-bottom: 4px;
}
.item-subtitle {
font-size: 0.8rem;
color: var(--text-muted);
font-family: monospace;
}
.rule-badge {
background: rgba(255, 255, 255, 0.1);
padding: 2px 8px;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 600;
color: var(--accent-light);
margin-right: 8px;
}
.empty-message {
padding: 32px;
text-align: center;
color: var(--text-muted);
font-style: italic;
}
/* Toggle switch */
.switch {
position: relative;
display: inline-block;
width: 44px;
height: 24px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(255, 255, 255, 0.1);
transition: .3s;
border-radius: 24px;
}
.slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .3s;
border-radius: 50%;
}
input:checked+.slider {
background-color: var(--accent);
box-shadow: 0 0 8px var(--accent-glow);
}
input:checked+.slider:before {
transform: translateX(20px);
}
/* Status message */
#status-msg {
display: none;
padding: 12px 16px;
border-radius: 8px;
margin-bottom: 20px;
font-size: 0.9rem;
font-weight: 500;
}
#status-msg.success {
display: block;
background: rgba(16, 185, 129, 0.15);
color: var(--green);
border: 1px solid rgba(16, 185, 129, 0.3);
}
#status-msg.error {
display: block;
background: rgba(239, 68, 68, 0.15);
color: var(--red);
border: 1px solid rgba(239, 68, 68, 0.3);
}
</style>
</head>
<body>
<div class="settings-container">
<div class="settings-header">
<a href="/" class="back-btn">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round">
<line x1="19" y1="12" x2="5" y2="12"></line>
<polyline points="12 19 5 12 12 5"></polyline>
</svg>
Dashboard
</a>
<h2>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3" />
<path
d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
</svg>
Settings
</h2>
</div>
<div class="tabs">
<button class="tab-btn active" data-target="tab-dbs">Databases</button>
<button class="tab-btn" data-target="tab-alerts">Alert Rules</button>
<button class="tab-btn" data-target="tab-notifications">Notifications</button>
</div>
<div id="status-msg"></div>
<!-- ================= DATABASES TAB ================= -->
<div id="tab-dbs" class="tab-content active">
<h3>Add Monitored Database</h3>
<p style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 20px;">
Enter a PostgreSQL connection string (DSN) to start monitoring a new database. It will immediately
appear on the dashboard.
</p>
<form id="form-add-db">
<div class="form-group">
<label>Connection String (DSN)</label>
<input type="text" id="db-dsn" class="form-control"
placeholder="postgresql://user:pass@host:5432/dbname" required>
</div>
<div style="display: flex; gap: 12px;">
<button type="button" id="btn-test-db" class="btn">Test Connection</button>
<button type="submit" class="btn btn-primary">Add Database</button>
</div>
</form>
<div class="item-list" id="list-dbs">
<div class="empty-message">Loading databases...</div>
</div>
</div>
<!-- ================= ALERT RULES TAB ================= -->
<div id="tab-alerts" class="tab-content">
<h3>Custom Alert Rules</h3>
<p style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 20px;">
Define thresholds for any metric. If a rule triggers, a notification will be sent (if configured).
The built-in "DOWN" alert is always active.
</p>
<form id="form-add-alert">
<div class="form-row">
<div class="form-group" style="flex: 1.5;">
<label>Database</label>
<select id="alert-db" class="form-control">
<option value="">All Databases</option>
</select>
</div>
<div class="form-group" style="flex: 2;">
<label>Metric</label>
<select id="alert-metric" class="form-control" required>
<option value="latency_ms">Latency (ms)</option>
<option value="connection_usage_pct">Connection Usage (%)</option>
<option value="cache_hit_ratio">Cache Hit Ratio (%)</option>
<option value="active_locks">Active Locks</option>
<option value="waiting_locks">Waiting Locks</option>
<option value="deadlocks">Deadlocks</option>
<option value="long_running_queries">Long Running Queries (>5m)</option>
<option value="replication_lag_ms">Replication Lag (ms)</option>
</select>
</div>
<div class="form-group" style="flex: 1;">
<label>Operator</label>
<select id="alert-op" class="form-control">
<option value=">">&gt; (Greater than)</option>
<option value="<">&lt; (Less than)</option>
<option value="==">== (Equal to)</option>
</select>
</div>
<div class="form-group" style="flex: 1.5;">
<label>Threshold</label>
<input type="number" id="alert-val" class="form-control" step="0.1" required>
</div>
</div>
<button type="submit" class="btn btn-primary">Add Rule</button>
</form>
<div class="item-list" id="list-alerts">
<div class="empty-message">Loading rules...</div>
</div>
</div>
<!-- ================= NOTIFICATIONS TAB ================= -->
<div id="tab-notifications" class="tab-content">
<h3>Telegram Integration</h3>
<p style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 20px;">
Configure a Telegram bot to receive alerts in a group or direct chat. Ensure the bot is added to your
target chat.
</p>
<form id="form-telegram">
<div class="form-group">
<label>Bot Token</label>
<input type="password" id="tg-token" class="form-control"
placeholder="123456789:ABCdefGHIjklmNOPQrsTUVwxyZ">
</div>
<div class="form-group">
<label>Chat ID</label>
<input type="text" id="tg-chat" class="form-control" placeholder="-1001234567890">
</div>
<div class="form-group" style="display: flex; align-items: center; gap: 12px; margin-bottom: 24px;">
<label class="switch">
<input type="checkbox" id="tg-enabled" checked>
<span class="slider"></span>
</label>
<span style="font-size: 0.9rem; color: var(--text-secondary);">Enable Telegram Alerts</span>
</div>
<div style="display: flex; gap: 12px;">
<button type="button" id="btn-test-tg" class="btn">Send Test Message</button>
<button type="submit" class="btn btn-primary">Save Configuration</button>
</div>
</form>
<hr style="border: 0; border-top: 1px solid rgba(255,255,255,0.05); margin: 32px 0;">
<h3>Slack Integration</h3>
<div
style="padding: 20px; background: rgba(0,0,0,0.2); border-radius: 8px; border: 1px dashed var(--border); text-align: center; color: var(--text-muted);">
<p>Slack Webhook support is currently documented for future implementation.</p>
</div>
</div>
</div>
<script src="/js/settings.js"></script>
</body>
</html>