class_name = "AuditLog"; parent::__construct(); $this->class_path .= $this->class_name; } protected function getModel(): AuditLogModel { if ($this->_model === null) { $this->_model = new AuditLogModel(); } return $this->_model; } protected function getAccountModel(): AccountModel { if ($this->_accountModel === null) { $this->_accountModel = new AccountModel(); } return $this->_accountModel; } protected function getArrayByResult(\stdClass $result, array $formDatas = []): array { $formDatas[AuditLogModel::PK] = $result->id; $formDatas[AuditLogModel::TITLE] = $result->action->type; $formDatas['action_info'] = isset($result->action->info) ? $result->action->info : ""; $formDatas['actor'] = $result->actor->type; $formDatas['interface'] = isset($result->interface) ? $result->interface : ""; $formDatas['zone_id'] = $result->newValueJson->zone_id; $formDatas['zone_name'] = isset($result->newValueJson->zone_name) ? $result->newValueJson->zone_name : ""; $formDatas['resource_id'] = $result->newValueJson->id; $formDatas['resource_name'] = isset($result->newValueJson->name) ? $result->newValueJson->name : ""; $formDatas['resource_type'] = $result->newValueJson->type ? $result->newValueJson->type : ""; $formDatas['status'] = $result->action->result ? "true" : "false"; $formDatas['updated_at'] = date("Y-m-d H:i:s"); $formDatas['created_at'] = $result->when; return $formDatas; } private function auditlog_process(AuditLogEntity $entity): void { //해당 Zone을 Sync작업한다 $zone_service = new ZoneService(); $zone_entity = $zone_service->getEntityByPK($entity->getZoneID()); if ($zone_entity !== null) { // $zone_entity = $zone_service->sync($entity, $zone_entity); // //해당 Zone의 Record reload작업한다 // $record_service = new RecordService(); // $record_service->reload($zone_entity); // //해당 Zone의 Firewall reload작업한다 // $firewall_service = new FirewallService(); // $firewall_service->reload($zone_entity); log_message("debug", "AuditLog Process의 {$zone_entity->getTitle()} Sync및 Record,Firewall Reload 처리작업"); } } public function reload(AccountEntity $account_entity): void { //Socket인증정보 정의 $auth_entity = $this->getAuthModel()->getEntityByPK($account_entity->getParent()); if ($auth_entity === null) { throw new \Exception("해당 계정정보를 찾을수 없습니다."); } $this->setAuthEntity($auth_entity); log_message("notice", "\n----------Account {$account_entity->getTitle()}의 AuditLog 처리 시작-----------"); try { $endpoint = sprintf("accounts/%s/audit_logs?since=%s", $account_entity->getPK(), date("Y-m-d")); log_message("debug", "Auditlog Endpoint: " . $endpoint); $response = $this->getMySocket()->get($endpoint); $body = json_decode($response->getBody()); foreach ($body->result as $result) { if (isset($result->action->result) && $result->action->result && isset($result->newValueJson->zone_id)) { // log_message("debug", var_export($result->newValueJson, true)); $entity = $this->getModel()->getEntityByPK($result->id); if ($entity === null) { $formDatas = $this->getArrayByResult($result); $entity = $this->getModel()->modify(new AuditlogEntity(), $formDatas); $this->auditlog_process($entity); } } } } catch (\Exception $e) { log_message("error", $e->getMessage()); throw new \Exception($e->getMessage()); } log_message("notice", message: "\n-----------Account {$account_entity->getTitle()}의 AuditLog 처리 완료-----------"); } }