From 9a91854d4ca127dce11585a075dfe27668ca082d Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 7 Jan 2026 11:31:37 +0100 Subject: [PATCH 1/3] Remove `monitoring module` dependency By separating `monitoring` module controllers. - Adjust view-script paths accordingly --- application/controllers/HostController.php | 56 +++------------ application/controllers/IdoHostController.php | 25 +++++++ .../controllers/IdoServiceController.php | 28 ++++++++ application/controllers/ServiceController.php | 68 +++++-------------- .../scripts/{host => ido-host}/show.phtml | 0 .../{service => ido-service}/show.phtml | 0 run.php | 22 ++++++ 7 files changed, 102 insertions(+), 97 deletions(-) create mode 100644 application/controllers/IdoHostController.php create mode 100644 application/controllers/IdoServiceController.php rename application/views/scripts/{host => ido-host}/show.phtml (100%) rename application/views/scripts/{service => ido-service}/show.phtml (100%) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index e22edde..b62aa56 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -2,63 +2,29 @@ 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\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)); - } - } else { - $hostName = $this->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)); - } + if ($host !== null) { + $this->redirectNow(Url::fromPath('icingadb/host')->setParams($this->params)); } $this->view->host = $hostName; diff --git a/application/controllers/IdoHostController.php b/application/controllers/IdoHostController.php new file mode 100644 index 0000000..b52d4fa --- /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)); + } + + $this->view->host = $hostName; + } +} diff --git a/application/controllers/IdoServiceController.php b/application/controllers/IdoServiceController.php new file mode 100644 index 0000000..3f8c247 --- /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)); + } + + $this->view->host = $hostName; + $this->view->service = $serviceName; + } +} diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 15d3f71..d807936 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -2,70 +2,34 @@ 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\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)); - } - } else { - $hostName = $this->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)); - } + if ($service !== null) { + $this->redirectNow(Url::fromPath('icingadb/service')->setParams($this->params)); } $this->view->host = $hostName; diff --git a/application/views/scripts/host/show.phtml b/application/views/scripts/ido-host/show.phtml similarity index 100% rename from application/views/scripts/host/show.phtml rename to application/views/scripts/ido-host/show.phtml diff --git a/application/views/scripts/service/show.phtml b/application/views/scripts/ido-service/show.phtml similarity index 100% rename from application/views/scripts/service/show.phtml rename to application/views/scripts/ido-service/show.phtml 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' + ] + )); +} From d17c4501b2ea882fa569ba7279bf76e6a87c8c3a Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 7 Jan 2026 14:54:35 +0100 Subject: [PATCH 2/3] Use same view script in monitoring and icingadb for `Access Denied` message - Host|ServiceController: The extended class `CompatController` has its own tabs. Therefore, set the view script tabs to null to avoid creating tabs twice. - View-scripts: Add a condition to create tabs only when the `monitoring` backend (ido[Host|Service]Controller) is used. --- application/controllers/HostController.php | 5 +++++ application/controllers/ServiceController.php | 5 +++++ application/views/scripts/ido-host/show.phtml | 2 ++ application/views/scripts/ido-service/show.phtml | 2 ++ 4 files changed, 14 insertions(+) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index b62aa56..886d34d 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Businessprocess\Controllers; use Icinga\Module\Businessprocess\IcingaDbObject; use Icinga\Module\Icingadb\Model\Host; use Icinga\Web\Url; +use ipl\Html\HtmlString; use ipl\Stdlib\Filter; use ipl\Web\Compat\CompatController; @@ -27,6 +28,10 @@ class HostController extends CompatController $this->redirectNow(Url::fromPath('icingadb/host')->setParams($this->params)); } + $this->getTabs()->disableLegacyExtensions(); + $this->view->host = $hostName; + $this->view->tabs = null; // compatController already creates tabs + $this->addContent(HtmlString::create($this->view->render('ido-host/show.phtml'))); } } diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index d807936..241155b 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Businessprocess\Controllers; use Icinga\Module\Businessprocess\IcingaDbObject; use Icinga\Module\Icingadb\Model\Service; use Icinga\Web\Url; +use ipl\Html\HtmlString; use ipl\Stdlib\Filter; use ipl\Web\Compat\CompatController; @@ -32,7 +33,11 @@ class ServiceController extends CompatController $this->redirectNow(Url::fromPath('icingadb/service')->setParams($this->params)); } + $this->getTabs()->disableLegacyExtensions(); + $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'))); } } diff --git a/application/views/scripts/ido-host/show.phtml b/application/views/scripts/ido-host/show.phtml index 413baf2..5cfc3f5 100644 --- a/application/views/scripts/ido-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/ido-service/show.phtml b/application/views/scripts/ido-service/show.phtml index 205b3f7..6da90c9 100644 --- a/application/views/scripts/ido-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)) ?>

From 86b5557c1e11e08e0dd32a357db2f9af751b777b Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 13 Jan 2026 10:08:38 +0100 Subject: [PATCH 3/3] Controllers: Add an `else` case to improve readability --- application/controllers/HostController.php | 12 ++++++------ application/controllers/IdoHostController.php | 4 ++-- application/controllers/IdoServiceController.php | 6 +++--- application/controllers/ServiceController.php | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 886d34d..9daa468 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -26,12 +26,12 @@ class HostController extends CompatController if ($host !== null) { $this->redirectNow(Url::fromPath('icingadb/host')->setParams($this->params)); + } else { + $this->getTabs()->disableLegacyExtensions(); + + $this->view->host = $hostName; + $this->view->tabs = null; // compatController already creates tabs + $this->addContent(HtmlString::create($this->view->render('ido-host/show.phtml'))); } - - $this->getTabs()->disableLegacyExtensions(); - - $this->view->host = $hostName; - $this->view->tabs = null; // compatController already creates tabs - $this->addContent(HtmlString::create($this->view->render('ido-host/show.phtml'))); } } diff --git a/application/controllers/IdoHostController.php b/application/controllers/IdoHostController.php index b52d4fa..db12b5e 100644 --- a/application/controllers/IdoHostController.php +++ b/application/controllers/IdoHostController.php @@ -18,8 +18,8 @@ class IdoHostController extends Controller $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; } - - $this->view->host = $hostName; } } diff --git a/application/controllers/IdoServiceController.php b/application/controllers/IdoServiceController.php index 3f8c247..a869aa1 100644 --- a/application/controllers/IdoServiceController.php +++ b/application/controllers/IdoServiceController.php @@ -20,9 +20,9 @@ class IdoServiceController extends Controller $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; } - - $this->view->host = $hostName; - $this->view->service = $serviceName; } } diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 241155b..2bc31e3 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -31,13 +31,13 @@ class ServiceController extends CompatController if ($service !== null) { $this->redirectNow(Url::fromPath('icingadb/service')->setParams($this->params)); + } else { + $this->getTabs()->disableLegacyExtensions(); + + $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->getTabs()->disableLegacyExtensions(); - - $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'))); } }