Remove monitoring module dependency (#492)
Some checks failed
L10n Update / update (push) Has been cancelled
CI / PHP (push) Has been cancelled

fixes #491

The controllers for `icingadb` and the `monitoring` backend have been
separated to remove the unwanted dependency.
Minor adjustments made to the view scripts so that it can be used by
both backends.
This commit is contained in:
Johannes Meyer 2026-01-21 17:02:06 +01:00 committed by GitHub
commit 3ebfcea4bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 117 additions and 98 deletions

View file

@ -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;
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Url;
class IdoHostController extends Controller
{
public function showAction(): void
{
$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));
} else {
$this->view->host = $hostName;
}
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Url;
class IdoServiceController extends Controller
{
public function showAction(): void
{
$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));
} else {
$this->view->host = $hostName;
$this->view->service = $serviceName;
}
}
}

View file

@ -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;
}
}

View file

@ -3,9 +3,11 @@
/** @var \Icinga\Web\Widget\Tabs $tabs */
/** @var string $host */
?>
<?php if ($tabs): ?>
<div class="controls">
<?= $tabs->showOnlyCloseButton() ?>
</div>
<?php endif ?>
<div class="content restricted">
<h1><?= $this->translate('Access Denied') ?></h1>
<p><?= sprintf($this->translate('You are lacking permission to access host "%s".'), $this->escape($host)) ?></p>

View file

@ -4,9 +4,11 @@
/** @var string $host */
/** @var string $service */
?>
<?php if ($tabs): ?>
<div class="controls">
<?= $tabs->showOnlyCloseButton() ?>
</div>
<?php endif ?>
<div class="content restricted">
<h1><?= $this->escape($this->translate('Access Denied')) ?></h1>
<p><?= $this->escape(sprintf($this->translate('You are lacking permission to access service "%s" on host "%s"'), $service, $host)) ?></p>

22
run.php
View file

@ -1,5 +1,7 @@
<?php
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
$this->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'
]
));
}