2019-10-09 11:26:52 -04:00
|
|
|
<?php
|
|
|
|
|
|
2020-03-13 03:38:01 -04:00
|
|
|
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
|
|
|
|
|
|
2019-11-04 19:07:30 -05:00
|
|
|
namespace Icinga\Module\Icingadb\Controllers;
|
2019-10-09 11:26:52 -04:00
|
|
|
|
2023-08-10 07:43:43 -04:00
|
|
|
use ArrayIterator;
|
2019-10-09 11:26:52 -04:00
|
|
|
use Icinga\Exception\NotFoundError;
|
2021-05-05 04:29:58 -04:00
|
|
|
use Icinga\Module\Icingadb\Command\Object\GetObjectCommand;
|
|
|
|
|
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
|
2024-12-17 08:57:00 -05:00
|
|
|
use Icinga\Module\Icingadb\Common\Backend;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Common\CommandActions;
|
|
|
|
|
use Icinga\Module\Icingadb\Common\Links;
|
|
|
|
|
use Icinga\Module\Icingadb\Common\ServiceLinks;
|
2021-08-17 11:25:54 -04:00
|
|
|
use Icinga\Module\Icingadb\Hook\TabHook\HookActions;
|
2024-11-21 04:23:06 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\DependencyNode;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\History;
|
|
|
|
|
use Icinga\Module\Icingadb\Model\Service;
|
2021-10-06 09:34:36 -04:00
|
|
|
use Icinga\Module\Icingadb\Redis\VolatileStateResults;
|
2024-11-21 04:23:06 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
|
|
|
|
|
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Controller;
|
2025-03-19 10:59:29 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\Detail\ObjectHeader;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Widget\Detail\QuickActions;
|
2020-02-06 09:23:45 -05:00
|
|
|
use Icinga\Module\Icingadb\Widget\Detail\ServiceDetail;
|
2021-05-05 04:29:58 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\Detail\ServiceInspectionDetail;
|
2021-09-03 05:53:43 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\Detail\ServiceMetaInfo;
|
2025-03-24 08:34:08 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\LoadMoreObjectList;
|
2025-03-19 06:41:30 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\ObjectList;
|
2024-11-21 04:23:06 -05:00
|
|
|
use ipl\Orm\Query;
|
|
|
|
|
use ipl\Sql\Expression;
|
2021-11-08 10:26:34 -05:00
|
|
|
use ipl\Stdlib\Filter;
|
2024-11-21 04:23:06 -05:00
|
|
|
use ipl\Web\Control\LimitControl;
|
|
|
|
|
use ipl\Web\Control\SortControl;
|
2021-08-27 07:18:27 -04:00
|
|
|
use ipl\Web\Url;
|
2024-11-21 07:03:20 -05:00
|
|
|
use ipl\Web\Widget\Tabs;
|
2024-11-25 09:15:48 -05:00
|
|
|
use Generator;
|
2019-10-09 11:26:52 -04:00
|
|
|
|
|
|
|
|
class ServiceController extends Controller
|
|
|
|
|
{
|
2019-10-10 07:41:52 -04:00
|
|
|
use CommandActions;
|
2021-08-17 11:25:54 -04:00
|
|
|
use HookActions;
|
2019-10-10 07:41:52 -04:00
|
|
|
|
2019-10-10 07:38:55 -04:00
|
|
|
/** @var Service The service object */
|
|
|
|
|
protected $service;
|
|
|
|
|
|
2024-11-21 07:03:20 -05:00
|
|
|
public function init(): void
|
2019-10-09 11:26:52 -04:00
|
|
|
{
|
2024-11-21 04:24:32 -05:00
|
|
|
$name = $this->params->shiftRequired('name');
|
|
|
|
|
$hostName = $this->params->shiftRequired('host.name');
|
2019-10-09 11:26:52 -04:00
|
|
|
|
2024-10-30 11:57:16 -04:00
|
|
|
$query = Service::on($this->getDb())
|
|
|
|
|
->with([
|
|
|
|
|
'state',
|
|
|
|
|
'icon_image',
|
|
|
|
|
'host',
|
|
|
|
|
'host.state',
|
|
|
|
|
'timeperiod'
|
|
|
|
|
]);
|
2022-03-29 08:39:50 -04:00
|
|
|
$query
|
|
|
|
|
->setResultSetClass(VolatileStateResults::class)
|
|
|
|
|
->filter(Filter::all(
|
|
|
|
|
Filter::equal('service.name', $name),
|
|
|
|
|
Filter::equal('host.name', $hostName)
|
|
|
|
|
));
|
2019-10-09 11:26:52 -04:00
|
|
|
|
2025-01-13 05:29:53 -05:00
|
|
|
if (Backend::supportsDependencies()) {
|
2024-12-17 08:57:00 -05:00
|
|
|
$query->withColumns(['has_problematic_parent']);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 06:38:03 -05:00
|
|
|
$this->applyRestrictions($query);
|
2019-11-22 10:01:27 -05:00
|
|
|
|
2019-10-09 11:26:52 -04:00
|
|
|
/** @var Service $service */
|
|
|
|
|
$service = $query->first();
|
|
|
|
|
if ($service === null) {
|
2025-01-09 05:21:02 -05:00
|
|
|
throw new NotFoundError($this->translate('Service not found'));
|
2019-10-09 11:26:52 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-10 07:38:55 -04:00
|
|
|
$this->service = $service;
|
2021-08-17 11:25:54 -04:00
|
|
|
$this->loadTabsForObject($service);
|
2019-11-03 17:20:46 -05:00
|
|
|
|
2025-03-19 10:59:29 -04:00
|
|
|
$this->addControl(new ObjectHeader($service));
|
2024-11-19 15:59:37 -05:00
|
|
|
|
2019-11-03 17:20:46 -05:00
|
|
|
$this->setTitleTab($this->getRequest()->getActionName());
|
2022-03-16 11:06:00 -04:00
|
|
|
$this->setTitle(
|
2025-01-09 05:21:02 -05:00
|
|
|
$this->translate('%s on %s', '<service> on <host>'),
|
2022-03-03 03:16:16 -05:00
|
|
|
$service->display_name,
|
|
|
|
|
$service->host->display_name
|
|
|
|
|
);
|
2019-10-10 07:38:55 -04:00
|
|
|
}
|
|
|
|
|
|
2024-11-21 07:03:20 -05:00
|
|
|
public function indexAction(): void
|
2019-10-10 07:38:55 -04:00
|
|
|
{
|
2019-11-28 05:35:38 -05:00
|
|
|
if ($this->service->state->is_overdue) {
|
|
|
|
|
$this->controls->addAttributes(['class' => 'overdue']);
|
|
|
|
|
}
|
2021-04-28 12:53:19 -04:00
|
|
|
|
2021-09-03 05:53:43 -04:00
|
|
|
$this->addControl(new ServiceMetaInfo($this->service));
|
2019-11-03 09:34:09 -05:00
|
|
|
$this->addControl(new QuickActions($this->service));
|
|
|
|
|
|
2020-02-06 09:23:45 -05:00
|
|
|
$this->addContent(new ServiceDetail($this->service));
|
2019-12-11 02:59:30 -05:00
|
|
|
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
2019-10-09 11:26:52 -04:00
|
|
|
}
|
2019-11-03 17:20:46 -05:00
|
|
|
|
2024-11-25 09:15:48 -05:00
|
|
|
public function parentsAction(): Generator
|
2024-11-21 04:23:06 -05:00
|
|
|
{
|
2025-01-17 02:40:35 -05:00
|
|
|
$nodesQuery = $this->fetchDependencyNodes(true);
|
2024-11-21 04:23:06 -05:00
|
|
|
|
|
|
|
|
$limitControl = $this->createLimitControl();
|
|
|
|
|
$paginationControl = $this->createPaginationControl($nodesQuery);
|
|
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$nodesQuery,
|
|
|
|
|
[
|
|
|
|
|
'name' => $this->translate('Name'),
|
|
|
|
|
'severity desc, last_state_change desc' => $this->translate('Severity'),
|
|
|
|
|
'state' => $this->translate('Current State'),
|
|
|
|
|
'last_state_change desc' => $this->translate('Last State Change')
|
|
|
|
|
]
|
|
|
|
|
);
|
2025-01-10 07:18:26 -05:00
|
|
|
|
2024-11-21 04:23:06 -05:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
|
|
|
|
|
|
|
|
|
$searchBar = $this->createSearchBar(
|
|
|
|
|
$nodesQuery,
|
|
|
|
|
[
|
|
|
|
|
$limitControl->getLimitParam(),
|
|
|
|
|
$sortControl->getSortParam(),
|
|
|
|
|
$viewModeSwitcher->getViewModeParam(),
|
|
|
|
|
'name',
|
|
|
|
|
'host.name'
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
|
|
|
|
if ($searchBar->hasBeenSubmitted()) {
|
|
|
|
|
$filter = $this->getFilter();
|
|
|
|
|
} else {
|
|
|
|
|
$this->addControl($searchBar);
|
|
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$filter = $searchBar->getFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$nodesQuery->filter($filter);
|
|
|
|
|
|
2024-11-25 09:15:48 -05:00
|
|
|
yield $this->export($nodesQuery);
|
|
|
|
|
|
2024-11-21 04:23:06 -05:00
|
|
|
$this->addControl($paginationControl);
|
|
|
|
|
$this->addControl($sortControl);
|
|
|
|
|
$this->addControl($limitControl);
|
|
|
|
|
$this->addControl($viewModeSwitcher);
|
|
|
|
|
$this->addControl($searchBar);
|
|
|
|
|
|
|
|
|
|
$this->addContent(
|
2025-03-19 06:41:30 -04:00
|
|
|
(new ObjectList($nodesQuery))
|
2024-11-21 04:23:06 -05:00
|
|
|
->setViewMode($viewModeSwitcher->getViewMode())
|
2025-05-06 05:17:39 -04:00
|
|
|
->setEmptyStateMessage($paginationControl->getEmptyStateMessage())
|
2024-11-21 04:23:06 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
|
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 09:15:48 -05:00
|
|
|
public function childrenAction(): Generator
|
2024-11-21 04:23:06 -05:00
|
|
|
{
|
2025-01-17 02:40:35 -05:00
|
|
|
$nodesQuery = $this->fetchDependencyNodes();
|
2024-11-21 04:23:06 -05:00
|
|
|
|
|
|
|
|
$limitControl = $this->createLimitControl();
|
|
|
|
|
$paginationControl = $this->createPaginationControl($nodesQuery);
|
|
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$nodesQuery,
|
|
|
|
|
[
|
|
|
|
|
'name' => $this->translate('Name'),
|
|
|
|
|
'severity desc, last_state_change desc' => $this->translate('Severity'),
|
|
|
|
|
'state' => $this->translate('Current State'),
|
|
|
|
|
'last_state_change desc' => $this->translate('Last State Change')
|
|
|
|
|
]
|
|
|
|
|
);
|
2025-01-10 07:18:26 -05:00
|
|
|
|
2024-11-21 04:23:06 -05:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
|
|
|
|
|
2025-01-17 06:00:38 -05:00
|
|
|
$preserveParams = [
|
|
|
|
|
$limitControl->getLimitParam(),
|
|
|
|
|
$sortControl->getSortParam(),
|
|
|
|
|
$viewModeSwitcher->getViewModeParam(),
|
|
|
|
|
'name',
|
|
|
|
|
'host.name'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
|
|
|
|
|
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
|
|
|
|
|
->setEditorUrl(
|
|
|
|
|
Url::fromPath('icingadb/service/children-search-editor')
|
|
|
|
|
->setParams($requestParams)
|
|
|
|
|
)->setSuggestionUrl(
|
|
|
|
|
Url::fromPath('icingadb/service/children-complete')
|
|
|
|
|
->setParams(clone $requestParams)
|
|
|
|
|
);
|
2024-11-21 04:23:06 -05:00
|
|
|
|
|
|
|
|
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
|
|
|
|
if ($searchBar->hasBeenSubmitted()) {
|
|
|
|
|
$filter = $this->getFilter();
|
|
|
|
|
} else {
|
|
|
|
|
$this->addControl($searchBar);
|
|
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$filter = $searchBar->getFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$nodesQuery->filter($filter);
|
|
|
|
|
|
2024-11-25 09:15:48 -05:00
|
|
|
yield $this->export($nodesQuery);
|
|
|
|
|
|
2024-11-21 04:23:06 -05:00
|
|
|
$this->addControl($paginationControl);
|
|
|
|
|
$this->addControl($sortControl);
|
|
|
|
|
$this->addControl($limitControl);
|
|
|
|
|
$this->addControl($viewModeSwitcher);
|
|
|
|
|
$this->addControl($searchBar);
|
|
|
|
|
|
|
|
|
|
$this->addContent(
|
2025-03-19 06:41:30 -04:00
|
|
|
(new ObjectList($nodesQuery))
|
2024-11-21 04:23:06 -05:00
|
|
|
->setViewMode($viewModeSwitcher->getViewMode())
|
2025-05-06 05:17:39 -04:00
|
|
|
->setEmptyStateMessage($paginationControl->getEmptyStateMessage())
|
2024-11-21 04:23:06 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
|
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 07:03:20 -05:00
|
|
|
public function sourceAction(): void
|
2021-05-05 04:29:58 -04:00
|
|
|
{
|
|
|
|
|
$this->assertPermission('icingadb/object/show-source');
|
2023-08-10 07:43:43 -04:00
|
|
|
|
|
|
|
|
$apiResult = (new CommandTransport())->send(
|
|
|
|
|
(new GetObjectCommand())
|
|
|
|
|
->setObjects(new ArrayIterator([$this->service]))
|
|
|
|
|
);
|
2021-05-05 04:29:58 -04:00
|
|
|
|
|
|
|
|
if ($this->service->state->is_overdue) {
|
|
|
|
|
$this->controls->addAttributes(['class' => 'overdue']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addContent(new ServiceInspectionDetail(
|
|
|
|
|
$this->service,
|
|
|
|
|
reset($apiResult)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 09:15:48 -05:00
|
|
|
public function historyAction(): Generator
|
2019-11-03 17:20:46 -05:00
|
|
|
{
|
2020-01-15 09:50:41 -05:00
|
|
|
$compact = $this->view->compact; // TODO: Find a less-legacy way..
|
2019-12-13 10:15:58 -05:00
|
|
|
|
2019-11-28 05:35:38 -05:00
|
|
|
if ($this->service->state->is_overdue) {
|
|
|
|
|
$this->controls->addAttributes(['class' => 'overdue']);
|
|
|
|
|
}
|
2019-12-13 10:15:58 -05:00
|
|
|
|
2019-11-03 17:20:46 -05:00
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
|
|
|
|
$history = History::on($db)->with([
|
|
|
|
|
'host',
|
|
|
|
|
'host.state',
|
|
|
|
|
'service',
|
|
|
|
|
'service.state',
|
|
|
|
|
'comment',
|
|
|
|
|
'downtime',
|
2020-05-04 06:42:10 -04:00
|
|
|
'flapping',
|
2019-11-03 17:20:46 -05:00
|
|
|
'notification',
|
2020-03-10 03:18:28 -04:00
|
|
|
'acknowledgement',
|
2019-11-03 17:20:46 -05:00
|
|
|
'state'
|
|
|
|
|
]);
|
2022-03-29 08:39:50 -04:00
|
|
|
$history->filter(Filter::all(
|
|
|
|
|
Filter::equal('history.host_id', $this->service->host_id),
|
|
|
|
|
Filter::equal('history.service_id', $this->service->id)
|
|
|
|
|
));
|
2019-11-03 17:20:46 -05:00
|
|
|
|
2021-08-27 07:18:27 -04:00
|
|
|
$before = $this->params->shift('before', time());
|
|
|
|
|
$url = Url::fromRequest()->setParams(clone $this->params);
|
2025-03-24 09:33:23 -04:00
|
|
|
$url->setParams(['name' => $this->service->name, 'host.name' => $this->service->host->name]);
|
2019-12-13 10:15:58 -05:00
|
|
|
|
2019-11-03 17:20:46 -05:00
|
|
|
$limitControl = $this->createLimitControl();
|
2021-08-27 07:18:27 -04:00
|
|
|
$paginationControl = $this->createPaginationControl($history);
|
|
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$history,
|
|
|
|
|
[
|
2025-01-09 05:21:02 -05:00
|
|
|
'history.event_time desc, history.event_type desc' => $this->translate('Event Time')
|
2021-08-27 07:18:27 -04:00
|
|
|
]
|
|
|
|
|
);
|
2021-09-08 05:08:36 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);
|
2021-08-27 07:18:27 -04:00
|
|
|
|
2020-01-31 08:01:01 -05:00
|
|
|
$history->peekAhead();
|
2021-08-27 07:18:27 -04:00
|
|
|
|
|
|
|
|
$page = $paginationControl->getCurrentPageNumber();
|
|
|
|
|
|
|
|
|
|
if ($page > 1 && ! $compact) {
|
2025-05-06 09:42:50 -04:00
|
|
|
$history->resetOffset();
|
2021-08-27 07:18:27 -04:00
|
|
|
$history->limit($page * $limitControl->getLimit());
|
2019-12-13 10:15:58 -05:00
|
|
|
}
|
2019-11-03 17:20:46 -05:00
|
|
|
|
2021-11-08 10:26:34 -05:00
|
|
|
$history->filter(Filter::lessThanOrEqual('event_time', $before));
|
|
|
|
|
|
2019-11-03 17:20:46 -05:00
|
|
|
yield $this->export($history);
|
|
|
|
|
|
2021-08-27 07:18:27 -04:00
|
|
|
$this->addControl($sortControl);
|
2019-11-03 17:20:46 -05:00
|
|
|
$this->addControl($limitControl);
|
2021-08-27 07:18:27 -04:00
|
|
|
$this->addControl($viewModeSwitcher);
|
2019-11-03 17:20:46 -05:00
|
|
|
|
2025-03-24 08:34:08 -04:00
|
|
|
$historyList = (new LoadMoreObjectList($history->execute()))
|
2021-08-27 07:18:27 -04:00
|
|
|
->setViewMode($viewModeSwitcher->getViewMode())
|
2021-08-23 05:43:54 -04:00
|
|
|
->setPageSize($limitControl->getLimit())
|
2021-08-27 07:18:27 -04:00
|
|
|
->setLoadMoreUrl($url->setParam('before', $before));
|
|
|
|
|
|
2019-12-13 10:15:58 -05:00
|
|
|
if ($compact) {
|
|
|
|
|
$historyList->setPageNumber($page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($compact && $page > 1) {
|
2021-08-23 05:43:54 -04:00
|
|
|
$this->document->addFrom($historyList);
|
2019-12-13 10:15:58 -05:00
|
|
|
} else {
|
|
|
|
|
$this->addContent($historyList);
|
|
|
|
|
}
|
2019-11-03 17:20:46 -05:00
|
|
|
}
|
|
|
|
|
|
2024-11-21 04:23:06 -05:00
|
|
|
public function completeAction(): void
|
|
|
|
|
{
|
2025-01-17 06:00:38 -05:00
|
|
|
$suggestions = (new ObjectSuggestions())
|
|
|
|
|
->setModel(DependencyNode::class)
|
2025-01-20 09:37:41 -05:00
|
|
|
->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup'])
|
2025-01-17 06:00:38 -05:00
|
|
|
->setBaseFilter(Filter::equal("child.service.id", $this->service->id))
|
|
|
|
|
->forRequest($this->getServerRequest());
|
|
|
|
|
|
|
|
|
|
$this->getDocument()->add($suggestions);
|
|
|
|
|
}
|
2024-11-21 04:23:06 -05:00
|
|
|
|
2025-01-17 06:00:38 -05:00
|
|
|
public function childrenCompleteAction(): void
|
|
|
|
|
{
|
2024-11-21 04:23:06 -05:00
|
|
|
$suggestions = (new ObjectSuggestions())
|
|
|
|
|
->setModel(DependencyNode::class)
|
2025-01-20 09:37:41 -05:00
|
|
|
->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup'])
|
2025-01-17 06:00:38 -05:00
|
|
|
->setBaseFilter(Filter::equal("parent.service.id", $this->service->id))
|
2024-11-21 04:23:06 -05:00
|
|
|
->forRequest($this->getServerRequest());
|
|
|
|
|
|
|
|
|
|
$this->getDocument()->add($suggestions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function searchEditorAction(): void
|
|
|
|
|
{
|
|
|
|
|
$editor = $this->createSearchEditor(
|
|
|
|
|
DependencyNode::on($this->getDb()),
|
2025-01-17 06:00:38 -05:00
|
|
|
Url::fromPath(
|
|
|
|
|
'icingadb/service/parents',
|
|
|
|
|
['name' => $this->service->name, 'host.name' => $this->service->host->name]
|
|
|
|
|
),
|
2024-11-21 04:23:06 -05:00
|
|
|
[
|
|
|
|
|
LimitControl::DEFAULT_LIMIT_PARAM,
|
|
|
|
|
SortControl::DEFAULT_SORT_PARAM,
|
|
|
|
|
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
|
|
|
|
|
'name',
|
|
|
|
|
'host.name'
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2025-01-17 06:00:38 -05:00
|
|
|
$this->getDocument()->add($editor);
|
|
|
|
|
$this->setTitle($this->translate('Adjust Filter'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function childrenSearchEditorAction(): void
|
|
|
|
|
{
|
|
|
|
|
$preserveParams = [
|
|
|
|
|
LimitControl::DEFAULT_LIMIT_PARAM,
|
|
|
|
|
SortControl::DEFAULT_SORT_PARAM,
|
|
|
|
|
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
|
|
|
|
|
'name',
|
|
|
|
|
'host.name'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$editor = $this->createSearchEditor(
|
|
|
|
|
DependencyNode::on($this->getDb()),
|
|
|
|
|
Url::fromPath(
|
|
|
|
|
'icingadb/service/children',
|
|
|
|
|
['name' => $this->service->name, 'host.name' => $this->service->host->name]
|
|
|
|
|
),
|
|
|
|
|
$preserveParams
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$editor->setSuggestionUrl(
|
|
|
|
|
Url::fromPath('icingadb/service/children-complete')
|
|
|
|
|
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
|
|
|
|
|
);
|
2024-11-21 04:23:06 -05:00
|
|
|
|
|
|
|
|
$this->getDocument()->add($editor);
|
|
|
|
|
$this->setTitle($this->translate('Adjust Filter'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-01-17 02:40:35 -05:00
|
|
|
* Fetch the dependency nodes of the current service
|
2024-11-21 04:23:06 -05:00
|
|
|
*
|
2025-01-17 02:40:35 -05:00
|
|
|
* @param bool $parents Whether to fetch the parents or the children
|
2024-11-21 04:23:06 -05:00
|
|
|
*
|
|
|
|
|
* @return Query
|
|
|
|
|
*/
|
2025-01-17 02:40:35 -05:00
|
|
|
protected function fetchDependencyNodes(bool $parents = false): Query
|
2024-11-21 04:23:06 -05:00
|
|
|
{
|
|
|
|
|
$query = DependencyNode::on($this->getDb())
|
|
|
|
|
->with([
|
|
|
|
|
'host',
|
|
|
|
|
'host.state',
|
|
|
|
|
'host.state.last_comment',
|
|
|
|
|
'service',
|
|
|
|
|
'service.state',
|
|
|
|
|
'service.state.last_comment',
|
|
|
|
|
'service.host',
|
|
|
|
|
'service.host.state',
|
|
|
|
|
'redundancy_group',
|
|
|
|
|
'redundancy_group.state'
|
|
|
|
|
])
|
|
|
|
|
->filter(Filter::equal(
|
2025-01-17 02:40:35 -05:00
|
|
|
sprintf('%s.service.id', $parents ? 'child' : 'parent'),
|
2024-11-21 04:23:06 -05:00
|
|
|
$this->service->id
|
|
|
|
|
))
|
|
|
|
|
->setResultSetClass(VolatileStateResults::class);
|
|
|
|
|
|
|
|
|
|
$this->applyRestrictions($query);
|
|
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 07:03:20 -05:00
|
|
|
protected function createTabs(): Tabs
|
2019-11-03 17:20:46 -05:00
|
|
|
{
|
2024-12-18 06:53:57 -05:00
|
|
|
if (! Backend::supportsDependencies()) {
|
|
|
|
|
$hasDependencyNode = false;
|
|
|
|
|
} else {
|
|
|
|
|
$hasDependencyNode = DependencyNode::on($this->getDb())
|
2025-01-17 02:40:35 -05:00
|
|
|
->columns([new Expression('1')])
|
|
|
|
|
->filter(Filter::all(
|
|
|
|
|
Filter::equal('service_id', $this->service->id),
|
|
|
|
|
Filter::equal('host_id', $this->service->host_id)
|
|
|
|
|
))
|
|
|
|
|
->disableDefaultSort()
|
|
|
|
|
->first() !== null;
|
2024-12-18 06:53:57 -05:00
|
|
|
}
|
2024-11-21 04:23:06 -05:00
|
|
|
|
2021-05-05 04:29:58 -04:00
|
|
|
$tabs = $this->getTabs()
|
2019-11-03 17:20:46 -05:00
|
|
|
->add('index', [
|
2025-01-09 05:21:02 -05:00
|
|
|
'label' => $this->translate('Service'),
|
2019-11-03 17:20:46 -05:00
|
|
|
'url' => Links::service($this->service, $this->service->host)
|
|
|
|
|
])
|
|
|
|
|
->add('history', [
|
2025-01-09 05:21:02 -05:00
|
|
|
'label' => $this->translate('History'),
|
2019-11-03 17:20:46 -05:00
|
|
|
'url' => ServiceLinks::history($this->service, $this->service->host)
|
|
|
|
|
]);
|
2021-05-05 04:29:58 -04:00
|
|
|
|
2024-12-18 06:53:57 -05:00
|
|
|
if ($hasDependencyNode) {
|
2024-11-21 04:23:06 -05:00
|
|
|
$tabs->add('parents', [
|
|
|
|
|
'label' => $this->translate('Parents'),
|
|
|
|
|
'url' => Url::fromPath(
|
|
|
|
|
'icingadb/service/parents',
|
|
|
|
|
['name' => $this->service->name, 'host.name' => $this->service->host->name]
|
|
|
|
|
)
|
|
|
|
|
])->add('children', [
|
|
|
|
|
'label' => $this->translate('Children'),
|
|
|
|
|
'url' => Url::fromPath(
|
|
|
|
|
'icingadb/service/children',
|
|
|
|
|
['name' => $this->service->name, 'host.name' => $this->service->host->name]
|
|
|
|
|
)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 04:29:58 -04:00
|
|
|
if ($this->hasPermission('icingadb/object/show-source')) {
|
|
|
|
|
$tabs->add('source', [
|
2025-01-09 05:21:02 -05:00
|
|
|
'label' => $this->translate('Source'),
|
2021-05-05 04:29:58 -04:00
|
|
|
'url' => Links::serviceSource($this->service, $this->service->host)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 11:25:54 -04:00
|
|
|
foreach ($this->loadAdditionalTabs() as $name => $tab) {
|
|
|
|
|
$tabs->add($name, $tab + ['urlParams' => [
|
|
|
|
|
'name' => $this->service->name,
|
|
|
|
|
'host.name' => $this->service->host->name
|
|
|
|
|
]]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 04:29:58 -04:00
|
|
|
return $tabs;
|
2019-11-03 17:20:46 -05:00
|
|
|
}
|
|
|
|
|
|
2024-11-21 07:03:20 -05:00
|
|
|
protected function setTitleTab(string $name): void
|
2019-11-03 17:20:46 -05:00
|
|
|
{
|
|
|
|
|
$tab = $this->createTabs()->get($name);
|
|
|
|
|
|
|
|
|
|
if ($tab !== null) {
|
2024-11-21 04:27:38 -05:00
|
|
|
$this->getTabs()->activate($name);
|
2019-11-03 17:20:46 -05:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-16 10:04:44 -05:00
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
protected function fetchCommandTargets(): array
|
2019-12-16 10:04:44 -05:00
|
|
|
{
|
|
|
|
|
return [$this->service];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 02:23:28 -04:00
|
|
|
protected function getCommandTargetsUrl(): Url
|
2019-12-16 10:04:44 -05:00
|
|
|
{
|
|
|
|
|
return Links::service($this->service, $this->service->host);
|
|
|
|
|
}
|
2021-08-17 11:25:54 -04:00
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
protected function getDefaultTabControls(): array
|
2021-08-17 11:25:54 -04:00
|
|
|
{
|
2025-03-19 10:59:29 -04:00
|
|
|
return [new ObjectHeader($this->service)];
|
2021-08-17 11:25:54 -04:00
|
|
|
}
|
2019-10-09 11:26:52 -04:00
|
|
|
}
|