SettingsHelper = new SettingsHelper(); } /** * Execute the console command. * * @return int */ public function handle() { return true; // Function disabled for optimization // return true; // $ip = CompanySettings::get($this->SettingsHelper->S_COMPANY_DOMAIN); $users_count = 0; $this->info('Checking server status...'); $storageResult = $this->checkStorageCapacity(); $client = new Client([ 'verify' => false]); $options = [ 'multipart' => [ [ 'name' => 'storage_total', 'contents' => $storageResult['total'] ], [ 'name' => 'storage_used', 'contents' => $storageResult['used'] ], [ 'name' => 'users_count', 'contents' => $users_count ], [ 'name' => 'last_cdr_call_date', 'contents' => $this->getLastCdrCallDate(), ] ]]; // print_r($options); dd($options); $request = new Request('POST', 'https://main.egytelecoms.com/api/LiveServers'); $res = $client->sendAsync($request, $options)->wait(5); echo $res->getBody(); return 0; } private function pingIp() { try { $process = new Process (['ping', '-c', '3', '185.188.249.147']); $process->setTimeout(10); $process->run(); if (!$process->isSuccessful()) { return false; } $output = $process->getOutput(); preg_match('/min\/avg\/max\/mdev = ([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+) ms/', $output, $matches); // return $matches ?? false; // print_r($matches); if (!empty($matches)) { return $matches; echo "min = $matches[1] ms" . PHP_EOL; echo "avg = $matches[2] ms" . PHP_EOL; echo "max = $matches[3] ms" . PHP_EOL; }else{ return false; } } catch (Exception $e) { return false; // echo $e->getMessage() . "\n"; } } private function checkStorageCapacity() { $process = new Process(['df', '-h', '/']); $process->run(); if (!$process->isSuccessful()) { return false; } $output = $process->getOutput(); preg_match('/\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\/\s*$/m', $output, $matches); if (!empty($matches)) { $parts = preg_split('/\s+/', $matches[0] ?? ''); $data = [ 'total' => intval($parts[1] ?? '0'), 'used' => intval($parts[2] ?? '0'), ]; return $data; } else { return false; } } private function getLastCdrCallDate() { $result = \DB::table('asteriskcdrdb.cdr') ->select('calldate') ->orderBy('calldate', 'DESC') ->first(); return $result ? $result->calldate : null; } }