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