feat: add db name to backup notifications

This commit is contained in:
Andras Bacsai 2024-04-25 12:09:46 +02:00
parent ee69cdbf7b
commit 2770755f9d
12 changed files with 36 additions and 7 deletions

View File

@ -207,4 +207,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return $this->clickhouse_db;
}
}

View File

@ -207,4 +207,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return '0';
}
}

View File

@ -208,5 +208,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return '0';
}
}

View File

@ -208,4 +208,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return $this->mariadb_database;
}
}

View File

@ -223,4 +223,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return $this->mongo_db;
}
}

View File

@ -209,4 +209,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return $this->mysql_database;
}
}

View File

@ -208,4 +208,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return $this->postgres_db;
}
}

View File

@ -204,4 +204,7 @@ public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
public function database_name() {
return '0';
}
}

View File

@ -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,
];

View File

@ -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,
];

View File

@ -1,5 +1,5 @@
<x-emails.layout>
Database backup for {{ $name }} with frequency of {{ $frequency }} was FAILED.
Database backup for {{ $name }} (db:{{$database_name}}) with frequency of {{ $frequency }} was FAILED.
### Reason

View File

@ -1,3 +1,3 @@
<x-emails.layout>
Database backup for {{ $name }} with frequency of {{ $frequency }} was successful.
Database backup for {{ $name }} (db:{{ $database_name }}) with frequency of {{ $frequency }} was successful.
</x-emails.layout>