diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index e22edde..9daa468 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -2,65 +2,36 @@ namespace Icinga\Module\Businessprocess\Controllers; -use Icinga\Application\Modules\Module; use Icinga\Module\Businessprocess\IcingaDbObject; -use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Icingadb\Model\Host; -use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\DataView\DataView; use Icinga\Web\Url; +use ipl\Html\HtmlString; use ipl\Stdlib\Filter; +use ipl\Web\Compat\CompatController; -class HostController extends Controller +class HostController extends CompatController { - /** - * True if business process prefers to use icingadb as backend for it's nodes - * - * @var bool - */ - protected $isIcingadbPreferred; - - protected function moduleInit() + public function showAction(): void { - $this->isIcingadbPreferred = Module::exists('icingadb') - && ! $this->params->has('backend') - && IcingadbSupport::useIcingaDbAsBackend(); + $hostName = $this->params->shift('host'); - if (! $this->isIcingadbPreferred) { - parent::moduleInit(); - } - } + $query = Host::on(IcingaDbObject::fetchDb()); + IcingaDbObject::applyIcingaDbRestrictions($query); - public function showAction() - { - if ($this->isIcingadbPreferred) { - $hostName = $this->params->shift('host'); + $query->filter(Filter::equal('host.name', $hostName)); - $query = Host::on(IcingaDbObject::fetchDb()); - IcingaDbObject::applyIcingaDbRestrictions($query); + $host = $query->first(); - $query->filter(Filter::equal('host.name', $hostName)); + $this->params->add('name', $hostName); - $host = $query->first(); - - $this->params->add('name', $hostName); - - if ($host !== null) { - $this->redirectNow(Url::fromPath('icingadb/host')->setParams($this->params)); - } + if ($host !== null) { + $this->redirectNow(Url::fromPath('icingadb/host')->setParams($this->params)); } else { - $hostName = $this->params->get('host'); + $this->getTabs()->disableLegacyExtensions(); - $query = $this->backend->select() - ->from('hoststatus', array('host_name')) - ->where('host_name', $hostName); - - $this->applyRestriction('monitoring/filter/objects', $query); - if ($query->fetchRow() !== false) { - $this->redirectNow(Url::fromPath('monitoring/host/show')->setParams($this->params)); - } + $this->view->host = $hostName; + $this->view->tabs = null; // compatController already creates tabs + $this->addContent(HtmlString::create($this->view->render('ido-host/show.phtml'))); } - - $this->view->host = $hostName; } } diff --git a/application/controllers/IdoHostController.php b/application/controllers/IdoHostController.php new file mode 100644 index 0000000..db12b5e --- /dev/null +++ b/application/controllers/IdoHostController.php @@ -0,0 +1,25 @@ +params->get('host'); + + $query = $this->backend->select() + ->from('hoststatus', array('host_name')) + ->where('host_name', $hostName); + + $this->applyRestriction('monitoring/filter/objects', $query); + if ($query->fetchRow() !== false) { + $this->redirectNow(Url::fromPath('monitoring/host/show')->setParams($this->params)); + } else { + $this->view->host = $hostName; + } + } +} diff --git a/application/controllers/IdoServiceController.php b/application/controllers/IdoServiceController.php new file mode 100644 index 0000000..a869aa1 --- /dev/null +++ b/application/controllers/IdoServiceController.php @@ -0,0 +1,28 @@ +params->get('host'); + $serviceName = $this->params->get('service'); + + $query = $this->backend->select() + ->from('servicestatus', array('service_description')) + ->where('host_name', $hostName) + ->where('service_description', $serviceName); + + $this->applyRestriction('monitoring/filter/objects', $query); + if ($query->fetchRow() !== false) { + $this->redirectNow(Url::fromPath('monitoring/service/show')->setParams($this->params)); + } else { + $this->view->host = $hostName; + $this->view->service = $serviceName; + } + } +} diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 15d3f71..2bc31e3 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -2,73 +2,42 @@ namespace Icinga\Module\Businessprocess\Controllers; -use Icinga\Application\Modules\Module; use Icinga\Module\Businessprocess\IcingaDbObject; -use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Icingadb\Model\Service; -use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\DataView\DataView; use Icinga\Web\Url; +use ipl\Html\HtmlString; use ipl\Stdlib\Filter; +use ipl\Web\Compat\CompatController; -class ServiceController extends Controller +class ServiceController extends CompatController { - /** - * True if business process prefers to use icingadb as backend for it's nodes - * - * @var bool - */ - protected $isIcingadbPreferred; - - protected function moduleInit() + public function showAction(): void { - $this->isIcingadbPreferred = Module::exists('icingadb') - && ! $this->params->has('backend') - && IcingadbSupport::useIcingaDbAsBackend(); + $hostName = $this->params->shift('host'); + $serviceName = $this->params->shift('service'); - if (! $this->isIcingadbPreferred) { - parent::moduleInit(); - } - } + $query = Service::on(IcingaDbObject::fetchDb()); + IcingaDbObject::applyIcingaDbRestrictions($query); - public function showAction() - { - if ($this->isIcingadbPreferred) { - $hostName = $this->params->shift('host'); - $serviceName = $this->params->shift('service'); + $query->filter(Filter::all( + Filter::equal('service.name', $serviceName), + Filter::equal('host.name', $hostName) + )); - $query = Service::on(IcingaDbObject::fetchDb()); - IcingaDbObject::applyIcingaDbRestrictions($query); + $service = $query->first(); - $query->filter(Filter::all( - Filter::equal('service.name', $serviceName), - Filter::equal('host.name', $hostName) - )); + $this->params->add('name', $serviceName); + $this->params->add('host.name', $hostName); - $service = $query->first(); - - $this->params->add('name', $serviceName); - $this->params->add('host.name', $hostName); - - if ($service !== null) { - $this->redirectNow(Url::fromPath('icingadb/service')->setParams($this->params)); - } + if ($service !== null) { + $this->redirectNow(Url::fromPath('icingadb/service')->setParams($this->params)); } else { - $hostName = $this->params->get('host'); - $serviceName = $this->params->get('service'); + $this->getTabs()->disableLegacyExtensions(); - $query = $this->backend->select() - ->from('servicestatus', array('service_description')) - ->where('host_name', $hostName) - ->where('service_description', $serviceName); - - $this->applyRestriction('monitoring/filter/objects', $query); - if ($query->fetchRow() !== false) { - $this->redirectNow(Url::fromPath('monitoring/service/show')->setParams($this->params)); - } + $this->view->host = $hostName; + $this->view->service = $serviceName; + $this->view->tabs = null; // compatController already creates tabs + $this->addContent(HtmlString::create($this->view->render('ido-service/show.phtml'))); } - - $this->view->host = $hostName; - $this->view->service = $serviceName; } } diff --git a/application/views/scripts/host/show.phtml b/application/views/scripts/ido-host/show.phtml similarity index 93% rename from application/views/scripts/host/show.phtml rename to application/views/scripts/ido-host/show.phtml index 413baf2..5cfc3f5 100644 --- a/application/views/scripts/host/show.phtml +++ b/application/views/scripts/ido-host/show.phtml @@ -3,9 +3,11 @@ /** @var \Icinga\Web\Widget\Tabs $tabs */ /** @var string $host */ ?> +
showOnlyCloseButton() ?>
+

translate('Access Denied') ?>

translate('You are lacking permission to access host "%s".'), $this->escape($host)) ?>

diff --git a/application/views/scripts/service/show.phtml b/application/views/scripts/ido-service/show.phtml similarity index 94% rename from application/views/scripts/service/show.phtml rename to application/views/scripts/ido-service/show.phtml index 205b3f7..6da90c9 100644 --- a/application/views/scripts/service/show.phtml +++ b/application/views/scripts/ido-service/show.phtml @@ -4,9 +4,11 @@ /** @var string $host */ /** @var string $service */ ?> +
showOnlyCloseButton() ?>
+

escape($this->translate('Access Denied')) ?>

escape(sprintf($this->translate('You are lacking permission to access service "%s" on host "%s"'), $service, $host)) ?>

diff --git a/run.php b/run.php index 6cb81f8..7c58106 100644 --- a/run.php +++ b/run.php @@ -1,5 +1,7 @@ provideHook('monitoring/HostActions'); $this->provideHook('monitoring/ServiceActions'); $this->provideHook('monitoring/DetailviewExtension'); @@ -8,3 +10,23 @@ $this->provideHook('icingadb/ServiceActions'); $this->provideHook('icingadb/icingadbSupport'); $this->provideHook('icingadb/ServiceDetailExtension'); //$this->provideHook('director/shipConfigFiles'); + +if (! static::exists('icingadb') || ! IcingadbSupport::useIcingaDbAsBackend()) { + $this->addRoute('businessprocess/host/show', new Zend_Controller_Router_Route_Static( + 'businessprocess/host/show', + [ + 'controller' => 'ido-host', + 'action' => 'show', + 'module' => 'businessprocess' + ] + )); + + $this->addRoute('businessprocess/service/show', new Zend_Controller_Router_Route_Static( + 'businessprocess/service/show', + [ + 'controller' => 'ido-service', + 'action' => 'show', + 'module' => 'businessprocess' + ] + )); +}