Files
coolify/app/Models/WebhookNotificationSettings.php
Andras Bacsai 7837a07ba2 fix(notifications): disable channels after repeated configuration failures
Count invalid keys, tokens, and deleted webhooks in a new failure_count column
on each notification settings table, like servers.unreachable_count. After 3
failures in a row the channel is disabled and the team is told by instance
email and its other channels. Rate limits and server errors are retried and
not counted; test notifications never count.
2026-10-12 14:37:58 +02:00

86 lines
2.7 KiB
PHP

<?php
namespace App\Models;
use App\Traits\TracksDeliveryFailures;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class WebhookNotificationSettings extends Model
{
use Notifiable, TracksDeliveryFailures;
public $timestamps = false;
protected $fillable = [
'team_id',
'webhook_enabled',
'webhook_url',
'deployment_success_webhook_notifications',
'deployment_failure_webhook_notifications',
'status_change_webhook_notifications',
'restart_limit_reached_webhook_notifications',
'backup_success_webhook_notifications',
'backup_failure_webhook_notifications',
'scheduled_task_success_webhook_notifications',
'scheduled_task_failure_webhook_notifications',
'docker_cleanup_success_webhook_notifications',
'docker_cleanup_failure_webhook_notifications',
'server_disk_usage_webhook_notifications',
'server_reachable_webhook_notifications',
'server_unreachable_webhook_notifications',
'server_patch_webhook_notifications',
'traefik_outdated_webhook_notifications',
];
protected $hidden = [
'webhook_url',
];
protected function casts(): array
{
return [
'webhook_enabled' => 'boolean',
'webhook_url' => 'encrypted',
'deployment_success_webhook_notifications' => 'boolean',
'deployment_failure_webhook_notifications' => 'boolean',
'status_change_webhook_notifications' => 'boolean',
'restart_limit_reached_webhook_notifications' => 'boolean',
'backup_success_webhook_notifications' => 'boolean',
'backup_failure_webhook_notifications' => 'boolean',
'scheduled_task_success_webhook_notifications' => 'boolean',
'scheduled_task_failure_webhook_notifications' => 'boolean',
'docker_cleanup_success_webhook_notifications' => 'boolean',
'docker_cleanup_failure_webhook_notifications' => 'boolean',
'server_disk_usage_webhook_notifications' => 'boolean',
'server_reachable_webhook_notifications' => 'boolean',
'server_unreachable_webhook_notifications' => 'boolean',
'server_patch_webhook_notifications' => 'boolean',
'traefik_outdated_webhook_notifications' => 'boolean',
];
}
public function team()
{
return $this->belongsTo(Team::class);
}
public function isEnabled()
{
return $this->webhook_enabled;
}
public function notificationChannelName(): string
{
return 'Webhook';
}
protected function disableNotificationChannel(): void
{
$this->webhook_enabled = false;
}
}