icingaweb2-module-businessp.../application/controllers/HostController.php
Ravi Kumar Kempapura Srinivasa 1a0ddfb08b Add IcingaDB MySQL backend in businessprocess
IcingaDB MySQL backend is added to the businessprocess module to obtain information regarding monitored nodes.

ref #276
2022-02-03 16:54:01 +01:00

57 lines
1.7 KiB
PHP

<?php
namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Module\Businessprocess\Common\IcingadbDatabase;
use Icinga\Module\Businessprocess\Web\Controller;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Monitoring\Backend;
use Icinga\Web\Url;
class HostController extends Controller
{
use IcingadbDatabase;
protected $backend;
protected $allParams;
public function showAction()
{
$this->allParams = $this->getAllParams();
$host = $this->params->getRequired('host');
if (array_key_exists('backend', $this->allParams)) {
if ($this->allParams['backend'] === '_icingadb') {
$this->backend = $this->getDb();
}
$query = Host::on($this->backend);
$query->getSelectBase()
->where(['host.name = ?' => $host]);
$this->applyMonitoringRestriction($query);
$queryHost = $query->columns('host.name')->assembleSelect();
$queryHost = $this->backend->select($queryHost)->fetch();
$this->params->add('name', $host);
if ($queryHost !== false) {
$this->redirectNow(Url::fromPath('icingadb/host/index')->setParams($this->params));
}
} else {
$this->backend = Backend::createBackend($this->_getParam('backend'));
$query = $this->backend->select()
->from('hoststatus', array('host_name'))
->where('host_name', $host);
if ($this->applyRestriction('monitoring/filter/objects', $query)->fetchRow() !== false) {
$this->redirectNow(Url::fromPath('monitoring/host/show')->setParams($this->params));
}
}
$this->view->host = $host;
}
}