Skip to content

Commit

Permalink
Merge pull request #145 from jkaninda/develop
Browse files Browse the repository at this point in the history
chore: update notification template
  • Loading branch information
jkaninda authored Dec 7, 2024
2 parents 05003b3 + 5cca957 commit 6f854d5
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 35 deletions.
3 changes: 3 additions & 0 deletions pkg/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func deleteTemp() {
func testDatabaseConnection(db *dbConfig) {

utils.Info("Connecting to %s database ...", db.dbName)
// Set database name for notification error
utils.DatabaseName = db.dbName

// Test database connection
query := "SELECT version();"

Expand Down
75 changes: 63 additions & 12 deletions templates/email-error.tmpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<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>
<body>
<h2>Hi,</h2>
<p>An error occurred during database backup.</p>
<h3>Failure Details:</h3>
<ul>
<li>Error Message: {{.Error}}</li>
<li>Date: {{.EndTime}}</li>
<li>Backup Reference: {{.BackupReference}} </li>
</ul>
<p>©2024 <a href="https://github.com/jkaninda/pg-bkup">pg-bkup</a></p>
<h2>🔴 Urgent: Database Backup Failure Notification</h2>
<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>
<ul>
<li><strong>Database Name:</strong> {{.DatabaseName}}</li>
<li><strong>Error Message:</strong> {{.Error}}</li>
<li><strong>Date:</strong> {{.EndTime}}</li>
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
</ul>
</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>
</html>
</html>
81 changes: 64 additions & 17 deletions templates/email.tmpl
Original file line number Diff line number Diff line change
@@ -1,23 +1,70 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<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>
<body>
<h2>Hi,</h2>
<p>Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}.</p>
<h3>Backup Details:</h3>
<ul>
<li>Database Name: {{.Database}}</li>
<li>Backup Start Time: {{.StartTime}}</li>
<li>Backup End Time: {{.EndTime}}</li>
<li>Backup Storage: {{.Storage}}</li>
<li>Backup Location: {{.BackupLocation}}</li>
<li>Backup Size: {{.BackupSize}} bytes</li>
<li>Backup Reference: {{.BackupReference}} </li>
</ul>
<p>Best regards,</p>
<p>©2024 <a href="https://github.com/jkaninda/pg-bkup">pg-bkup</a></p>
<h2>✅ Database Backup Successful</h2>
<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>
<ul>
<li><strong>Database Name:</strong> {{.Database}}</li>
<li><strong>Backup Start Time:</strong> {{.StartTime}}</li>
<li><strong>Backup End Time:</strong> {{.EndTime}}</li>
<li><strong>Backup Storage:</strong> {{.Storage}}</li>
<li><strong>Backup Location:</strong> {{.BackupLocation}}</li>
<li><strong>Backup Size:</strong> {{.BackupSize}} bytes</li>
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
</ul>
</div>

<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>
</html>
</html>
9 changes: 6 additions & 3 deletions templates/telegram-error.tmpl
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 7 additions & 3 deletions templates/telegram.tmpl
Original file line number Diff line number Diff line change
@@ -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}}
Expand All @@ -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.
3 changes: 3 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ErrorMessage struct {
EndTime string
Error string
BackupReference string
DatabaseName string
}

// loadMailConfig gets mail environment variables and returns MailConfig
Expand Down Expand Up @@ -81,3 +82,5 @@ func backupReference() string {
}

const templatePath = "/config/templates"

var DatabaseName = ""
2 changes: 2 additions & 0 deletions utils/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 6f854d5

Please sign in to comment.