summaryrefslogtreecommitdiffstats
path: root/application/controllers/HostsController.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:21:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:21:16 +0000
commit2e582fe0b8b6a8e67982ddb84935db1bd3b401fe (patch)
treedd511b321f308264952cffb005a4288ea4e478e6 /application/controllers/HostsController.php
parentInitial commit. (diff)
downloadicingaweb2-module-graphite-2e582fe0b8b6a8e67982ddb84935db1bd3b401fe.tar.xz
icingaweb2-module-graphite-2e582fe0b8b6a8e67982ddb84935db1bd3b401fe.zip
Adding upstream version 1.2.2.upstream/1.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/HostsController.php')
-rw-r--r--application/controllers/HostsController.php112
1 files changed, 112 insertions, 0 deletions
diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php
new file mode 100644
index 0000000..f77281a
--- /dev/null
+++ b/application/controllers/HostsController.php
@@ -0,0 +1,112 @@
+<?php
+
+/* Icinga Graphite Web | (c) 2022 Icinga GmbH | GPLv2 */
+
+namespace Icinga\Module\Graphite\Controllers;
+
+use GuzzleHttp\Psr7\ServerRequest;
+use Icinga\Module\Graphite\Web\Controller\IcingadbGraphiteController;
+use Icinga\Module\Graphite\Web\Controller\TimeRangePickerTrait;
+use Icinga\Module\Graphite\Web\Widget\IcingadbGraphs;
+use Icinga\Module\Icingadb\Model\Host;
+use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
+use Icinga\Web\Url;
+use ipl\Html\HtmlString;
+use ipl\Stdlib\Filter;
+use ipl\Web\Control\LimitControl;
+use ipl\Web\Control\SortControl;
+
+class HostsController extends IcingadbGraphiteController
+{
+ use TimeRangePickerTrait;
+
+ public function indexAction()
+ {
+ if (! $this->useIcingadbAsBackend) {
+ $params = urldecode($this->params->get('legacyParams'));
+ $this->redirectNow(Url::fromPath('graphite/list/hosts')->setQueryString($params));
+ }
+
+ // shift graph params to avoid exception
+ $graphRange = $this->params->shift('graph_range');
+ $baseFilter = $graphRange ? Filter::equal('graph_range', $graphRange) : null;
+ foreach ($this->graphParams as $param) {
+ $this->params->shift($param);
+ }
+
+ $this->addTitleTab(t('Hosts'));
+
+ $db = $this->getDb();
+
+ $hosts = Host::on($db)->with('state');
+ $hosts->filter(Filter::like('state.performance_data', '*'));
+
+ $this->applyRestrictions($hosts);
+
+ $limitControl = $this->createLimitControl();
+ $paginationControl = $this->createPaginationControl($hosts);
+ $sortControl = $this->createSortControl($hosts, ['host.display_name' => t('Hostname')]);
+
+ $searchBar = $this->createSearchBar(
+ $hosts,
+ array_merge(
+ [$limitControl->getLimitParam(), $sortControl->getSortParam()],
+ $this->graphParams
+ )
+ );
+
+ if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
+ if ($searchBar->hasBeenSubmitted()) {
+ $filter = $this->getFilter();
+ } else {
+ $this->addControl($searchBar);
+ $this->sendMultipartUpdate();
+ return;
+ }
+ } else {
+ $filter = $searchBar->getFilter();
+ }
+
+ $hosts->filter($filter);
+
+ $this->addControl($paginationControl);
+ $this->addControl($sortControl);
+ $this->addControl($limitControl);
+ $this->addControl($searchBar);
+ $this->handleTimeRangePickerRequest();
+ $this->addControl(HtmlString::create($this->renderTimeRangePicker($this->view)));
+
+ $this->addContent(
+ (new IcingadbGraphs($hosts->execute()))
+ ->setBaseFilter($baseFilter)
+ );
+
+ if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
+ $this->sendMultipartUpdate();
+ }
+
+ $this->setAutorefreshInterval(30);
+ }
+
+ public function completeAction()
+ {
+ $suggestions = new ObjectSuggestions();
+ $suggestions->setModel(Host::class);
+ $suggestions->forRequest(ServerRequest::fromGlobals());
+ $this->getDocument()->add($suggestions);
+ }
+
+ public function searchEditorAction()
+ {
+ $editor = $this->createSearchEditor(
+ Host::on($this->getDb()),
+ array_merge(
+ [LimitControl::DEFAULT_LIMIT_PARAM, SortControl::DEFAULT_SORT_PARAM],
+ $this->graphParams
+ )
+ );
+
+ $this->getDocument()->add($editor);
+ $this->setTitle(t('Adjust Filter'));
+ }
+}