Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,15 @@ jobs:
-H "Content-Type: application/json" \
-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>\"}"

- 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
Expand Down Expand Up @@ -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\":\"<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>\"}"

- 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
Expand Down
32 changes: 16 additions & 16 deletions lib/monitoring/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 },
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -273,7 +273,7 @@ export class MonitoringAlerting {
}
})
}

if (process.env.NODE_ENV === 'development') {
console.log(`[ALERTING] ${success ? 'SUCCESS' : 'FAILED'} - ${channelType}:`, logEntry)
} else {
Expand Down Expand Up @@ -462,7 +462,7 @@ export class MonitoringAlerting {
*/
private async sendEmailAlert(alert: Alert, config: Record<string, unknown>): Promise<void> {
const emailRecipients = (config.emailRecipients as string) || process.env.ALERT_EMAIL_RECIPIENTS || 'connect@codeunia.com';

const emailContent = {
subject: `[${alert.severity.toUpperCase()}] ${alert.title}`,
html: `
Expand Down Expand Up @@ -520,15 +520,15 @@ 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,
subject: emailContent.subject,
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
Expand Down
Loading