icingaweb2-module-businessp.../application/controllers/HostController.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2017-12-04 12:05:07 -05:00
<?php
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;
2017-12-04 12:05:07 -05:00
use Icinga\Web\Url;
use ipl\Stdlib\Filter;
2017-12-04 12:05:07 -05:00
class HostController extends Controller
{
protected $isIcingadb;
protected $explicitIcingadb;
protected function moduleInit()
2017-12-04 12:05:07 -05:00
{
$this->isIcingadb = $this->params->shift('backend') === '_icingadb';
$this->explicitIcingadb = Module::exists('icingadb')
&& IcingadbSupport::useIcingaDbAsBackend();
if (! $this->isIcingadb) {
parent::moduleInit();
}
}
public function showAction()
{
if ($this->isIcingadb || $this->explicitIcingadb) {
$hostName = $this->params->shift('host');
$query = Host::on(IcingaDbObject::fetchDb());
IcingaDbObject::applyIcingaDbRestrictions($query);
$query->filter(Filter::equal('host.name', $hostName));
2017-12-04 12:05:07 -05:00
$host = $query->first();
$this->params->add('name', $hostName);
if ($host !== false) {
$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);
2017-12-04 12:05:07 -05:00
if ($this->applyRestriction('monitoring/filter/objects', $query)->fetchRow() !== false) {
$this->redirectNow(Url::fromPath('monitoring/host/show')->setParams($this->params));
}
2017-12-04 12:05:07 -05:00
}
$this->view->host = $hostName;
2017-12-04 12:05:07 -05:00
}
}