feat: premium tier features — auto-backup scheduling, resource alerting, bundled workflows, one-click revert, notification manager
This commit is contained in:
@@ -10,7 +10,7 @@ const { success } = require('../response-helpers');
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ resourceMonitor, docker, asyncHandler, log }) {
|
||||
module.exports = function({ resourceMonitor, docker, asyncHandler, log, notificationManager }) {
|
||||
const router = express.Router();
|
||||
|
||||
// ===== RESOURCE MONITORING ENDPOINTS =====
|
||||
@@ -66,7 +66,86 @@ module.exports = function({ resourceMonitor, docker, asyncHandler, log }) {
|
||||
success(res, { aggregated, hours });
|
||||
}, 'monitoring-aggregated'));
|
||||
|
||||
// Configure alerts
|
||||
// ===== ALERT CONFIGURATION (bulk) =====
|
||||
|
||||
// Get all alert configs
|
||||
router.get('/monitoring/alerts/config', asyncHandler(async (req, res) => {
|
||||
const configs = resourceMonitor.getAllAlertConfigs();
|
||||
success(res, { configs });
|
||||
}, 'monitoring-alerts-config-get'));
|
||||
|
||||
// Set all alert configs (bulk update)
|
||||
router.post('/monitoring/alerts/config', asyncHandler(async (req, res) => {
|
||||
const { configs } = req.body;
|
||||
if (!configs || typeof configs !== 'object') {
|
||||
const { ValidationError } = require('../errors');
|
||||
throw new ValidationError('configs object required');
|
||||
}
|
||||
for (const [containerId, config] of Object.entries(configs)) {
|
||||
resourceMonitor.setAlertConfig(containerId, config);
|
||||
}
|
||||
success(res, { message: 'Alert configurations saved' });
|
||||
}, 'monitoring-alerts-config-set'));
|
||||
|
||||
// Get alert history
|
||||
router.get('/monitoring/alerts', asyncHandler(async (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 50;
|
||||
const history = resourceMonitor.getAlertHistory(limit);
|
||||
success(res, { history });
|
||||
}, 'monitoring-alerts-history'));
|
||||
|
||||
// Send test alert notification for a container
|
||||
router.post('/monitoring/alerts/:containerId/test', asyncHandler(async (req, res) => {
|
||||
const { containerId } = req.params;
|
||||
|
||||
// Get container name from docker
|
||||
let containerName = containerId;
|
||||
try {
|
||||
const containers = await docker.client.listContainers({ all: false });
|
||||
const containerInfo = containers.find(c => c.Id === containerId || c.Id.startsWith(containerId));
|
||||
if (containerInfo) {
|
||||
containerName = containerInfo.Names[0]?.replace(/^\//, '') || containerId;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
const testAlert = {
|
||||
containerId,
|
||||
containerName,
|
||||
timestamp: new Date().toISOString(),
|
||||
alerts: [{
|
||||
type: 'test',
|
||||
severity: 'info',
|
||||
message: 'This is a test alert notification',
|
||||
value: 0,
|
||||
threshold: 0
|
||||
}],
|
||||
stats: null,
|
||||
config: resourceMonitor.getAlertConfig(containerId) || {}
|
||||
};
|
||||
|
||||
if (notificationManager) {
|
||||
await notificationManager.sendAlert(testAlert);
|
||||
}
|
||||
|
||||
// Also log to alert history
|
||||
resourceMonitor.addAlertHistoryEntry({
|
||||
id: `test-${Date.now()}`,
|
||||
timestamp: new Date().toISOString(),
|
||||
containerId,
|
||||
containerName,
|
||||
type: 'test',
|
||||
metric: 'test',
|
||||
value: 0,
|
||||
threshold: 0,
|
||||
severity: 'info',
|
||||
notified: true,
|
||||
autoRestartTriggered: false
|
||||
});
|
||||
|
||||
success(res, { message: 'Test alert sent', alert: testAlert });
|
||||
}, 'monitoring-alerts-test'));
|
||||
|
||||
// Configure alerts for a container
|
||||
router.post('/monitoring/alerts/:containerId', asyncHandler(async (req, res) => {
|
||||
resourceMonitor.setAlertConfig(req.params.containerId, req.body);
|
||||
success(res, { message: 'Alert configuration saved' });
|
||||
|
||||
Reference in New Issue
Block a user