2017-12-04 12:05:07 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Controllers;
|
|
|
|
|
|
2022-02-10 10:25:12 -05:00
|
|
|
use Dompdf\Exception;
|
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\Service;
|
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 ServiceController extends Controller
|
|
|
|
|
{
|
2022-02-10 10:25:12 -05:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2017-12-04 12:05:07 -05:00
|
|
|
public function showAction()
|
|
|
|
|
{
|
2020-05-12 17:20:01 -04:00
|
|
|
$icingadb = $this->params->shift('icingadb');
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2021-11-18 06:19:05 -05:00
|
|
|
if ($icingadb && Module::exists('icingadb')) {
|
2020-05-12 17:20:01 -04:00
|
|
|
$hostName = $this->params->shift('host');
|
|
|
|
|
$serviceName = $this->params->shift('service');
|
|
|
|
|
|
2022-02-10 10:25:12 -05:00
|
|
|
$query = Service::on(IcingaDbObject::fetchDb())->with('host');
|
2021-11-17 10:22:22 -05:00
|
|
|
IcingaDbObject::applyIcingaDbRestrictions($query);
|
2017-12-04 12:05:07 -05:00
|
|
|
|
2022-02-10 10:25:12 -05:00
|
|
|
$query->filter(Filter::all(
|
|
|
|
|
Filter::equal('service.name', $serviceName),
|
|
|
|
|
Filter::equal('host.name', $hostName)
|
|
|
|
|
));
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2021-11-17 04:10:00 -05:00
|
|
|
$service = $query->first();
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2020-04-30 09:55:49 -04:00
|
|
|
$this->params->add('name', $serviceName);
|
|
|
|
|
$this->params->add('host.name', $hostName);
|
2020-04-27 19:08:24 -04:00
|
|
|
|
2021-11-17 04:10:00 -05:00
|
|
|
if ($service !== false) {
|
2020-04-30 09:55:49 -04:00
|
|
|
$this->redirectNow(Url::fromPath('icingadb/service')->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');
|
|
|
|
|
$serviceName = $this->params->get('service');
|
|
|
|
|
|
2020-04-27 19:08:24 -04:00
|
|
|
$query = $this->backend->select()
|
|
|
|
|
->from('servicestatus', array('service_description'))
|
2020-04-30 09:55:49 -04:00
|
|
|
->where('host_name', $hostName)
|
|
|
|
|
->where('service_description', $serviceName);
|
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/service/show')->setParams($this->params));
|
|
|
|
|
}
|
2017-12-04 12:05:07 -05:00
|
|
|
}
|
|
|
|
|
|
2020-04-30 09:55:49 -04:00
|
|
|
$this->view->host = $hostName;
|
|
|
|
|
$this->view->service = $serviceName;
|
2017-12-04 12:05:07 -05:00
|
|
|
}
|
|
|
|
|
}
|