feat: add notification settings to server_disk_usage
This commit is contained in:
@@ -116,10 +116,14 @@ class Kernel extends ConsoleKernel
|
|||||||
}
|
}
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$last_sentinel_update = $server->sentinel_updated_at;
|
$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 ServerCheckJob($server))->everyMinute()->onOneServer();
|
||||||
}
|
}
|
||||||
// $schedule->job(new ServerStorageCheckJob($server))->everyMinute()->onOneServer();
|
|
||||||
$serverTimezone = $server->settings->server_timezone;
|
$serverTimezone = $server->settings->server_timezone;
|
||||||
if ($server->settings->force_docker_cleanup) {
|
if ($server->settings->force_docker_cleanup) {
|
||||||
$schedule->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();
|
$schedule->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();
|
||||||
|
@@ -18,6 +18,7 @@ class Discord extends Component
|
|||||||
'team.discord_notifications_status_changes' => 'nullable|boolean',
|
'team.discord_notifications_status_changes' => 'nullable|boolean',
|
||||||
'team.discord_notifications_database_backups' => 'nullable|boolean',
|
'team.discord_notifications_database_backups' => 'nullable|boolean',
|
||||||
'team.discord_notifications_scheduled_tasks' => 'nullable|boolean',
|
'team.discord_notifications_scheduled_tasks' => 'nullable|boolean',
|
||||||
|
'team.discord_notifications_server_disk_usage' => 'nullable|boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $validationAttributes = [
|
protected $validationAttributes = [
|
||||||
|
@@ -31,6 +31,7 @@ class Email extends Component
|
|||||||
'team.smtp_notifications_status_changes' => 'nullable|boolean',
|
'team.smtp_notifications_status_changes' => 'nullable|boolean',
|
||||||
'team.smtp_notifications_database_backups' => 'nullable|boolean',
|
'team.smtp_notifications_database_backups' => 'nullable|boolean',
|
||||||
'team.smtp_notifications_scheduled_tasks' => 'nullable|boolean',
|
'team.smtp_notifications_scheduled_tasks' => 'nullable|boolean',
|
||||||
|
'team.smtp_notifications_server_disk_usage' => 'nullable|boolean',
|
||||||
'team.use_instance_email_settings' => 'boolean',
|
'team.use_instance_email_settings' => 'boolean',
|
||||||
'team.resend_enabled' => 'nullable|boolean',
|
'team.resend_enabled' => 'nullable|boolean',
|
||||||
'team.resend_api_key' => 'nullable',
|
'team.resend_api_key' => 'nullable',
|
||||||
|
@@ -24,6 +24,7 @@ class Telegram extends Component
|
|||||||
'team.telegram_notifications_status_changes_message_thread_id' => 'nullable|string',
|
'team.telegram_notifications_status_changes_message_thread_id' => 'nullable|string',
|
||||||
'team.telegram_notifications_database_backups_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_scheduled_tasks_thread_id' => 'nullable|string',
|
||||||
|
'team.telegram_notifications_server_disk_usage' => 'nullable|boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $validationAttributes = [
|
protected $validationAttributes = [
|
||||||
|
@@ -1275,4 +1275,8 @@ $schema://$host {
|
|||||||
loggy('Error restarting Sentinel: '.$e->getMessage());
|
loggy('Error restarting Sentinel: '.$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function url()
|
||||||
|
{
|
||||||
|
return base_url().'/server/'.$this->uuid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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_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_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_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_enabled' => ['type' => 'boolean', 'description' => 'Whether Discord is enabled or not.'],
|
||||||
'discord_webhook_url' => ['type' => 'string', 'description' => 'The Discord webhook URL.'],
|
'discord_webhook_url' => ['type' => 'string', 'description' => 'The Discord webhook URL.'],
|
||||||
'discord_notifications_test' => ['type' => 'boolean', 'description' => 'Whether to send test notifications via Discord.'],
|
'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_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_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_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.'],
|
'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_enabled' => ['type' => 'boolean', 'description' => 'Whether to enable resending or not.'],
|
||||||
'resend_api_key' => ['type' => 'string', 'description' => 'The resending API key.'],
|
'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_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_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.'],
|
'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.'],
|
'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' => ['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.'],
|
'telegram_notifications_scheduled_tasks_thread_id' => ['type' => 'string', 'description' => 'The Telegram scheduled task message thread ID.'],
|
||||||
|
@@ -22,22 +22,7 @@ class HighDiskUsage extends Notification implements ShouldQueue
|
|||||||
|
|
||||||
public function via(object $notifiable): array
|
public function via(object $notifiable): array
|
||||||
{
|
{
|
||||||
$channels = [];
|
return setNotificationChannels($notifiable, 'server_disk_usage');
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail(): MailMessage
|
public function toMail(): MailMessage
|
||||||
@@ -59,11 +44,13 @@ class HighDiskUsage extends Notification implements ShouldQueue
|
|||||||
title: ':cross_mark: High disk usage detected',
|
title: ':cross_mark: High disk usage detected',
|
||||||
description: "Server '{$this->server->name}' high disk usage detected!",
|
description: "Server '{$this->server->name}' high disk usage detected!",
|
||||||
color: DiscordMessage::errorColor(),
|
color: DiscordMessage::errorColor(),
|
||||||
|
isCritical: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
$message->addField('Disk usage', "{$this->disk_usage}%");
|
$message->addField('Disk usage', "{$this->disk_usage}%", true);
|
||||||
$message->addField('Threshold', "{$this->server_disk_usage_notification_threshold}%");
|
$message->addField('Threshold', "{$this->server_disk_usage_notification_threshold}%", true);
|
||||||
$message->addField('Tips', '[Link](https://coolify.io/docs/knowledge-base/server/automated-cleanup)');
|
$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;
|
return $message;
|
||||||
}
|
}
|
||||||
|
@@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@@ -37,6 +37,8 @@
|
|||||||
label="Backup Status" />
|
label="Backup Status" />
|
||||||
<x-forms.checkbox instantSave="saveModel" id="team.discord_notifications_scheduled_tasks"
|
<x-forms.checkbox instantSave="saveModel" id="team.discord_notifications_scheduled_tasks"
|
||||||
label="Scheduled Tasks Status" />
|
label="Scheduled Tasks Status" />
|
||||||
|
<x-forms.checkbox instantSave="saveModel" id="team.discord_notifications_server_disk_usage"
|
||||||
|
label="Server Disk Usage" />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@@ -116,6 +116,8 @@
|
|||||||
label="Backup Status" />
|
label="Backup Status" />
|
||||||
<x-forms.checkbox instantSave="saveModel" id="team.smtp_notifications_scheduled_tasks"
|
<x-forms.checkbox instantSave="saveModel" id="team.smtp_notifications_scheduled_tasks"
|
||||||
label="Scheduled Tasks Status" />
|
label="Scheduled Tasks Status" />
|
||||||
|
<x-forms.checkbox instantSave="saveModel" id="team.smtp_notifications_server_disk_usage"
|
||||||
|
label="Server Disk Usage" />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@@ -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."
|
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" />
|
id="team.telegram_notifications_scheduled_tasks_thread_id" label="Custom Topic ID" />
|
||||||
</div>
|
</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>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user