DeploymentLog: new action and table
Fetching logs has to be completed and moved elsewhere
This commit is contained in:
parent
9ea08647dc
commit
1c86d9ebf7
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Core\RestApiClient;
|
||||
use Icinga\Module\Director\Core\CoreApi;
|
||||
use Exception;
|
||||
|
||||
class Director_ListController extends ActionController
|
||||
{
|
||||
|
@ -115,6 +118,66 @@ class Director_ListController extends ActionController
|
|||
$this->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());
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class DeploymentLogTable extends QuickTable
|
||||
{
|
||||
public function getColumns()
|
||||
{
|
||||
$columns = array(
|
||||
'id' => '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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue