From 8e58d7a4c3406016f5a4c2c8fc4501df49b60b02 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sat, 7 Dec 2024 17:36:05 +0100 Subject: [PATCH] chore: update notification template --- pkg/helper.go | 2 + templates/email-error.tmpl | 75 +++++++++++++++++++++++++++----- templates/email.tmpl | 82 +++++++++++++++++++++++++++-------- templates/telegram-error.tmpl | 9 ++-- templates/telegram.tmpl | 10 +++-- utils/config.go | 3 ++ utils/notification.go | 2 + 7 files changed, 147 insertions(+), 36 deletions(-) diff --git a/pkg/helper.go b/pkg/helper.go index d8db4ba..215c737 100644 --- a/pkg/helper.go +++ b/pkg/helper.go @@ -72,6 +72,8 @@ func testDatabaseConnection(db *dbConfig) { return } utils.Info("Connecting to %s database ...", db.dbName) + // Set database name for notification error + utils.DatabaseName = db.dbName cmd := exec.Command("mysql", "-h", db.dbHost, "-P", db.dbPort, "-u", db.dbUserName, db.dbName, "-e", "quit") // Capture the output var out bytes.Buffer diff --git a/templates/email-error.tmpl b/templates/email-error.tmpl index c71bb8f..6325baf 100644 --- a/templates/email-error.tmpl +++ b/templates/email-error.tmpl @@ -1,18 +1,69 @@ - + - 🔴 Urgent: Database Backup Failure Notification + + 🔴 Urgent: Database Backup Failure + -

Hi,

-

An error occurred during database backup.

-

Failure Details:

- -

©2024 mysql-bkup

+

🔴 Urgent: Database Backup Failure Notification

+

Dear Team,

+

An error occurred during the database backup process. Please review the details below and take the necessary actions:

+ +
+

Failure Details:

+ +
+ +

We recommend investigating the issue as soon as possible to prevent potential data loss or service disruptions.

+ +

For more information, visit the pg-bkup documentation.

+ + - \ No newline at end of file + diff --git a/templates/email.tmpl b/templates/email.tmpl index 0ec0866..2b10b4c 100644 --- a/templates/email.tmpl +++ b/templates/email.tmpl @@ -1,24 +1,70 @@ - + - ✅ Database Backup Notification – {{.Database}} + + ✅ Database Backup Successful – {{.Database}} + -

Hi,

-

Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}.

-

Backup Details:

- -

Best regards,

-

©2024 mysql-bkup

- +

✅ Database Backup Successful

+

Dear Team,

+

The backup process for the {{.Database}} database was successfully completed. Please find the details below:

+ +
+

Backup Details:

+
    +
  • Database Name: {{.Database}}
  • +
  • Backup Start Time: {{.StartTime}}
  • +
  • Backup End Time: {{.EndTime}}
  • +
  • Backup Storage: {{.Storage}}
  • +
  • Backup Location: {{.BackupLocation}}
  • +
  • Backup Size: {{.BackupSize}} bytes
  • +
  • Backup Reference: {{.BackupReference}}
  • +
+
+ +

You can access the backup at the specified location if needed. Thank you for using mysql-bkup.

+ + - \ No newline at end of file + diff --git a/templates/telegram-error.tmpl b/templates/telegram-error.tmpl index fc5336c..fddc706 100644 --- a/templates/telegram-error.tmpl +++ b/templates/telegram-error.tmpl @@ -1,8 +1,11 @@ 🔴 Urgent: Database Backup Failure Notification -Hi, -An error occurred during database backup. + +Dear Team, +An error occurred during the database backup process. +Please review the details below and take the necessary actions: Failure Details: +- Database Name: {{.DatabaseName}} - Date: {{.EndTime}} - Backup Reference: {{.BackupReference}} - Error Message: {{.Error}} - +We recommend investigating the issue as soon as possible to prevent potential data loss or service disruptions. \ No newline at end of file diff --git a/templates/telegram.tmpl b/templates/telegram.tmpl index c25e73d..6423ce7 100644 --- a/templates/telegram.tmpl +++ b/templates/telegram.tmpl @@ -1,6 +1,8 @@ -[✅ Database Backup Notification – {{.Database}} -Hi, -Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}. +✅ Database Backup Successful + +Dear Team, +The backup process for the {{.Database}} database was successfully completed. +Please find the details below: Backup Details: - Database Name: {{.Database}} @@ -10,3 +12,5 @@ Backup Details: - Backup Location: {{.BackupLocation}} - Backup Size: {{.BackupSize}} bytes - Backup Reference: {{.BackupReference}} + +You can access the backup at the specified location if needed. \ No newline at end of file diff --git a/utils/config.go b/utils/config.go index 0afb6a6..d111b01 100644 --- a/utils/config.go +++ b/utils/config.go @@ -50,6 +50,7 @@ type ErrorMessage struct { EndTime string Error string BackupReference string + DatabaseName string } // loadMailConfig gets mail environment variables and returns MailConfig @@ -81,3 +82,5 @@ func backupReference() string { } const templatePath = "/config/templates" + +var DatabaseName = "" diff --git a/utils/notification.go b/utils/notification.go index 538e10d..795c4d3 100644 --- a/utils/notification.go +++ b/utils/notification.go @@ -167,6 +167,7 @@ func NotifyError(error string) { Error: error, EndTime: time.Now().Format(TimeFormat()), BackupReference: os.Getenv("BACKUP_REFERENCE"), + DatabaseName: DatabaseName, }, "email-error.tmpl") if err != nil { Error("Could not parse error template: %v", err) @@ -183,6 +184,7 @@ func NotifyError(error string) { Error: error, EndTime: time.Now().Format(TimeFormat()), BackupReference: os.Getenv("BACKUP_REFERENCE"), + DatabaseName: DatabaseName, }, "telegram-error.tmpl") if err != nil { Error("Could not parse error template: %v", err)