feat(maintenance): add maintenance_mode flag, API support, UI toggle; skip alerts during maintenance; rebuild client

This commit is contained in:
nmemmert committed 2025-12-15 16:35:52 -05:00
1 parent 2329362f09
commit 65fca3d3e3
9 files changed
+88 -16

No files matched your search

+10
View File
@@ -20,6 +20,7 @@ db.exec(`
check_interval INTEGER DEFAULT 60000,
timeout INTEGER DEFAULT 5000,
enabled INTEGER DEFAULT 1,
maintenance_mode INTEGER DEFAULT 0,
group_id INTEGER REFERENCES groups(id) ON DELETE SET NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
@@ -76,6 +77,15 @@ try {
// Column already exists
}
try {
db.prepare("ALTER TABLE resources ADD COLUMN maintenance_mode INTEGER DEFAULT 0").run();
console.log('[DB] Added maintenance_mode column to resources');
} catch (err) {
if (err.message.includes('duplicate')) {
console.log('[DB] maintenance_mode column already exists');
}
}
try {
db.prepare("ALTER TABLE resources ADD COLUMN http_keyword TEXT").run();
} catch (err) {}
+8 -6
View File
@@ -137,15 +137,15 @@ app.get('/api/resources/:id', (req, res) => {
// Create resource
app.post('/api/resources', (req, res) => {
const { name, url, type, check_interval, timeout, group_id, http_keyword, http_headers, quiet_hours_start, quiet_hours_end, cert_expiry_days, sla_target, email_to } = req.body;
const { name, url, type, check_interval, timeout, group_id, http_keyword, http_headers, quiet_hours_start, quiet_hours_end, cert_expiry_days, sla_target, email_to, maintenance_mode } = req.body;
if (!name || !url) {
return res.status(400).json({ error: 'Name and URL are required' });
}
const stmt = db.prepare(`
INSERT INTO resources (name, url, type, check_interval, timeout, group_id, http_keyword, http_headers, quiet_hours_start, quiet_hours_end, cert_expiry_days, sla_target, email_to)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO resources (name, url, type, check_interval, timeout, group_id, http_keyword, http_headers, quiet_hours_start, quiet_hours_end, cert_expiry_days, sla_target, email_to, maintenance_mode)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`);
const result = stmt.run(
@@ -161,7 +161,8 @@ app.post('/api/resources', (req, res) => {
quiet_hours_end || null,
cert_expiry_days || 30,
sla_target || 99.9,
email_to || null
email_to || null,
maintenance_mode ? 1 : 0
);
// Invalidate related cache entries
@@ -173,11 +174,11 @@ app.post('/api/resources', (req, res) => {
// Update resource
app.put('/api/resources/:id', (req, res) => {
const { name, url, type, check_interval, timeout, enabled, group_id, http_keyword, http_headers, quiet_hours_start, quiet_hours_end, cert_expiry_days, sla_target, email_to } = req.body;
const { name, url, type, check_interval, timeout, enabled, group_id, http_keyword, http_headers, quiet_hours_start, quiet_hours_end, cert_expiry_days, sla_target, email_to, maintenance_mode } = req.body;
const stmt = db.prepare(`
UPDATE resources
SET name = ?, url = ?, type = ?, check_interval = ?, timeout = ?, enabled = ?, group_id = ?, http_keyword = ?, http_headers = ?, quiet_hours_start = ?, quiet_hours_end = ?, cert_expiry_days = ?, sla_target = ?, email_to = ?
SET name = ?, url = ?, type = ?, check_interval = ?, timeout = ?, enabled = ?, group_id = ?, http_keyword = ?, http_headers = ?, quiet_hours_start = ?, quiet_hours_end = ?, cert_expiry_days = ?, sla_target = ?, email_to = ?, maintenance_mode = ?
WHERE id = ?
`);
@@ -196,6 +197,7 @@ app.put('/api/resources/:id', (req, res) => {
cert_expiry_days || 30,
sla_target || 99.9,
email_to || null,
maintenance_mode ? 1 : 0,
req.params.id
);
+5 -1
View File
@@ -49,7 +49,11 @@ class Scheduler {
LIMIT 12
`).all(resource.id);
stats.recentChecks = recentChecks.reverse();
await notificationService.sendAlert(resource, incident, stats);
if (resource.maintenance_mode) {
console.log(`Resource ${resource.name} in maintenance; skipping alert`);
} else {
await notificationService.sendAlert(resource, incident, stats);
}
}
console.log(`Checked ${resource.name}: ${result.status} (${result.response_time}ms)`);