From 2770755f9d7448a42f724ba1770c96c23e41176a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 25 Apr 2024 12:09:46 +0200 Subject: [PATCH] feat: add db name to backup notifications --- app/Models/StandaloneClickhouse.php | 3 +++ app/Models/StandaloneDragonfly.php | 3 +++ app/Models/StandaloneKeydb.php | 4 +++- app/Models/StandaloneMariadb.php | 3 +++ app/Models/StandaloneMongodb.php | 3 +++ app/Models/StandaloneMysql.php | 3 +++ app/Models/StandalonePostgresql.php | 3 +++ app/Models/StandaloneRedis.php | 3 +++ app/Notifications/Database/BackupFailed.php | 7 +++++-- app/Notifications/Database/BackupSuccess.php | 7 +++++-- resources/views/emails/backup-failed.blade.php | 2 +- resources/views/emails/backup-success.blade.php | 2 +- 12 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/Models/StandaloneClickhouse.php b/app/Models/StandaloneClickhouse.php index 2197d51df..3746a32f5 100644 --- a/app/Models/StandaloneClickhouse.php +++ b/app/Models/StandaloneClickhouse.php @@ -207,4 +207,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return $this->clickhouse_db; + } } diff --git a/app/Models/StandaloneDragonfly.php b/app/Models/StandaloneDragonfly.php index 7b18666b8..adc1ea6cc 100644 --- a/app/Models/StandaloneDragonfly.php +++ b/app/Models/StandaloneDragonfly.php @@ -207,4 +207,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return '0'; + } } diff --git a/app/Models/StandaloneKeydb.php b/app/Models/StandaloneKeydb.php index 1dc55228a..ff91322a0 100644 --- a/app/Models/StandaloneKeydb.php +++ b/app/Models/StandaloneKeydb.php @@ -208,5 +208,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } - + public function database_name() { + return '0'; + } } diff --git a/app/Models/StandaloneMariadb.php b/app/Models/StandaloneMariadb.php index 5e18bbfde..37d39f882 100644 --- a/app/Models/StandaloneMariadb.php +++ b/app/Models/StandaloneMariadb.php @@ -208,4 +208,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return $this->mariadb_database; + } } diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php index 8e4d327a3..5538efe1a 100644 --- a/app/Models/StandaloneMongodb.php +++ b/app/Models/StandaloneMongodb.php @@ -223,4 +223,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return $this->mongo_db; + } } diff --git a/app/Models/StandaloneMysql.php b/app/Models/StandaloneMysql.php index eede451d7..53e9b6f22 100644 --- a/app/Models/StandaloneMysql.php +++ b/app/Models/StandaloneMysql.php @@ -209,4 +209,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return $this->mysql_database; + } } diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index cf449a815..6435c49de 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -208,4 +208,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return $this->postgres_db; + } } diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php index da4701df9..de18c8c07 100644 --- a/app/Models/StandaloneRedis.php +++ b/app/Models/StandaloneRedis.php @@ -204,4 +204,7 @@ public function scheduledBackups() { return $this->morphMany(ScheduledDatabaseBackup::class, 'database'); } + public function database_name() { + return '0'; + } } diff --git a/app/Notifications/Database/BackupFailed.php b/app/Notifications/Database/BackupFailed.php index f149a9d06..3aa63ffd9 100644 --- a/app/Notifications/Database/BackupFailed.php +++ b/app/Notifications/Database/BackupFailed.php @@ -17,11 +17,13 @@ class BackupFailed extends Notification implements ShouldQueue public $tries = 1; public string $name; + public string $database_name; public string $frequency; public function __construct(ScheduledDatabaseBackup $backup, public $database, public $output) { $this->name = $database->name; + $this->database_name = $database->database_name(); $this->frequency = $backup->frequency; } @@ -36,6 +38,7 @@ public function toMail(): MailMessage $mail->subject("Coolify: [ACTION REQUIRED] Backup FAILED for {$this->database->name}"); $mail->view('emails.backup-failed', [ 'name' => $this->name, + 'database_name' => $this->database_name, 'frequency' => $this->frequency, 'output' => $this->output, ]); @@ -44,11 +47,11 @@ public function toMail(): MailMessage public function toDiscord(): string { - return "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}"; + return "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}"; } public function toTelegram(): array { - $message = "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}"; + $message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}"; return [ "message" => $message, ]; diff --git a/app/Notifications/Database/BackupSuccess.php b/app/Notifications/Database/BackupSuccess.php index bbe0bc6d3..9ca3234e1 100644 --- a/app/Notifications/Database/BackupSuccess.php +++ b/app/Notifications/Database/BackupSuccess.php @@ -14,11 +14,13 @@ class BackupSuccess extends Notification implements ShouldQueue public $tries = 1; public string $name; + public string $database_name; public string $frequency; public function __construct(ScheduledDatabaseBackup $backup, public $database) { $this->name = $database->name; + $this->database_name = $database->database_name(); $this->frequency = $backup->frequency; } @@ -33,6 +35,7 @@ public function toMail(): MailMessage $mail->subject("Coolify: Backup successfully done for {$this->database->name}"); $mail->view('emails.backup-success', [ 'name' => $this->name, + 'database_name' => $this->database_name, 'frequency' => $this->frequency, ]); return $mail; @@ -40,11 +43,11 @@ public function toMail(): MailMessage public function toDiscord(): string { - return "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was successful."; + return "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful."; } public function toTelegram(): array { - $message = "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was successful."; + $message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful."; return [ "message" => $message, ]; diff --git a/resources/views/emails/backup-failed.blade.php b/resources/views/emails/backup-failed.blade.php index de6a7c981..f50ff0c33 100644 --- a/resources/views/emails/backup-failed.blade.php +++ b/resources/views/emails/backup-failed.blade.php @@ -1,5 +1,5 @@ -Database backup for {{ $name }} with frequency of {{ $frequency }} was FAILED. +Database backup for {{ $name }} (db:{{$database_name}}) with frequency of {{ $frequency }} was FAILED. ### Reason diff --git a/resources/views/emails/backup-success.blade.php b/resources/views/emails/backup-success.blade.php index 0d54a254c..e48df9e6a 100644 --- a/resources/views/emails/backup-success.blade.php +++ b/resources/views/emails/backup-success.blade.php @@ -1,3 +1,3 @@ -Database backup for {{ $name }} with frequency of {{ $frequency }} was successful. +Database backup for {{ $name }} (db:{{ $database_name }}) with frequency of {{ $frequency }} was successful.