This commit is contained in:
Bozhidar Slaveykov 2024-04-06 19:39:34 +03:00
parent 742dddb16a
commit 7a0e333e00
3 changed files with 24 additions and 4 deletions

View file

@ -1,11 +1,10 @@
<?php
namespace app\ApiSDK;
namespace App\ApiSDK;
class PhyreApiSDK
{
public $ip;
public $port;
public $port = 8443;
public $password;
public $username;
@ -38,7 +37,7 @@ class PhyreApiSDK
// ));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}

View file

@ -77,6 +77,10 @@ class PhyreServerResource extends Resource
//
])
->actions([
Tables\Actions\Action::make('Refresh Status')
->action(function ($record) {
$record->healthCheck();
}),
Tables\Actions\EditAction::make(),
])
->bulkActions([

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\ApiSDK\PhyreApiSDK;
use App\Events\ModelPhyreServerCreated;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -28,4 +29,20 @@ class PhyreServer extends Model
}
public function healthCheck()
{
try {
$phyreApiSDK = new PhyreApiSDK($this->ip, 8443, $this->password, $this->username);
$response = $phyreApiSDK->healthCheck();
if (isset($response['status']) && $response['status'] == 'ok') {
$this->status = 'Online';
$this->save();
}
} catch (\Exception $e) {
$this->status = 'Offline';
$this->save();
}
}
}