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) {
|
2024-01-30 09:53:12 +00:00
|
|
|
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...");
|
2024-01-30 09:52:57 +00:00
|
|
|
$server->update([
|
|
|
|
'ip' => '1.2.3.4'
|
|
|
|
]);
|
2024-01-30 09:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|