2016-10-27 19:58:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2019-09-17 15:06:39 +02:00
|
|
|
use Icinga\Module\Director\Web\Tabs\MainTabs;
|
2018-10-05 15:56:22 +02:00
|
|
|
use Icinga\Module\Director\Web\Widget\HealthCheckPluginOutput;
|
2016-10-27 19:58:31 +02:00
|
|
|
use Icinga\Module\Director\Dashboard\Dashboard;
|
2018-10-05 15:56:22 +02:00
|
|
|
use Icinga\Module\Director\Health;
|
2016-10-27 19:58:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
2018-06-07 23:50:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DbSelectorForm;
|
2016-10-27 19:58:31 +02:00
|
|
|
|
|
|
|
class DashboardController extends ActionController
|
|
|
|
{
|
2016-11-03 16:06:18 +01:00
|
|
|
protected function checkDirectorPermissions()
|
|
|
|
{
|
2018-06-23 11:17:56 +02:00
|
|
|
// No special permissions required, override parent method
|
2016-11-03 16:06:18 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 23:50:31 +02:00
|
|
|
protected function addDbSelection()
|
|
|
|
{
|
2018-06-23 11:17:56 +02:00
|
|
|
if ($this->isMultiDbSetup()) {
|
2019-05-02 13:23:06 +02:00
|
|
|
$form = new DbSelectorForm(
|
|
|
|
$this->getResponse(),
|
|
|
|
$this->Window(),
|
|
|
|
$this->listAllowedDbResourceNames()
|
|
|
|
);
|
2018-06-23 11:17:56 +02:00
|
|
|
$this->content()->add($form);
|
2019-05-02 13:23:06 +02:00
|
|
|
$form->handleRequest($this->getServerRequest());
|
2018-06-23 11:17:56 +02:00
|
|
|
}
|
2018-06-07 23:50:31 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 19:58:31 +02:00
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
if ($this->getRequest()->isGet()) {
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
}
|
|
|
|
|
2020-01-10 12:33:54 +01:00
|
|
|
$mainDashboards = [
|
|
|
|
'Objects',
|
|
|
|
'Alerts',
|
|
|
|
'Automation',
|
|
|
|
'Deployment',
|
|
|
|
'Director',
|
|
|
|
'Data',
|
|
|
|
];
|
2017-07-14 11:02:44 +02:00
|
|
|
$this->setTitle($this->translate('Icinga Director - Main Dashboard'));
|
2017-07-19 18:37:19 +02:00
|
|
|
$names = $this->params->getValues('name', $mainDashboards);
|
2018-06-07 23:50:31 +02:00
|
|
|
if (! $this->params->has('name')) {
|
|
|
|
$this->addDbSelection();
|
|
|
|
}
|
2016-12-14 14:58:51 +01:00
|
|
|
if (count($names) === 1) {
|
2017-07-19 18:37:19 +02:00
|
|
|
$name = $names[0];
|
|
|
|
$dashboard = Dashboard::loadByName($name, $this->db());
|
|
|
|
$this->tabs($dashboard->getTabs())->activate($name);
|
2016-12-14 14:58:51 +01:00
|
|
|
} else {
|
2019-09-17 15:06:39 +02:00
|
|
|
$this->tabs(new MainTabs($this->Auth(), $this->getDbResourceName()))->activate('main');
|
2016-12-14 14:58:51 +01:00
|
|
|
}
|
2017-06-14 18:20:39 +02:00
|
|
|
|
2017-07-03 15:19:43 +02:00
|
|
|
$cntDashboards = 0;
|
2016-12-14 14:58:51 +01:00
|
|
|
foreach ($names as $name) {
|
2017-07-19 18:37:19 +02:00
|
|
|
if ($name instanceof Dashboard) {
|
|
|
|
$dashboard = $name;
|
|
|
|
} else {
|
|
|
|
$dashboard = Dashboard::loadByName($name, $this->db());
|
|
|
|
}
|
2016-10-27 19:58:31 +02:00
|
|
|
if ($dashboard->isAvailable()) {
|
2017-07-03 15:19:43 +02:00
|
|
|
$cntDashboards++;
|
2017-06-14 18:20:39 +02:00
|
|
|
$this->content()->add($dashboard);
|
2016-10-27 19:58:31 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 15:19:43 +02:00
|
|
|
|
|
|
|
if ($cntDashboards === 0) {
|
|
|
|
$msg = $this->translate(
|
|
|
|
'No dashboard available, you might have not enough permissions'
|
|
|
|
);
|
|
|
|
$this->content()->add($msg);
|
|
|
|
}
|
2016-10-27 19:58:31 +02:00
|
|
|
}
|
|
|
|
}
|