Remove monitoring module dependency

By separating `monitoring` module controllers.

- Adjust view-script paths accordingly
This commit is contained in:
Sukhwinder Dhillon 2026-01-07 11:31:37 +01:00
parent b756147764
commit 9a91854d4c
7 changed files with 102 additions and 97 deletions

View file

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

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));
}
$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));
}
$this->view->host = $hostName;
$this->view->service = $serviceName;
}
}

View file

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

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'
]
));
}