Fix high disk usage notification bug in

ServerStatusJob.php and HighDiskUsage.php
This commit is contained in:
Andras Bacsai 2023-11-16 13:49:08 +01:00
parent 2fe429fe92
commit 81437e6822
3 changed files with 10 additions and 9 deletions

View File

@ -33,11 +33,13 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
{ {
ray("checking server status for {$this->server->id}"); ray("checking server status for {$this->server->id}");
try { try {
$this->server->checkServerRediness(); $this->server->checkServerRediness();
$disk_usage = $this->server->getDiskUsage(); $disk_usage = $this->server->getDiskUsage();
ray($this->server->settings->cleanup_after_percentage);
if ($disk_usage >= $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->high_disk_usage_notification_sent = true;
$this->server->save(); $this->server->save();
$this->server->team->notify(new HighDiskUsage($this->server, $disk_usage, $this->server->settings->cleanup_after_percentage)); $this->server->team->notify(new HighDiskUsage($this->server, $disk_usage, $this->server->settings->cleanup_after_percentage));

View File

@ -18,9 +18,6 @@ class HighDiskUsage extends Notification implements ShouldQueue
public $tries = 1; public $tries = 1;
public function __construct(public Server $server, public int $disk_usage, public int $cleanup_after_percentage) 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 public function via(object $notifiable): array
@ -56,13 +53,13 @@ class HighDiskUsage extends Notification implements ShouldQueue
public function toDiscord(): string 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; return $message;
} }
public function toTelegram(): array public function toTelegram(): array
{ {
return [ 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."
]; ];
} }
} }

View File

@ -1,7 +1,9 @@
<x-emails.layout> <x-emails.layout>
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.)
</x-emails.layout> </x-emails.layout>