An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: add notification settings to server_disk_usage
Andras Bacsai2e9ce3ed2a95
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.phpindex b837ebfc64..3c6c32aa7c 100644--- a/app/Console/Kernel.php+++ b/app/Console/Kernel.php@@ -116,10 +116,14 @@ class Kernel extends ConsoleKernel}foreach ($servers as $server) {$last_sentinel_update = $server->sentinel_updated_at;- if (Carbon::parse($last_sentinel_update)->isBefore(now()->subMinutes(4))) {+ $push_interval_seconds = $server->settings->sentinel_push_interval_seconds;+ $wait_before_doing_ssh_check = $push_interval_seconds * 3;+ if ($wait_before_doing_ssh_check < 120) {+ $wait_before_doing_ssh_check = 120;+ }+ if (Carbon::parse($last_sentinel_update)->isBefore(now()->subSeconds($wait_before_doing_ssh_check))) {$schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer();}- // $schedule->job(new ServerStorageCheckJob($server))->everyMinute()->onOneServer();$serverTimezone = $server->settings->server_timezone;if ($server->settings->force_docker_cleanup) {$schedule->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();diff --git a/app/Livewire/Notifications/Discord.php b/app/Livewire/Notifications/Discord.phpindex 65c202b7db..49666dabd0 100644--- a/app/Livewire/Notifications/Discord.php+++ b/app/Livewire/Notifications/Discord.php@@ -18,6 +18,7 @@ class Discord extends Component'team.discord_notifications_status_changes' => 'nullable|boolean','team.discord_notifications_database_backups' => 'nullable|boolean','team.discord_notifications_scheduled_tasks' => 'nullable|boolean',+ 'team.discord_notifications_server_disk_usage' => 'nullable|boolean',];protected $validationAttributes = [diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.phpindex acb1d69a22..08415731d7 100644--- a/app/Livewire/Notifications/Email.php+++ b/app/Livewire/Notifications/Email.php@@ -31,6 +31,7 @@ class Email extends Component'team.smtp_notifications_status_changes' => 'nullable|boolean','team.smtp_notifications_database_backups' => 'nullable|boolean','team.smtp_notifications_scheduled_tasks' => 'nullable|boolean',+ 'team.smtp_notifications_server_disk_usage' => 'nullable|boolean','team.use_instance_email_settings' => 'boolean','team.resend_enabled' => 'nullable|boolean','team.resend_api_key' => 'nullable',diff --git a/app/Livewire/Notifications/Telegram.php b/app/Livewire/Notifications/Telegram.phpindex e163a25e0d..a035df71c3 100644--- a/app/Livewire/Notifications/Telegram.php+++ b/app/Livewire/Notifications/Telegram.php@@ -24,6 +24,7 @@ class Telegram extends Component'team.telegram_notifications_status_changes_message_thread_id' => 'nullable|string','team.telegram_notifications_database_backups_message_thread_id' => 'nullable|string','team.telegram_notifications_scheduled_tasks_thread_id' => 'nullable|string',+ 'team.telegram_notifications_server_disk_usage' => 'nullable|boolean',];protected $validationAttributes = [diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 1eb7496c9f..50162a14cf 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -1275,4 +1275,8 @@ $schema://$host {loggy('Error restarting Sentinel: '.$e->getMessage());}}+ public function url()+ {+ return base_url().'/server/'.$this->uuid;+ }}diff --git a/app/Models/Team.php b/app/Models/Team.phpindex 3f8e97bc54..a0f99e5f81 100644--- a/app/Models/Team.php+++ b/app/Models/Team.php@@ -34,6 +34,7 @@ use OpenApi\Attributes as OA;'smtp_notifications_status_changes' => ['type' => 'boolean', 'description' => 'Whether to send status change notifications via SMTP.'],'smtp_notifications_scheduled_tasks' => ['type' => 'boolean', 'description' => 'Whether to send scheduled task notifications via SMTP.'],'smtp_notifications_database_backups' => ['type' => 'boolean', 'description' => 'Whether to send database backup notifications via SMTP.'],+ 'smtp_notifications_server_disk_usage' => ['type' => 'boolean', 'description' => 'Whether to send server disk usage notifications via SMTP.'],'discord_enabled' => ['type' => 'boolean', 'description' => 'Whether Discord is enabled or not.'],'discord_webhook_url' => ['type' => 'string', 'description' => 'The Discord webhook URL.'],'discord_notifications_test' => ['type' => 'boolean', 'description' => 'Whether to send test notifications via Discord.'],@@ -41,6 +42,7 @@ use OpenApi\Attributes as OA;'discord_notifications_status_changes' => ['type' => 'boolean', 'description' => 'Whether to send status change notifications via Discord.'],'discord_notifications_database_backups' => ['type' => 'boolean', 'description' => 'Whether to send database backup notifications via Discord.'],'discord_notifications_scheduled_tasks' => ['type' => 'boolean', 'description' => 'Whether to send scheduled task notifications via Discord.'],+ 'discord_notifications_server_disk_usage' => ['type' => 'boolean', 'description' => 'Whether to send server disk usage notifications via Discord.'],'show_boarding' => ['type' => 'boolean', 'description' => 'Whether to show the boarding screen or not.'],'resend_enabled' => ['type' => 'boolean', 'description' => 'Whether to enable resending or not.'],'resend_api_key' => ['type' => 'string', 'description' => 'The resending API key.'],@@ -56,6 +58,7 @@ use OpenApi\Attributes as OA;'telegram_notifications_deployments_message_thread_id' => ['type' => 'string', 'description' => 'The Telegram deployment message thread ID.'],'telegram_notifications_status_changes_message_thread_id' => ['type' => 'string', 'description' => 'The Telegram status change message thread ID.'],'telegram_notifications_database_backups_message_thread_id' => ['type' => 'string', 'description' => 'The Telegram database backup message thread ID.'],+'custom_server_limit' => ['type' => 'string', 'description' => 'The custom server limit.'],'telegram_notifications_scheduled_tasks' => ['type' => 'boolean', 'description' => 'Whether to send scheduled task notifications via Telegram.'],'telegram_notifications_scheduled_tasks_thread_id' => ['type' => 'string', 'description' => 'The Telegram scheduled task message thread ID.'],diff --git a/app/Notifications/Server/HighDiskUsage.php b/app/Notifications/Server/HighDiskUsage.phpindex 108eead9c7..3a01aabe4e 100644--- a/app/Notifications/Server/HighDiskUsage.php+++ b/app/Notifications/Server/HighDiskUsage.php@@ -22,22 +22,7 @@ class HighDiskUsage extends Notification implements ShouldQueuepublic function via(object $notifiable): array{- $channels = [];- $isEmailEnabled = isEmailEnabled($notifiable);- $isDiscordEnabled = data_get($notifiable, 'discord_enabled');- $isTelegramEnabled = data_get($notifiable, 'telegram_enabled');-- if ($isDiscordEnabled) {- $channels[] = DiscordChannel::class;- }- if ($isEmailEnabled) {- $channels[] = EmailChannel::class;- }- if ($isTelegramEnabled) {- $channels[] = TelegramChannel::class;- }-- return $channels;+ return setNotificationChannels($notifiable, 'server_disk_usage');}public function toMail(): MailMessage@@ -59,11 +44,13 @@ class HighDiskUsage extends Notification implements ShouldQueuetitle: ':cross_mark: High disk usage detected',description: "Server '{$this->server->name}' high disk usage detected!",color: DiscordMessage::errorColor(),+ isCritical: true,);- $message->addField('Disk usage', "{$this->disk_usage}%");- $message->addField('Threshold', "{$this->server_disk_usage_notification_threshold}%");- $message->addField('Tips', '[Link](https://coolify.io/docs/knowledge-base/server/automated-cleanup)');+ $message->addField('Disk usage', "{$this->disk_usage}%", true);+ $message->addField('Threshold', "{$this->server_disk_usage_notification_threshold}%", true);+ $message->addField('What to do?', '[Link](https://coolify.io/docs/knowledge-base/server/automated-cleanup)', true);+ $message->addField('Change Settings', '[Threshold]('.base_url().'/server/'.$this->server->uuid.'#advanced) | [Notification]('.base_url().'/notifications/discord)');return $message;}diff --git a/database/migrations/2024_10_22_121223_add_server_disk_usage_notification.php b/database/migrations/2024_10_22_121223_add_server_disk_usage_notification.phpnew file mode 100644index 0000000000..a2aa381b7e--- /dev/null+++ b/database/migrations/2024_10_22_121223_add_server_disk_usage_notification.php@@ -0,0 +1,32 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('teams', function (Blueprint $table) {+ $table->boolean('discord_notifications_server_disk_usage')->default(true)->after('discord_enabled');+ $table->boolean('smtp_notifications_server_disk_usage')->default(true)->after('smtp_enabled');+ $table->boolean('telegram_notifications_server_disk_usage')->default(true)->after('telegram_enabled');+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('teams', function (Blueprint $table) {+ $table->dropColumn('discord_notifications_server_disk_usage');+ $table->dropColumn('smtp_notifications_server_disk_usage');+ $table->dropColumn('telegram_notifications_server_disk_usage');+ });+ }+};diff --git a/resources/views/livewire/notifications/discord.blade.php b/resources/views/livewire/notifications/discord.blade.phpindex 1dbdf241e9..300af6d73a 100644--- a/resources/views/livewire/notifications/discord.blade.php+++ b/resources/views/livewire/notifications/discord.blade.php@@ -37,6 +37,8 @@label="Backup Status" /><x-forms.checkbox instantSave="saveModel" id="team.discord_notifications_scheduled_tasks"label="Scheduled Tasks Status" />+ <x-forms.checkbox instantSave="saveModel" id="team.discord_notifications_server_disk_usage"+ label="Server Disk Usage" /></div>@endif</div>diff --git a/resources/views/livewire/notifications/email.blade.php b/resources/views/livewire/notifications/email.blade.phpindex 594cf427bb..a87a31c24f 100644--- a/resources/views/livewire/notifications/email.blade.php+++ b/resources/views/livewire/notifications/email.blade.php@@ -116,6 +116,8 @@label="Backup Status" /><x-forms.checkbox instantSave="saveModel" id="team.smtp_notifications_scheduled_tasks"label="Scheduled Tasks Status" />+ <x-forms.checkbox instantSave="saveModel" id="team.smtp_notifications_server_disk_usage"+ label="Server Disk Usage" /></div>@endif</div>diff --git a/resources/views/livewire/notifications/telegram.blade.php b/resources/views/livewire/notifications/telegram.blade.phpindex 3f57ff4711..09b4dd7dbb 100644--- a/resources/views/livewire/notifications/telegram.blade.php+++ b/resources/views/livewire/notifications/telegram.blade.php@@ -71,7 +71,11 @@helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used."id="team.telegram_notifications_scheduled_tasks_thread_id" label="Custom Topic ID" /></div>-+ <div class="flex flex-col">+ <h4>Server Disk Usage</h4>+ <x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_server_disk_usage"+ label="Enabled" />+ </div></div>@endif</form>