Files
ladill-servers/app/Models/NodeCapacityAlert.php
T
isaaccladandCursor b6c8ac343f Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 19:18:30 +00:00

76 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NodeCapacityAlert extends Model
{
use HasFactory;
public const TYPE_CAPACITY_WARNING = 'capacity_warning';
public const TYPE_CAPACITY_CRITICAL = 'capacity_critical';
public const TYPE_RESOURCE_HIGH = 'resource_high';
public const TYPE_NEEDS_EXPANSION = 'needs_expansion';
protected $fillable = [
'hosting_node_id',
'alert_type',
'current_accounts',
'max_accounts',
'capacity_percent',
'resource_usage',
'message',
'is_resolved',
'resolved_by',
'resolved_at',
'resolution_notes',
];
protected $casts = [
'current_accounts' => 'integer',
'max_accounts' => 'integer',
'capacity_percent' => 'decimal:2',
'resource_usage' => 'array',
'is_resolved' => 'boolean',
'resolved_at' => 'datetime',
];
public function hostingNode(): BelongsTo
{
return $this->belongsTo(HostingNode::class);
}
public function resolvedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'resolved_by');
}
public function scopeUnresolved($query)
{
return $query->where('is_resolved', false);
}
public function scopeCritical($query)
{
return $query->whereIn('alert_type', [self::TYPE_CAPACITY_CRITICAL, self::TYPE_NEEDS_EXPANSION]);
}
public function resolve(User $admin, ?string $notes = null): void
{
$this->update([
'is_resolved' => true,
'resolved_by' => $admin->id,
'resolved_at' => now(),
'resolution_notes' => $notes,
]);
}
public function isCritical(): bool
{
return in_array($this->alert_type, [self::TYPE_CAPACITY_CRITICAL, self::TYPE_NEEDS_EXPANSION]);
}
}