From 23be945fd2810ee82e3a23cbcd2352c9bda43d4f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:44:18 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- application/controllers/ListController.php | 192 +++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 application/controllers/ListController.php (limited to 'application/controllers/ListController.php') diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php new file mode 100644 index 0000000..46d8321 --- /dev/null +++ b/application/controllers/ListController.php @@ -0,0 +1,192 @@ +getTabs() + ->extend(new OutputFormat([OutputFormat::TYPE_CSV, OutputFormat::TYPE_JSON])) + ->extend(new DashboardAction()) + ->extend(new MenuAction()); + } + + public function hostsAction() + { + if ($this->useIcingadbAsBackend) { + $legacyParams = urlencode($this->params->toString()); + $params = QueryString::render( + UrlMigrator::transformFilter( + QueryString::parse($this->params->toString()) + ) + ); + + $url = Url::fromPath('graphite/hosts') + ->setQueryString($params); + + if ($legacyParams) { + $url->setParam('legacyParams', $legacyParams); + } + + $this->redirectNow($url); + } + + $this->addTitleTab( + 'hosts', + mt('monitoring', 'Hosts'), + mt('monitoring', 'List hosts') + ); + + $hostsQuery = $this->applyMonitoringRestriction( + $this->backend->select()->from('hoststatus', ['host_name']) + ); + + $hostsQuery->applyFilter(Filter::expression('host_perfdata', '!=', '')); + + $this->view->baseUrl = $baseUrl = Url::fromPath('monitoring/host/show'); + TimeRangePickerTools::copyAllRangeParameters( + $baseUrl->getParams(), + $this->getRequest()->getUrl()->getParams() + ); + + $this->filterQuery($hostsQuery); + $this->setupPaginationControl($hostsQuery); + $this->setupLimitControl(); + $this->setupSortControl(['host_display_name' => mt('monitoring', 'Hostname')], $hostsQuery); + + $hosts = []; + foreach ($hostsQuery->peekAhead($this->view->compact) as $host) { + $host = new Host($this->backend, $host->host_name); + $host->fetch(); + $hosts[] = $host; + } + + $this->handleTimeRangePickerRequest(); + $this->view->timeRangePicker = $this->renderTimeRangePicker($this->view); + $this->view->hosts = $hosts; + $this->view->hasMoreHosts = ! $this->view->compact && $hostsQuery->hasMore(); + + $this->setAutorefreshInterval(30); + } + + public function servicesAction() + { + if ($this->useIcingadbAsBackend) { + $legacyParams = urlencode($this->params->toString()); + $params = QueryString::render( + UrlMigrator::transformFilter( + QueryString::parse($this->params->toString()) + ) + ); + + $url = Url::fromPath('graphite/services') + ->setQueryString($params); + + if ($legacyParams) { + $url->setParam('legacyParams', $legacyParams); + } + + $this->redirectNow($url); + } + + $this->addTitleTab( + 'services', + mt('monitoring', 'Services'), + mt('monitoring', 'List services') + ); + + $servicesQuery = $this->applyMonitoringRestriction( + $this->backend->select()->from('servicestatus', ['host_name', 'service_description']) + ); + + $servicesQuery->applyFilter(Filter::expression('service_perfdata', '!=', '')); + + $this->view->hostBaseUrl = $hostBaseUrl = Url::fromPath('monitoring/host/show'); + TimeRangePickerTools::copyAllRangeParameters( + $hostBaseUrl->getParams(), + $this->getRequest()->getUrl()->getParams() + ); + + $this->view->serviceBaseUrl = $serviceBaseUrl = Url::fromPath('monitoring/service/show'); + TimeRangePickerTools::copyAllRangeParameters( + $serviceBaseUrl->getParams(), + $this->getRequest()->getUrl()->getParams() + ); + + $this->filterQuery($servicesQuery); + $this->setupPaginationControl($servicesQuery); + $this->setupLimitControl(); + $this->setupSortControl([ + 'service_display_name' => mt('monitoring', 'Service Name'), + 'host_display_name' => mt('monitoring', 'Hostname') + ], $servicesQuery); + + $services = []; + foreach ($servicesQuery->peekAhead($this->view->compact) as $service) { + $service = new Service($this->backend, $service->host_name, $service->service_description); + $service->fetch(); + $services[] = $service; + } + + $this->handleTimeRangePickerRequest(); + $this->view->timeRangePicker = $this->renderTimeRangePicker($this->view); + $this->view->services = $services; + $this->view->hasMoreServices = ! $this->view->compact && $servicesQuery->hasMore(); + + $this->setAutorefreshInterval(30); + } + + /** + * Apply filters on a DataView + * + * @param DataView $dataView The DataView to apply filters on + */ + protected function filterQuery(DataView $dataView) + { + $this->setupFilterControl( + $dataView, + null, + null, + array_merge( + ['format', 'stateType', 'addColumns', 'problems', 'graphs_limit'], + TimeRangePickerTools::getAllRangeParameters() + ) + ); + $this->handleFormatRequest($dataView); + } + + /** + * Add title tab + * + * @param string $action + * @param string $title + * @param string $tip + */ + protected function addTitleTab($action, $title, $tip) + { + $this->getTabs()->add($action, [ + 'title' => $tip, + 'label' => $title, + 'url' => Url::fromRequest(), + 'active' => true + ]); + } +} -- cgit v1.2.3