Add all files
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\UptimeLab\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Paymenter\Extensions\Others\UptimeLab\Services\UptimeMonitoringService;
|
||||
|
||||
class CheckUptimeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'uptime:check {--server= : Check specific server by ID}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Check uptime status of all servers or a specific server';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$monitoringService = new UptimeMonitoringService();
|
||||
|
||||
if ($serverId = $this->option('server')) {
|
||||
$this->checkSpecificServer($serverId, $monitoringService);
|
||||
} else {
|
||||
$this->checkAllServers($monitoringService);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all active servers
|
||||
*/
|
||||
private function checkAllServers(UptimeMonitoringService $monitoringService): void
|
||||
{
|
||||
$this->info('Starting uptime check for all active servers...');
|
||||
|
||||
try {
|
||||
$monitoringService->checkAllServers();
|
||||
$this->info('Uptime check completed successfully!');
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Uptime check failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a specific server
|
||||
*/
|
||||
private function checkSpecificServer(string $serverId, UptimeMonitoringService $monitoringService): void
|
||||
{
|
||||
$this->info("Starting uptime check for server ID: {$serverId}...");
|
||||
|
||||
try {
|
||||
$server = \Paymenter\Extensions\Others\UptimeLab\Models\UptimeServer::find($serverId);
|
||||
|
||||
if (!$server) {
|
||||
$this->error("Server with ID {$serverId} not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
$checkResult = $monitoringService->checkServerStatus($server);
|
||||
$monitoringService->updateServerStatus($server, $checkResult);
|
||||
|
||||
$status = $checkResult['online'] ? 'ONLINE' : 'OFFLINE';
|
||||
$responseTime = $checkResult['response_time'] ? $checkResult['response_time'] . 'ms' : 'N/A';
|
||||
|
||||
$this->info("Server: {$server->name}");
|
||||
$this->info("Status: {$status}");
|
||||
$this->info("Response Time: {$responseTime}");
|
||||
$this->info("Uptime check completed successfully!");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Uptime check failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user