diff --git a/app/Controllers/Admin/HPILOController.php b/app/Controllers/Admin/HPILOController.php index d5b8d11..60ff711 100644 --- a/app/Controllers/Admin/HPILOController.php +++ b/app/Controllers/Admin/HPILOController.php @@ -47,11 +47,18 @@ class HPILOController extends \App\Controllers\Admin\AdminController ////추가 Action final public function console($uid) { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $ilo = new HPILO4($this->getAdapter($entity)); - $this->_viewDatas['SessionKey'] = $ilo->console(); - $this->_viewDatas['entity'] = $entity; - return view($this->_viewPath . '/console_iframe', $this->_viewDatas); + try { + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $ilo = new HPILO4($this->getAdapter($entity)); + $this->_viewDatas['SessionKey'] = $ilo->console(); + $this->_viewDatas['entity'] = $entity; + return view($this->_viewPath . '/console_iframe', $this->_viewDatas); + } catch (\Exception $e) { + $message = "{$entity->getTitle()} " . __FUNCTION__ . " 실패하였습니다."; + log_message("warning", $message . "
\n{$e->getMessage()}"); + log_message("info", "{$this->_viewDatas['title']} {$message}"); + return alert_CommonHelper($message, 'back'); + } } final public function reset($uid, string $type) @@ -75,25 +82,19 @@ class HPILOController extends \App\Controllers\Admin\AdminController } } - private function refresh(HPILO4 $ilo, HPILOEntity $entity) - { - $entity = $ilo->refresh($entity); - if ($entity->hasChanged()) { - if (!$this->_model->save($entity)) { - log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery()); - log_message("error", implode("\n", $this->_model->errors())); - throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors())); - } - } - return $entity; - } final public function reload($uid) { try { $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $ilo = new HPILO4($this->getAdapter($entity)); - // throw new \Exception(var_export($ilo, true)); - $entity = $this->refresh($ilo, $entity); + $entity = $ilo->reload($entity); + if ($entity->hasChanged()) { + if (!$this->_model->save($entity)) { + log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery()); + log_message("error", implode("\n", $this->_model->errors())); + throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors())); + } + } $message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다."; log_message("info", "{$this->_viewDatas['title']} {$message}"); return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL'])); diff --git a/app/Libraries/API/HPILO/HPILO4.php b/app/Libraries/API/HPILO/HPILO4.php index 2b25060..a69c98c 100644 --- a/app/Libraries/API/HPILO/HPILO4.php +++ b/app/Libraries/API/HPILO/HPILO4.php @@ -8,22 +8,12 @@ use App\Libraries\Adapter\API\Adapter; class HPILO4 { private $_adapter = null; - private $_system = array(); + private $_health = "OK"; protected $_base_url = "/redfish/v1"; public function __construct(Adapter $adapter) { $this->_adapter = $adapter; } - private function getSystemInfo() - { - $results = $this->_adapter->get($this->_base_url . "/Systems/1/"); - $this->_system['model'] = sprintf("%s %s", $results->Model, $results->BiosVersion); - $this->_system['processor'] = trim($results->Processors->ProcessorFamily) . " * " . $results->Processors->Count; - $this->_system['memory'] = $results->Memory->TotalSystemMemoryGB; - $this->_system['health'] = 'OK'; - $this->_system['power'] = $results->Power; - $this->_system['detail'] = ''; - } private function getMemoryInfo($url) { @@ -31,7 +21,7 @@ class HPILO4 $results = $this->_adapter->get($url); //오류체크 if ($results->DIMMStatus != "GoodInUse") { - $this->_system['health'] = "ERROR"; + $this->_health = "ERROR"; } return sprintf( "%s: %s %sMhz %sMB => %s", @@ -58,7 +48,7 @@ class HPILO4 $info = $this->_adapter->get($url); //오류체크 if ($info->Status->Health != "OK") { - $this->_system['health'] = "ERROR"; + $this->_health = "ERROR"; } return sprintf( "%s %s %sGB => %s", @@ -68,7 +58,7 @@ class HPILO4 $info->Status->Health ); } - private function getPhysicalDiskInfos(): array + private function getPhysicalDiskInfos(): string { $results = $this->_adapter->get($this->_base_url . "/Systems/1/SmartStorage/ArrayControllers/0/DiskDrives/"); $disks = array("\n------Physical Disk------"); @@ -77,16 +67,15 @@ class HPILO4 array_push($disks, $this->getPhysicalDiskInfo($link->href)); } } - return $disks; + return implode("\n", $disks); } - - private function getLogicalDiskInfo($url) + private function getLogicalDiskInfo($url): string { //url에서 맨앞의 /를 없애야함(substr사용) $info = $this->_adapter->get($url); //오류체크 if ($info->Status->Health != "OK") { - $this->_system['health'] = "ERROR"; + $this->_health = "ERROR"; } return sprintf( "%s Raid:%s %s_%s %sMB => %s", @@ -98,7 +87,7 @@ class HPILO4 $info->Status->Health ); } - private function getLogicalDiskInfos(): array + private function getLogicalDiskInfos(): string { $results = $this->_adapter->get($this->_base_url . "/Systems/1/SmartStorage/ArrayControllers/0/LogicalDrives/"); $disks = array("\n------Logical Disk------"); @@ -107,21 +96,21 @@ class HPILO4 array_push($disks, $this->getLogicalDiskInfo($link->href)); } } - return $disks; + return implode("\n", $disks); } - private function getFanInfos(): array + private function getFanInfos(): string { $results = $this->_adapter->get($this->_base_url . "/Chassis/1/Thermal/"); $fans = array("\n------Fan------"); foreach ($results->Fans as $fan) { //오류체크 if ($fan->Status->Health != "OK") { - $this->_system['health'] = "ERROR"; + $this->_health = "ERROR"; } array_push($fans, sprintf("%s => %s", $fan->FanName, $fan->Status->Health)); } - return $fans; + return implode("\n", $fans); } public function console() @@ -152,16 +141,19 @@ class HPILO4 return $this->_adapter->post($this->_base_url . "/Systems/1", array("Action" => 'Reset', "ResetType" => $resetType)); } - public function refresh(HPILOEntity $entity): HPILOEntity + public function reload(HPILOEntity $entity): HPILOEntity { - $this->getSystemInfo(); - $this->_system['detail'] .= implode("\n", $this->getMemoryInfos()); - $this->_system['detail'] .= implode("\n", $this->getPhysicalDiskInfos()); - $this->_system['detail'] .= implode("\n", $this->getLogicalDiskInfos()); - $this->_system['detail'] .= implode("\n", $this->getFanInfos()); - foreach ($this->_system as $field => $value) { - $entity->$field = $value; - } + //시스템 정보 가져오기 + $results = $this->_adapter->get($this->_base_url . "/Systems/1/"); + $entity->model = sprintf("%s %s", $results->Model, $results->BiosVersion); + $entity->processor = trim($results->Processors->ProcessorFamily) . " * " . $results->Processors->Count; + $entity->memory = $results->Memory->TotalSystemMemoryGB; + $entity->power = $results->Power; + //각 부품별 정보 가져오기 + $entity->detail = $this->getMemoryInfos(); + $entity->detail .= $this->getPhysicalDiskInfos(); + $entity->detail .= $this->getLogicalDiskInfos(); + $entity->detail .= $this->getFanInfos(); return $entity; } }