diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:21 +0000 |
commit | 1ac4a2050c8076eb96e07e83721ebc9db864db94 (patch) | |
tree | da9b32212bf99154450a7668f61a75f65617a9fa /library/Toplevelview/Web | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-toplevelview-1ac4a2050c8076eb96e07e83721ebc9db864db94.tar.xz icingaweb2-module-toplevelview-1ac4a2050c8076eb96e07e83721ebc9db864db94.zip |
Adding upstream version 0.3.3.upstream/0.3.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Toplevelview/Web')
-rw-r--r-- | library/Toplevelview/Web/Controller.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/library/Toplevelview/Web/Controller.php b/library/Toplevelview/Web/Controller.php new file mode 100644 index 0000000..c010cd7 --- /dev/null +++ b/library/Toplevelview/Web/Controller.php @@ -0,0 +1,53 @@ +<?php +/* Copyright (C) 2017 Icinga Development Team <info@icinga.com> */ + +namespace Icinga\Module\Toplevelview\Web; + +use Icinga\Application\Icinga; +use Icinga\Exception\ConfigurationError; +use Icinga\Exception\IcingaException; +use Icinga\Module\Monitoring\Backend\MonitoringBackend; +use Icinga\Web\Controller as IcingaController; + +class Controller extends IcingaController +{ + /** @var MonitoringBackend */ + protected $monitoringBackend; + + public function init() + { + parent::init(); + + if (! extension_loaded('yaml')) { + throw new ConfigurationError('You need the PHP extension "yaml" in order to use TopLevelView'); + } + } + + /** + * Retrieves the Icinga MonitoringBackend + * + * @param string|null $name + * + * @return MonitoringBackend + * @throws IcingaException When monitoring is not enabled + */ + protected function monitoringBackend($name = null) + { + if ($this->monitoringBackend === null) { + if (! Icinga::app()->getModuleManager()->hasEnabled('monitoring')) { + throw new IcingaException('The module "monitoring" must be enabled and configured!'); + } + $this->monitoringBackend = MonitoringBackend::instance($name); + } + return $this->monitoringBackend; + } + + protected function setViewScript($name, $controller = null) + { + if ($controller !== null) { + $name = sprintf('%s/%s', $controller, $name); + } + $this->_helper->viewRenderer->setNoController(true); + $this->_helper->viewRenderer->setScriptAction($name); + } +} |