2017-12-04 12:05:07 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Controllers;
|
|
|
|
|
|
2021-11-18 06:19:05 -05:00
|
|
|
use Icinga\Application\Modules\Module;
|
2021-11-17 10:22:22 -05:00
|
|
|
use Icinga\Module\Businessprocess\IcingaDbObject;
|
2022-02-10 10:25:12 -05:00
|
|
|
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
2020-04-27 19:08:24 -04:00
|
|
|
use Icinga\Module\Icingadb\Model\Host;
|
2020-04-30 09:55:49 -04:00
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2017-12-04 12:05:07 -05:00
|
|
|
use Icinga\Web\Url;
|
2022-02-10 10:25:12 -05:00
|
|
|
use ipl\Stdlib\Filter;
|
2017-12-04 12:05:07 -05:00
|
|
|
|
|
|
|
|
class HostController extends Controller
|
|
|
|
|
{
|
2022-02-15 04:24:58 -05:00
|
|
|
/**
|
|
|
|
|
* True if business process prefers to use icingadb as backend for it's nodes
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $isIcingadbPreferred;
|
2022-02-10 10:25:12 -05:00
|
|
|
|
|
|
|
|
protected function moduleInit()
|
2017-12-04 12:05:07 -05:00
|
|
|
{
|
2022-02-15 04:24:58 -05:00
|
|
|
$this->isIcingadbPreferred = Module::exists('icingadb')
|
|
|
|
|
&& ! $this->params->has('backend')
|
2022-02-10 10:25:12 -05:00
|
|
|
&& IcingadbSupport::useIcingaDbAsBackend();
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2022-02-15 04:24:58 -05:00
|
|
|
if (! $this->isIcingadbPreferred) {
|
2022-02-10 10:25:12 -05:00
|
|
|
parent::moduleInit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showAction()
|
|
|
|
|
{
|
2022-02-15 04:24:58 -05:00
|
|
|
if ($this->isIcingadbPreferred) {
|
2020-05-12 17:20:01 -04:00
|
|
|
$hostName = $this->params->shift('host');
|
|
|
|
|
|
2022-02-10 10:25:12 -05:00
|
|
|
$query = Host::on(IcingaDbObject::fetchDb());
|
2021-11-17 10:22:22 -05:00
|
|
|
IcingaDbObject::applyIcingaDbRestrictions($query);
|
2021-11-17 04:10:00 -05:00
|
|
|
|
2022-02-10 10:25:12 -05:00
|
|
|
$query->filter(Filter::equal('host.name', $hostName));
|
2017-12-04 12:05:07 -05:00
|
|
|
|
2021-11-17 04:10:00 -05:00
|
|
|
$host = $query->first();
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2020-04-30 09:55:49 -04:00
|
|
|
$this->params->add('name', $hostName);
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2021-11-17 04:10:00 -05:00
|
|
|
if ($host !== false) {
|
2020-04-30 09:55:49 -04:00
|
|
|
$this->redirectNow(Url::fromPath('icingadb/host')->setParams($this->params));
|
2020-04-27 19:08:24 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2020-05-12 17:20:01 -04:00
|
|
|
$hostName = $this->params->get('host');
|
|
|
|
|
|
2020-04-27 19:08:24 -04:00
|
|
|
$query = $this->backend->select()
|
|
|
|
|
->from('hoststatus', array('host_name'))
|
2020-04-30 09:55:49 -04:00
|
|
|
->where('host_name', $hostName);
|
2017-12-04 12:05:07 -05:00
|
|
|
|
2020-04-27 19:08:24 -04: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
|
|
|
}
|
|
|
|
|
|
2020-04-30 09:55:49 -04:00
|
|
|
$this->view->host = $hostName;
|
2017-12-04 12:05:07 -05:00
|
|
|
}
|
|
|
|
|
}
|