diff --git a/app/Console/Commands/CheckRoomOnlineStatus.php b/app/Console/Commands/CheckRoomOnlineStatus.php index ed507d2..f4fb264 100644 --- a/app/Console/Commands/CheckRoomOnlineStatus.php +++ b/app/Console/Commands/CheckRoomOnlineStatus.php @@ -23,9 +23,8 @@ class CheckRoomOnlineStatus extends Command $rooms = Room::with('branch')->where('is_online',1)->get(); foreach ($rooms as $room) { - // 找出最近的一筆 MachineStatus 資料(比對 hostname 和 branch_name) + $branch = optional($room->branch); $latestStatus = MachineStatus::where('hostname', $room->type->value.$room->name) - //->where('branch_name', optional($room->branch)->name) ->latest('created_at') ->first(); @@ -34,12 +33,15 @@ class CheckRoomOnlineStatus extends Command $room->status = RoomStatus::Error; $room->save(); - $response = (new MachineStatusForwarder($rooms->branch->external_ip, "/api/room/receiveSwitch", [ - "branch_name"=>$rooms->branch->name, - "room_name"=>$rooms->type->value.$rooms->name, - "command" =>"error", - - ]))->forward(); + $response = (new MachineStatusForwarder( + $branch->external_ip ?? '', + '/api/room/receiveSwitch', + [ + 'branch_name' => $branch->name, + 'room_name' => $room->type->value.$room->name, + 'command' => 'error', + ] + ))->forward(); $this->info("Room [{$room->name}] marked as offline (no recent MachineStatus)"); } } diff --git a/app/Services/MachineStatusForwarder.php b/app/Services/MachineStatusForwarder.php index e516d41..d6f2f02 100644 --- a/app/Services/MachineStatusForwarder.php +++ b/app/Services/MachineStatusForwarder.php @@ -39,12 +39,12 @@ class MachineStatusForwarder $client = new ApiClient($mainDomainUrl, $this->user->api_plain_token); $response = $client->post($this->endpoint, $this->validated); - Log::info('✅ Machine status forwarded', [ + /* Log::info('✅ Machine status forwarded', [ 'endpoint' => $this->endpoint, 'request' => $this->validated, 'status' => $response->status(), 'body' => $response->json(), - ]); + ]); */ } else { Log::warning("🔒 User with ID 2 not found or missing token"); }