Merge pull request #145 from jkaninda/develop

chore: update notification template
This commit is contained in:
2024-12-07 18:00:53 +01:00
committed by GitHub
7 changed files with 148 additions and 35 deletions

View File

@@ -69,6 +69,9 @@ func deleteTemp() {
func testDatabaseConnection(db *dbConfig) { func testDatabaseConnection(db *dbConfig) {
utils.Info("Connecting to %s database ...", db.dbName) utils.Info("Connecting to %s database ...", db.dbName)
// Set database name for notification error
utils.DatabaseName = db.dbName
// Test database connection // Test database connection
query := "SELECT version();" query := "SELECT version();"

View File

@@ -1,18 +1,69 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>🔴 Urgent: Database Backup Failure Notification</title> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🔴 Urgent: Database Backup Failure</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
color: #333;
margin: 0;
padding: 20px;
}
h2 {
color: #d9534f;
}
.details {
background-color: #ffffff;
border: 1px solid #ddd;
padding: 15px;
border-radius: 5px;
margin-top: 10px;
}
.details ul {
list-style-type: none;
padding: 0;
}
.details li {
margin: 5px 0;
}
a {
color: #0275d8;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
footer {
margin-top: 20px;
font-size: 0.9em;
color: #6c757d;
}
</style>
</head> </head>
<body> <body>
<h2>Hi,</h2> <h2>🔴 Urgent: Database Backup Failure Notification</h2>
<p>An error occurred during database backup.</p> <p>Dear Team,</p>
<p>An error occurred during the database backup process. Please review the details below and take the necessary actions:</p>
<div class="details">
<h3>Failure Details:</h3> <h3>Failure Details:</h3>
<ul> <ul>
<li>Error Message: {{.Error}}</li> <li><strong>Database Name:</strong> {{.DatabaseName}}</li>
<li>Date: {{.EndTime}}</li> <li><strong>Error Message:</strong> {{.Error}}</li>
<li>Backup Reference: {{.BackupReference}} </li> <li><strong>Date:</strong> {{.EndTime}}</li>
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
</ul> </ul>
<p>©2024 <a href="https://github.com/jkaninda/pg-bkup">pg-bkup</a></p> </div>
<p>We recommend investigating the issue as soon as possible to prevent potential data loss or service disruptions.</p>
<p>For more information, visit the <a href="https://jkaninda.github.io/pg-bkup">pg-bkup documentation</a>.</p>
<footer>
&copy; 2024 <a href="https://github.com/jkaninda/pg-bkup">pg-bkup</a> | Automated Backup System
</footer>
</body> </body>
</html> </html>

View File

@@ -1,23 +1,70 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>✅ Database Backup Notification {{.Database}}</title> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>✅ Database Backup Successful {{.Database}}</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
color: #333;
margin: 0;
padding: 20px;
}
h2 {
color: #5cb85c;
}
.details {
background-color: #ffffff;
border: 1px solid #ddd;
padding: 15px;
border-radius: 5px;
margin-top: 10px;
}
.details ul {
list-style-type: none;
padding: 0;
}
.details li {
margin: 5px 0;
}
a {
color: #0275d8;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
footer {
margin-top: 20px;
font-size: 0.9em;
color: #6c757d;
}
</style>
</head> </head>
<body> <body>
<h2>Hi,</h2> <h2>✅ Database Backup Successful</h2>
<p>Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}.</p> <p>Dear Team,</p>
<p>The backup process for the <strong>{{.Database}}</strong> database was successfully completed. Please find the details below:</p>
<div class="details">
<h3>Backup Details:</h3> <h3>Backup Details:</h3>
<ul> <ul>
<li>Database Name: {{.Database}}</li> <li><strong>Database Name:</strong> {{.Database}}</li>
<li>Backup Start Time: {{.StartTime}}</li> <li><strong>Backup Start Time:</strong> {{.StartTime}}</li>
<li>Backup End Time: {{.EndTime}}</li> <li><strong>Backup End Time:</strong> {{.EndTime}}</li>
<li>Backup Storage: {{.Storage}}</li> <li><strong>Backup Storage:</strong> {{.Storage}}</li>
<li>Backup Location: {{.BackupLocation}}</li> <li><strong>Backup Location:</strong> {{.BackupLocation}}</li>
<li>Backup Size: {{.BackupSize}} bytes</li> <li><strong>Backup Size:</strong> {{.BackupSize}} bytes</li>
<li>Backup Reference: {{.BackupReference}} </li> <li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
</ul> </ul>
<p>Best regards,</p> </div>
<p>©2024 <a href="https://github.com/jkaninda/pg-bkup">pg-bkup</a></p>
<p>You can access the backup at the specified location if needed. Thank you for using <a href="https://jkaninda.github.io/pg-bkup/">pg-bkup</a>.</p>
<footer>
&copy; 2024 <a href="https://github.com/jkaninda/pg-bkup">pg-bkup</a> | Automated Backup System
</footer>
</body> </body>
</html> </html>

View File

@@ -1,8 +1,11 @@
🔴 Urgent: Database Backup Failure Notification 🔴 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: Failure Details:
- Database Name: {{.DatabaseName}}
- Date: {{.EndTime}} - Date: {{.EndTime}}
- Backup Reference: {{.BackupReference}} - Backup Reference: {{.BackupReference}}
- Error Message: {{.Error}} - Error Message: {{.Error}}
We recommend investigating the issue as soon as possible to prevent potential data loss or service disruptions.

View File

@@ -1,6 +1,8 @@
Database Backup Notification {{.Database}} ✅ Database Backup Successful
Hi,
Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}. Dear Team,
The backup process for the {{.Database}} database was successfully completed.
Please find the details below:
Backup Details: Backup Details:
- Database Name: {{.Database}} - Database Name: {{.Database}}
@@ -10,3 +12,5 @@ Backup Details:
- Backup Location: {{.BackupLocation}} - Backup Location: {{.BackupLocation}}
- Backup Size: {{.BackupSize}} bytes - Backup Size: {{.BackupSize}} bytes
- Backup Reference: {{.BackupReference}} - Backup Reference: {{.BackupReference}}
You can access the backup at the specified location if needed.

View File

@@ -50,6 +50,7 @@ type ErrorMessage struct {
EndTime string EndTime string
Error string Error string
BackupReference string BackupReference string
DatabaseName string
} }
// loadMailConfig gets mail environment variables and returns MailConfig // loadMailConfig gets mail environment variables and returns MailConfig
@@ -81,3 +82,5 @@ func backupReference() string {
} }
const templatePath = "/config/templates" const templatePath = "/config/templates"
var DatabaseName = ""

View File

@@ -167,6 +167,7 @@ func NotifyError(error string) {
Error: error, Error: error,
EndTime: time.Now().Format(TimeFormat()), EndTime: time.Now().Format(TimeFormat()),
BackupReference: os.Getenv("BACKUP_REFERENCE"), BackupReference: os.Getenv("BACKUP_REFERENCE"),
DatabaseName: DatabaseName,
}, "email-error.tmpl") }, "email-error.tmpl")
if err != nil { if err != nil {
Error("Could not parse error template: %v", err) Error("Could not parse error template: %v", err)
@@ -183,6 +184,7 @@ func NotifyError(error string) {
Error: error, Error: error,
EndTime: time.Now().Format(TimeFormat()), EndTime: time.Now().Format(TimeFormat()),
BackupReference: os.Getenv("BACKUP_REFERENCE"), BackupReference: os.Getenv("BACKUP_REFERENCE"),
DatabaseName: DatabaseName,
}, "telegram-error.tmpl") }, "telegram-error.tmpl")
if err != nil { if err != nil {
Error("Could not parse error template: %v", err) Error("Could not parse error template: %v", err)