From 81437e682232fb5b9d2be5f4ba4a4b7e79d72a35 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 16 Nov 2023 13:49:08 +0100 Subject: [PATCH] Fix high disk usage notification bug in ServerStatusJob.php and HighDiskUsage.php --- app/Jobs/ServerStatusJob.php | 6 ++++-- app/Notifications/Server/HighDiskUsage.php | 7 ++----- resources/views/emails/high-disk-usage.blade.php | 6 ++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/Jobs/ServerStatusJob.php b/app/Jobs/ServerStatusJob.php index 1d9c4a682..d3599049d 100644 --- a/app/Jobs/ServerStatusJob.php +++ b/app/Jobs/ServerStatusJob.php @@ -33,11 +33,13 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted { ray("checking server status for {$this->server->id}"); try { - $this->server->checkServerRediness(); $disk_usage = $this->server->getDiskUsage(); - ray($this->server->settings->cleanup_after_percentage); if ($disk_usage >= $this->server->settings->cleanup_after_percentage) { + if ($this->server->high_disk_usage_notification_sent) { + ray('high disk usage notification already sent'); + return; + } $this->server->high_disk_usage_notification_sent = true; $this->server->save(); $this->server->team->notify(new HighDiskUsage($this->server, $disk_usage, $this->server->settings->cleanup_after_percentage)); diff --git a/app/Notifications/Server/HighDiskUsage.php b/app/Notifications/Server/HighDiskUsage.php index e638bc6c9..d23a2a0a4 100644 --- a/app/Notifications/Server/HighDiskUsage.php +++ b/app/Notifications/Server/HighDiskUsage.php @@ -18,9 +18,6 @@ class HighDiskUsage extends Notification implements ShouldQueue public $tries = 1; public function __construct(public Server $server, public int $disk_usage, public int $cleanup_after_percentage) { - if ($this->server->high_disk_usage_notification_sent === false) { - return; - } } public function via(object $notifiable): array @@ -56,13 +53,13 @@ class HighDiskUsage extends Notification implements ShouldQueue public function toDiscord(): string { - $message = "Coolify: Server '{$this->server->name}' high disk usage detected! \nDisk usage: {$this->disk_usage}"; + $message = "Coolify: Server '{$this->server->name}' high disk usage detected! \nDisk usage: {$this->disk_usage}. Please cleanup your disk to prevent data-loss. Here are some tips: https://coolify.io/docs/automated-cleanup."; return $message; } public function toTelegram(): array { return [ - "message" => "Coolify: Server '{$this->server->name}' high disk usage detected! \n Disk usage: {$this->disk_usage}" + "message" => "Coolify: Server '{$this->server->name}' high disk usage detected! \n Disk usage: {$this->disk_usage}. Please cleanup your disk to prevent data-loss. Here are some tips: https://coolify.io/docs/automated-cleanup." ]; } } diff --git a/resources/views/emails/high-disk-usage.blade.php b/resources/views/emails/high-disk-usage.blade.php index cff1590db..0a4baa300 100644 --- a/resources/views/emails/high-disk-usage.blade.php +++ b/resources/views/emails/high-disk-usage.blade.php @@ -1,7 +1,9 @@ -Your server ({{ $name }}) has high disk usage ({{ $disk_usage }}%). +Your server ({{ $name }}) has high disk usage ({{ $disk_usage }}% used). Threshold is {{ $threshold }}%. -Threshold is {{ $threshold }}% (you can change it in the Server Settings menu). +Please cleanup your disk to prevent data-loss. Here are some [tips](https://coolify.io/docs/automated-cleanup). + +(You can change the threshold in the Server Settings menu.)