config/deployments: re-arrange urls and links

This commit is contained in:
Thomas Gelf 2016-02-28 16:52:37 +01:00
parent 8b3b1528c5
commit df133e7981
4 changed files with 99 additions and 90 deletions

View File

@ -7,11 +7,44 @@ use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Web\Notification;
use Icinga\Web\Url;
use Exception;
class ConfigController extends ActionController
{
protected $isApified = true;
public function deploymentsAction()
{
$this->setAutorefreshInterval(5);
try {
if ($this->getRequest()->getUrl()->shift('checkforchanges')) {
$this->fetchLogs();
}
} catch (Exception $e) {
// No problem, Icinga might be reloading
}
$this->view->addLink = $this->view->qlink(
$this->translate('Render config'),
'director/config/store',
null,
array('class' => 'icon-wrench')
);
$this->overviewTabs()->activate('deploymentlog');
$this->view->title = $this->translate('Deployments');
$this->prepareTable('deploymentLog');
try {
// Move elsewhere
$this->view->table->setActiveStageName(
$this->api()->getActiveStageName()
);
} catch (Exception $e) {
// Don't care
}
$this->render('objects/table', null, 'objects');
}
public function deployAction()
{
// TODO: require POST
@ -28,7 +61,7 @@ class ConfigController extends ActionController
if ($isApiRequest) {
return $this->sendJson((object) array('checksum' => $checksum));
} else {
$url = Url::fromPath('director/list/deploymentlog');
$url = Url::fromPath('director/config/deployments?checkforchanges');
Notification::success(
$this->translate('Config has been submitted, validation is going on')
);
@ -47,6 +80,50 @@ class ConfigController extends ActionController
}
}
public function activitiesAction()
{
$this->setAutorefreshInterval(10);
$this->overviewTabs()->activate('activitylog');
$this->view->title = $this->translate('Activity Log');
$this->prepareAndRenderTable('activityLog');
}
protected function fetchLogs()
{
$api = $this->api();
$collected = false;
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');
}
$collected = true;
$deployment->store();
}
// TODO: Not correct, we might clear logs we formerly skipped
if ($collected) {
// $api->wipeInactiveStages();
}
}
// Show all files for a given config
public function filesAction()
{
@ -126,4 +203,22 @@ class ConfigController extends ActionController
)
);
}
protected function overviewTabs()
{
$this->view->tabs = $this->getTabs()->add(
'deploymentlog',
array(
'label' => $this->translate('Deployments'),
'url' => 'director/config/deployments'
)
)->add(
'activitylog',
array(
'label' => $this->translate('Activity Log'),
'url' => 'director/config/activities'
)
);
return $this->view->tabs;
}
}

View File

@ -7,54 +7,6 @@ use Exception;
class ListController extends ActionController
{
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->prepareTable('deploymentLog');
try {
// Move elsewhere
$this->view->table->setActiveStageName(
$this->api()->getActiveStageName()
);
} catch (Exception $e) {
// Don't care
}
$this->render('table');
}
public function generatedconfigAction()
{
$this->view->addLink = $this->view->qlink(
$this->translate('Generate'),
'director/config/store'
);
$this->setConfigTabs()->activate('generatedconfig');
$this->view->title = $this->translate('Generated Configs');
$this->prepareAndRenderTable('generatedConfig');
}
public function activitylogAction()
{
$this->setAutorefreshInterval(10);
$this->setConfigTabs()->activate('activitylog');
$this->view->title = $this->translate('Activity Log');
$this->prepareAndRenderTable('activityLog');
}
public function datalistAction()
{
$this->view->addLink = $this->view->icon('plus')
@ -143,40 +95,4 @@ class ListController extends ActionController
$this->view->table = $this->loadTable('syncrule')->setConnection($this->db());
$this->render('table');
}
protected function fetchLogs()
{
$api = $this->api();
$collected = false;
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');
}
$collected = true;
$deployment->store();
}
// TODO: Not correct, we might clear logs we formerly skipped
if ($collected) {
// $api->wipeInactiveStages();
}
}
}

View File

@ -97,9 +97,7 @@ $all = array(
array('book', $this->translate('Audit log'), 'director/config/activities', $this->translate('Wondering about what changed why? Track you changes!'), 'ok'),
),
$this->translate('Deploy configuration to your Icinga nodes') => array(
array('wrench', $this->translate('Deployment'), 'director/list/deploymentlog', $this->translate('Manage deployments, access audit log and history') . pendingDeployments($this)),
array('globe', $this->translate('Zones'), 'director/zones', statSummary($this, 'zone')),
array('cloud', $this->translate('Endpoints'), 'director/endpoints', statSummary($this, 'endpoint')),
array('wrench', $this->translate('Deployment'), 'director/config/deployments', $this->translate('Manage deployments, access audit log and history') . pendingDeployments($this), $this->undeployedActivities ? 'warning' : 'ok'),
array('lock-open-alt', $this->translate('Api users'), 'director/apiusers', statSummary($this, 'apiuser')),
array('cloud', $this->translate('Endpoints'), 'director/endpoints', statSummary($this, 'endpoint')),
array('globe', $this->translate('Zones'), 'director/zones', statSummary($this, 'zone')),

View File

@ -37,7 +37,7 @@ $section->add($this->translate('Users'))->setUrl('director/users')->setPriority(
$section->add($this->translate('Import / Sync'))
->setUrl('director/list/importsource')
->setPriority(901);
$section->add($this->translate('Config'))
->setUrl('director/list/deploymentlog')
$section->add($this->translate('Deployments / History'))
->setUrl('director/config/deployments')
->setPriority(902)
->setRenderer('ConfigHealthItemRenderer');