Skip to content

Commit 00162ee

Browse files
committed
feat: Enable Slack notifications for alerts and CI/CD deployment status.
1 parent 428ef47 commit 00162ee

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

.github/workflows/ci-cd.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,15 @@ jobs:
560560
-H "Content-Type: application/json" \
561561
-d "{\"from\":\"alerts@codeunia.com\",\"to\":[\"connect@codeunia.com\"],\"subject\":\"🚀 Production Deployment Successful\",\"html\":\"<h2>Production Deployment Successful</h2><p>Your Codeunia application has been successfully deployed to production.</p><p><strong>Deployment URL:</strong> <a href='${{ steps.deploy-production.outputs.deployment-url }}'>${{ steps.deploy-production.outputs.deployment-url }}</a></p><p><strong>Branch:</strong> ${{ github.ref_name }}</p><p><strong>Commit:</strong> ${{ github.sha }}</p><p><strong>Deployed by:</strong> ${{ github.actor }}</p>\"}"
562562
563+
- name: Notify deployment success via Slack
564+
if: success()
565+
run: |
566+
if [ -n "${{ secrets.SLACK_WEBHOOK_URL }}" ]; then
567+
curl -X POST -H 'Content-type: application/json' --data '{"text":"🚀 *Production Deployment Successful*\nURL: ${{ steps.deploy-production.outputs.deployment-url }}\nBranch: ${{ github.ref_name }}\nDeployed by: ${{ github.actor }}"}' ${{ secrets.SLACK_WEBHOOK_URL }}
568+
else
569+
echo "SLACK_WEBHOOK_URL not set, skipping Slack notification"
570+
fi
571+
563572
# Rollback on Failure
564573
rollback:
565574
name: Rollback on Failure
@@ -596,6 +605,14 @@ jobs:
596605
-H "Content-Type: application/json" \
597606
-d "{\"from\":\"alerts@codeunia.com\",\"to\":[\"connect@codeunia.com\"],\"subject\":\"⚠️ Production Deployment Failed - Rollback Initiated\",\"html\":\"<h2>Production Deployment Failed</h2><p>Your Codeunia application deployment failed and rollback has been initiated.</p><p><strong>Branch:</strong> ${{ github.ref_name }}</p><p><strong>Commit:</strong> ${{ github.sha }}</p><p><strong>Failed by:</strong> ${{ github.actor }}</p><p><strong>Action:</strong> Please check the deployment logs and fix the issues.</p>\"}"
598607
608+
- name: Notify rollback via Slack
609+
run: |
610+
if [ -n "${{ secrets.SLACK_WEBHOOK_URL }}" ]; then
611+
curl -X POST -H 'Content-type: application/json' --data '{"text":"⚠️ *Production Deployment Failed - Rollback Initiated*\nBranch: ${{ github.ref_name }}\nFailed by: ${{ github.actor }}\nCheck logs for details."}' ${{ secrets.SLACK_WEBHOOK_URL }}
612+
else
613+
echo "SLACK_WEBHOOK_URL not set, skipping Slack notification"
614+
fi
615+
599616
# Performance Monitoring
600617
performance:
601618
name: Performance Monitoring

lib/monitoring/alerting.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ export class MonitoringAlerting {
6868
* Initialize alert channels based on configuration
6969
*/
7070
private initializeAlertChannels(): void {
71-
// Only use email alerts for now - disable Slack and Discord
72-
// if (this.alertConfig.slack_webhook) {
73-
// this.alertChannels.push({
74-
// type: 'slack',
75-
// config: { webhook_url: this.alertConfig.slack_webhook },
76-
// enabled: false // Disabled as requested
77-
// });
78-
// }
71+
// Slack integration enabled
72+
if (this.alertConfig.slack_webhook) {
73+
this.alertChannels.push({
74+
type: 'slack',
75+
config: { webhook_url: this.alertConfig.slack_webhook },
76+
enabled: true
77+
});
78+
}
7979

8080
// if (this.alertConfig.discord_webhook) {
8181
// this.alertChannels.push({
@@ -94,10 +94,10 @@ export class MonitoringAlerting {
9494
}
9595

9696
// Always enable email alerts with the default recipient
97-
const emailRecipients = this.alertConfig.email_recipients && this.alertConfig.email_recipients.length > 0
98-
? this.alertConfig.email_recipients
97+
const emailRecipients = this.alertConfig.email_recipients && this.alertConfig.email_recipients.length > 0
98+
? this.alertConfig.email_recipients
9999
: ['connect@codeunia.com'];
100-
100+
101101
this.alertChannels.push({
102102
type: 'email',
103103
config: { recipients: emailRecipients },
@@ -158,7 +158,7 @@ export class MonitoringAlerting {
158158
}
159159

160160
// Check for high response times
161-
const slowServices = results.checks.filter(check =>
161+
const slowServices = results.checks.filter(check =>
162162
check.responseTime > this.alertConfig.alert_thresholds.response_time_ms
163163
);
164164
for (const service of slowServices) {
@@ -273,7 +273,7 @@ export class MonitoringAlerting {
273273
}
274274
})
275275
}
276-
276+
277277
if (process.env.NODE_ENV === 'development') {
278278
console.log(`[ALERTING] ${success ? 'SUCCESS' : 'FAILED'} - ${channelType}:`, logEntry)
279279
} else {
@@ -462,7 +462,7 @@ export class MonitoringAlerting {
462462
*/
463463
private async sendEmailAlert(alert: Alert, config: Record<string, unknown>): Promise<void> {
464464
const emailRecipients = (config.emailRecipients as string) || process.env.ALERT_EMAIL_RECIPIENTS || 'connect@codeunia.com';
465-
465+
466466
const emailContent = {
467467
subject: `[${alert.severity.toUpperCase()}] ${alert.title}`,
468468
html: `
@@ -520,15 +520,15 @@ Codeunia Monitoring System
520520
if (process.env.RESEND_API_KEY) {
521521
const { Resend } = await import('resend');
522522
const resend = new Resend(process.env.RESEND_API_KEY);
523-
523+
524524
await resend.emails.send({
525525
from: 'alerts@codeunia.com',
526526
to: emailRecipients,
527527
subject: emailContent.subject,
528528
html: emailContent.html,
529529
text: emailContent.text
530530
});
531-
531+
532532
console.log(`📧 Email alert sent to ${emailRecipients}: ${alert.title}`);
533533
} else {
534534
// Fallback to console log if Resend is not configured

0 commit comments

Comments
 (0)