From 00162eecd81cc44c95c6c61b5d577dad91efd760 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 12 Dec 2025 12:14:07 +0530 Subject: [PATCH] feat: Enable Slack notifications for alerts and CI/CD deployment status. --- .github/workflows/ci-cd.yml | 17 +++++++++++++++++ lib/monitoring/alerting.ts | 32 ++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 9f15cca5f..aefbf1879 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -560,6 +560,15 @@ jobs: -H "Content-Type: application/json" \ -d "{\"from\":\"alerts@codeunia.com\",\"to\":[\"connect@codeunia.com\"],\"subject\":\"🚀 Production Deployment Successful\",\"html\":\"

Production Deployment Successful

Your Codeunia application has been successfully deployed to production.

Deployment URL: ${{ steps.deploy-production.outputs.deployment-url }}

Branch: ${{ github.ref_name }}

Commit: ${{ github.sha }}

Deployed by: ${{ github.actor }}

\"}" + - name: Notify deployment success via Slack + if: success() + run: | + if [ -n "${{ secrets.SLACK_WEBHOOK_URL }}" ]; then + 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 }} + else + echo "SLACK_WEBHOOK_URL not set, skipping Slack notification" + fi + # Rollback on Failure rollback: name: Rollback on Failure @@ -596,6 +605,14 @@ jobs: -H "Content-Type: application/json" \ -d "{\"from\":\"alerts@codeunia.com\",\"to\":[\"connect@codeunia.com\"],\"subject\":\"⚠️ Production Deployment Failed - Rollback Initiated\",\"html\":\"

Production Deployment Failed

Your Codeunia application deployment failed and rollback has been initiated.

Branch: ${{ github.ref_name }}

Commit: ${{ github.sha }}

Failed by: ${{ github.actor }}

Action: Please check the deployment logs and fix the issues.

\"}" + - name: Notify rollback via Slack + run: | + if [ -n "${{ secrets.SLACK_WEBHOOK_URL }}" ]; then + 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 }} + else + echo "SLACK_WEBHOOK_URL not set, skipping Slack notification" + fi + # Performance Monitoring performance: name: Performance Monitoring diff --git a/lib/monitoring/alerting.ts b/lib/monitoring/alerting.ts index 2c0430635..826dd6eed 100644 --- a/lib/monitoring/alerting.ts +++ b/lib/monitoring/alerting.ts @@ -68,14 +68,14 @@ export class MonitoringAlerting { * Initialize alert channels based on configuration */ private initializeAlertChannels(): void { - // Only use email alerts for now - disable Slack and Discord - // if (this.alertConfig.slack_webhook) { - // this.alertChannels.push({ - // type: 'slack', - // config: { webhook_url: this.alertConfig.slack_webhook }, - // enabled: false // Disabled as requested - // }); - // } + // Slack integration enabled + if (this.alertConfig.slack_webhook) { + this.alertChannels.push({ + type: 'slack', + config: { webhook_url: this.alertConfig.slack_webhook }, + enabled: true + }); + } // if (this.alertConfig.discord_webhook) { // this.alertChannels.push({ @@ -94,10 +94,10 @@ export class MonitoringAlerting { } // Always enable email alerts with the default recipient - const emailRecipients = this.alertConfig.email_recipients && this.alertConfig.email_recipients.length > 0 - ? this.alertConfig.email_recipients + const emailRecipients = this.alertConfig.email_recipients && this.alertConfig.email_recipients.length > 0 + ? this.alertConfig.email_recipients : ['connect@codeunia.com']; - + this.alertChannels.push({ type: 'email', config: { recipients: emailRecipients }, @@ -158,7 +158,7 @@ export class MonitoringAlerting { } // Check for high response times - const slowServices = results.checks.filter(check => + const slowServices = results.checks.filter(check => check.responseTime > this.alertConfig.alert_thresholds.response_time_ms ); for (const service of slowServices) { @@ -273,7 +273,7 @@ export class MonitoringAlerting { } }) } - + if (process.env.NODE_ENV === 'development') { console.log(`[ALERTING] ${success ? 'SUCCESS' : 'FAILED'} - ${channelType}:`, logEntry) } else { @@ -462,7 +462,7 @@ export class MonitoringAlerting { */ private async sendEmailAlert(alert: Alert, config: Record): Promise { const emailRecipients = (config.emailRecipients as string) || process.env.ALERT_EMAIL_RECIPIENTS || 'connect@codeunia.com'; - + const emailContent = { subject: `[${alert.severity.toUpperCase()}] ${alert.title}`, html: ` @@ -520,7 +520,7 @@ Codeunia Monitoring System if (process.env.RESEND_API_KEY) { const { Resend } = await import('resend'); const resend = new Resend(process.env.RESEND_API_KEY); - + await resend.emails.send({ from: 'alerts@codeunia.com', to: emailRecipients, @@ -528,7 +528,7 @@ Codeunia Monitoring System html: emailContent.html, text: emailContent.text }); - + console.log(`📧 Email alert sent to ${emailRecipients}: ${alert.title}`); } else { // Fallback to console log if Resend is not configured