getStatus()
Signatur
public function getStatus(ProductHosting $productHosting): ServerHostingStatusResponseBeschreibung
Diese Methode wird per Ajax-Anfrage ausgeführt, um das Status-Badge des Hosting anzuzeigen. Es besteht aus dem Badge-Typ (success, warning, danger usw.) und dem Badge-Text.
Tipp: Du kannst zusätzliche Daten als dritten Parameter übergeben, z. B. die aktuellen Statistiken zur Echtzeitnutzung, die im Frontend wie unten beschrieben über ein JavaScript-Event verwendet werden können.
Beispiel
public function getStatus(ProductHosting $productHosting): ServerHostingStatusResponse {
// Make the API call to retrieve the VPS information
$response = $this->getClient($productHosting->host)->sendHostCall("{$productHosting->custom_fields['proxmoxVirtualization']}/{$productHosting->custom_fields['proxmoxVmId']}/status/current")->data;
// Handle the response to display the badge accordingly
if ($response->status === 'stopped') {
$status = "Offline";
$badge = "danger";
}
if ($response->status === 'running') {
$status = "Online";
$badge = "success";
}
return new ServerHostingStatusResponse(
$status ?? "Unknown", // The badge text
$badge ?? "danger", // The badge variant (see https://getbootstrap.com/docs/4.0/components/badge/#contextual-variations)
[ // Additional statistics of the VPS which are displayed in the frontend (optional)
"stats" => [
"uptime" => $response->uptime,
"ram" => [
"max" => $response->maxmem,
"current" => $response->mem,
"usage" => round($response->mem / $response->maxmem * 100, 2),
],
"disk" => [
"max" => $response->maxdisk,
"current" => $response->disk,
],
"cpu" => [
"cores" => $response->cpus,
"usage" => round($response->cpu * 100, 2),
],
]
]);
}War das hilfreich?