Bozhidar Slaveykov 1 anno fa
parent
commit
7a0e333e00

+ 3 - 4
web/app/ApiSDK/PhyreApiSDK.php

@@ -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;
     }
 

+ 4 - 0
web/app/Filament/Resources/PhyreServerResource.php

@@ -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([

+ 17 - 0
web/app/Models/PhyreServer.php

@@ -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();
+        }
+
+    }
+
 }