Wire up remaining TODO stubs: P3 test notifications, P2 drift notification trigger

- P3: test notification endpoint now instantiates real Slack/Email/Webhook notifiers
- P2: drift processor triggers notification service when drift_score > 0 (non-fatal on failure)
This commit is contained in:
2026-03-01 04:14:26 +00:00
parent b10e88e14d
commit e1b22e5309
2 changed files with 45 additions and 5 deletions

View File

@@ -50,8 +50,35 @@ export function registerNotificationRoutes(app: FastifyInstance) {
const { channel } = req.params as { channel: string };
const tenantId = (req as any).tenantId;
// TODO: Send test notification via the configured channel
logger.info({ tenantId, channel }, 'Test notification sent');
return { status: 'sent', channel };
const configResult = await withTenant(tenantId, async (client) => {
return client.query('SELECT * FROM notification_configs WHERE channel = $1', [channel]);
});
const cfg = configResult.rows[0];
if (!cfg) return reply.status(404).send({ error: `No ${channel} config found` });
const { SlackNotifier, EmailNotifier, WebhookNotifier } = await import('../notifications/dispatcher.js');
const testIncident = {
incidentId: 'test-000',
title: '[TEST] dd0c/alert notification test',
severity: 'info',
service: 'test-service',
alertCount: 1,
firstAlertAt: new Date(),
fingerprint: 'test',
dashboardUrl: `https://alert.dd0c.dev/incidents/test-000`,
};
let sent = false;
if (channel === 'slack' && cfg.config?.slack_webhook_url) {
sent = await new SlackNotifier(cfg.config.slack_webhook_url).send(testIncident);
} else if (channel === 'email' && cfg.config?.email_to) {
sent = await new EmailNotifier(process.env.RESEND_API_KEY ?? '', 'alerts@dd0c.dev', cfg.config.email_to).send(testIncident);
} else if (channel === 'webhook' && cfg.config?.webhook_url) {
sent = await new WebhookNotifier(cfg.config.webhook_url).send(testIncident);
}
logger.info({ tenantId, channel, sent }, 'Test notification sent');
return { status: sent ? 'sent' : 'failed', channel };
});
}