lasthourcloud/app/Console/Commands/CleanupUnreachableServers.php

28 lines
925 B
PHP
Raw Normal View History

2024-01-30 09:50:54 +00:00
<?php
namespace App\Console\Commands;
use App\Models\Server;
use Illuminate\Console\Command;
class CleanupUnreachableServers extends Command
{
protected $signature = 'cleanup:unreachable-servers';
2024-02-23 20:51:43 +00:00
protected $description = 'Cleanup Unreachable Servers (7 days)';
2024-01-30 09:50:54 +00:00
public function handle()
{
echo "Running unreachable server cleanup...\n";
2024-02-23 20:51:43 +00:00
$servers = Server::where('unreachable_count', 3)->where('unreachable_notification_sent', true)->where('updated_at', '<', now()->subDays(7))->get();
2024-01-30 09:50:54 +00:00
if ($servers->count() > 0) {
foreach ($servers as $server) {
echo "Cleanup unreachable server ($server->id) with name $server->name";
2024-02-23 20:51:43 +00:00
send_internal_notification("Server $server->name is unreachable for 7 days. Cleaning up...");
$server->update([
'ip' => '1.2.3.4'
]);
2024-01-30 09:50:54 +00:00
}
}
}
}