2015-06-29 16:01:10 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2016-03-13 23:48:22 +01:00
|
|
|
use Exception;
|
2016-04-22 11:19:54 +02:00
|
|
|
use Icinga\Module\Director\Objects\SyncRule;
|
2015-06-30 11:27:32 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
2015-06-29 16:01:10 +02:00
|
|
|
|
2015-12-18 09:01:25 +01:00
|
|
|
class IndexController extends ActionController
|
2015-06-29 16:01:10 +02:00
|
|
|
{
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2016-03-21 09:10:09 +01:00
|
|
|
if ($this->getRequest()->isGet()) {
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
}
|
|
|
|
|
2016-03-21 19:16:26 +01:00
|
|
|
if (! $this->Config()->get('db', 'resource')
|
|
|
|
|| !$this->fetchStats()
|
|
|
|
|| !$this->hasDeploymentEndpoint()
|
|
|
|
) {
|
|
|
|
$this->getTabs()->add('overview', array(
|
|
|
|
'url' => $this->getRequest()->getUrl(),
|
|
|
|
'label' => $this->translate('Configuration')
|
|
|
|
))->activate('overview');
|
|
|
|
$this->view->title = $this->translate('Configuration');
|
|
|
|
$this->view->form = $this->loadForm('kickstart')->handleRequest();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->getTabs()->add('overview', array(
|
|
|
|
'url' => $this->getRequest()->getUrl(),
|
|
|
|
'label' => $this->translate('Overview')
|
|
|
|
))->activate('overview');
|
2016-04-22 11:19:54 +02:00
|
|
|
|
|
|
|
$this->fetchSyncState();
|
2015-06-29 16:01:10 +02:00
|
|
|
}
|
2016-03-21 19:16:26 +01:00
|
|
|
}
|
2015-12-18 10:51:38 +01:00
|
|
|
|
2016-04-22 11:19:54 +02:00
|
|
|
protected function fetchSyncState()
|
|
|
|
{
|
|
|
|
$syncs = SyncRule::loadAll($this->db());
|
|
|
|
if (count($syncs) > 0) {
|
|
|
|
$state = 'ok';
|
|
|
|
} else {
|
|
|
|
$state = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($syncs as $sync) {
|
|
|
|
if ($sync->sync_state !== 'in-sync') {
|
|
|
|
if ($sync->sync_state === 'failing') {
|
|
|
|
$state = 'critical';
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
$state = 'warning';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->syncState = $state;
|
|
|
|
}
|
|
|
|
|
2016-03-21 19:16:26 +01:00
|
|
|
protected function hasDeploymentEndpoint()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->view->hasDeploymentEndpoint = $this->db()->hasDeploymentEndpoint();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return false;
|
2015-12-18 10:51:38 +01:00
|
|
|
}
|
2016-03-21 19:16:26 +01:00
|
|
|
|
|
|
|
return $this->view->hasDeploymentEndpoint;
|
2015-06-29 16:01:10 +02:00
|
|
|
}
|
2016-03-13 23:48:22 +01:00
|
|
|
|
|
|
|
protected function fetchStats()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->view->stats = $this->db()->getObjectSummary();
|
|
|
|
$this->view->undeployedActivities = $this->db()->countActivitiesSinceLastDeployedConfig();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-29 16:01:10 +02:00
|
|
|
}
|