Add moduleInit() method to HostController and ServiceController to check if icingadb is used.

Use moduleInit() to check whether icingadb to be used.
Also use ipl\Stdlib\Filter with $query->filter() instead $query->getSelectBase()->where() in case of icingadb.
This commit is contained in:
raviks789 2022-02-10 16:25:12 +01:00
parent 6552ae2004
commit 6ebaedccf4
2 changed files with 41 additions and 14 deletions

View file

@ -3,28 +3,39 @@
namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\Common\IcingadbDatabase;
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\Web\Url;
use ipl\Stdlib\Filter;
class HostController extends Controller
{
use IcingadbDatabase;
protected $isIcingadb;
protected $explicitIcingadb;
protected function moduleInit()
{
$this->isIcingadb = $this->params->shift('backend') === '_icingadb';
$this->explicitIcingadb = Module::exists('icingadb')
&& IcingadbSupport::useIcingaDbAsBackend();
if (! $this->isIcingadb) {
parent::moduleInit();
}
}
public function showAction()
{
$icingadb = $this->params->shift('icingadb');
if ($icingadb && Module::exists('icingadb')) {
if ($this->isIcingadb || $this->explicitIcingadb) {
$hostName = $this->params->shift('host');
$query = Host::on($this->getDb());
$query = Host::on(IcingaDbObject::fetchDb());
IcingaDbObject::applyIcingaDbRestrictions($query);
$query->getSelectBase()
->where(['host.name = ?' => $hostName]);
$query->filter(Filter::equal('host.name', $hostName));
$host = $query->first();

View file

@ -2,16 +2,31 @@
namespace Icinga\Module\Businessprocess\Controllers;
use Dompdf\Exception;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\Common\IcingadbDatabase;
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\Web\Url;
use ipl\Stdlib\Filter;
class ServiceController extends Controller
{
use IcingadbDatabase;
protected $isIcingadb;
protected $explicitIcingadb;
protected function moduleInit()
{
$this->isIcingadb = $this->params->shift('backend') === '_icingadb';
$this->explicitIcingadb = Module::exists('icingadb')
&& IcingadbSupport::useIcingaDbAsBackend();
if (! $this->isIcingadb) {
parent::moduleInit();
}
}
public function showAction()
{
@ -21,12 +36,13 @@ class ServiceController extends Controller
$hostName = $this->params->shift('host');
$serviceName = $this->params->shift('service');
$query = Service::on($this->getDb())->with('host');
$query = Service::on(IcingaDbObject::fetchDb())->with('host');
IcingaDbObject::applyIcingaDbRestrictions($query);
$query->getSelectBase()
->where(['service.name = ?' => $serviceName])
->where(['service_host.name = ?' => $hostName]);
$query->filter(Filter::all(
Filter::equal('service.name', $serviceName),
Filter::equal('host.name', $hostName)
));
$service = $query->first();