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