diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 6651634e..db0a2cf8 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -1,6 +1,9 @@ prepareAndRenderTable('generatedConfig'); } + public function deploymentlogAction() + { + $this->setAutorefreshInterval(5); + try { + $this->fetchLogs(); + } catch (Exception $e) { + // No problem, Icinga might be reloading + } + + $this->view->NOaddLink = $this->view->qlink( + $this->translate('Deploy'), + 'director/config/deploy' + ); + + $this->setConfigTabs()->activate('deploymentlog'); + $this->view->title = $this->translate('Deployments'); + $this->prepareAndRenderTable('deploymentLog'); + } + + protected function fetchLogs() + { + $api = $this->api(); + foreach ($this->db()->getUncollectedDeployments() as $deployment) { + $stage = $deployment->stage_name; + try { + $availableFiles = $api->listStageFiles($stage); + } catch (Exception $e) { + // This is not correct. We might miss logs as af an ongoing reload + $deployment->stage_collected = 'y'; + $deployment->store(); + continue; + } + + if (in_array('startup.log', $availableFiles) + && in_array('status', $availableFiles)) + { + if ($api->getStagedFile($stage, 'status') === '0') { + $deployment->startup_succeeded = 'y'; + } else { + $deployment->startup_succeeded = 'n'; + } + $deployment->startup_log = $this->api()->getStagedFile($stage, 'startup.log'); + } + + $deployment->store(); + } + + // Not correct, we might clear logs we formerly skipped + $api->wipeInactiveStages(); + } + + protected function api() + { + $apiconfig = $this->Config()->getSection('api'); + $client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port')); + $client->setCredentials($apiconfig->get('username'), $apiconfig->get('password')); + $api = new CoreApi($client); + return $api; + } + protected function prepareAndRenderTable($name) { $table = $this->loadTable($name)->setConnection($this->db()); diff --git a/application/tables/DeploymentLogTable.php b/application/tables/DeploymentLogTable.php new file mode 100644 index 00000000..a0144826 --- /dev/null +++ b/application/tables/DeploymentLogTable.php @@ -0,0 +1,61 @@ + 'l.id', + 'peer_identity' => 'l.peer_identity', + 'start_time' => 'l.start_time', + 'stage_collected' => 'l.stage_collected', + 'dump_succeeded' => 'l.dump_succeeded', + 'startup_succeeded' => 'l.startup_succeeded', + 'checksum' => 'LOWER(HEX(c.checksum))', + 'duration' => "l.duration_dump || 'ms'", + ); + + if ($this->connection->getDbType() === 'pgsql') { + $columns['checksum'] = "LOWER(ENCODE(c.checksum, 'hex'))"; + } + + return $columns; + } + + protected function getActionUrl($row) + { + return $this->url('director/deployment/show', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'peer_identity' => $view->translate('Peer'), + // 'checksum' => $view->translate('Checksum'), + 'start_time' => $view->translate('Time'), + 'dump_succeeded' => $view->translate('Sent'), + 'startup_succeeded' => $view->translate('Loaded'), + ); + } + + public function getBaseQuery() + { + $db = $this->connection()->getConnection(); + + $query = $db->select()->from( + array('l' => 'director_deployment_log'), + array() + )->joinLeft( + array('c' => 'director_generated_config'), + 'c.checksum = l.config_id', ///Aaaarg + array() + )->order('l.start_time DESC'); + + return $query; + } +}