icingadb-web/application/controllers/ServiceController.php

64 lines
1.7 KiB
PHP
Raw Normal View History

2019-10-09 11:26:52 -04:00
<?php
namespace Icinga\Module\Eagle\Controllers;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Eagle\Common\CommandActions;
use Icinga\Module\Eagle\Common\Links;
2019-10-09 11:26:52 -04:00
use Icinga\Module\Eagle\Model\Service;
use Icinga\Module\Eagle\Web\Controller;
2019-11-03 09:34:09 -05:00
use Icinga\Module\Eagle\Widget\Detail\ObjectDetail;
use Icinga\Module\Eagle\Widget\Detail\QuickActions;
use Icinga\Module\Eagle\Widget\ServiceList;
2019-10-09 11:26:52 -04:00
class ServiceController extends Controller
{
use CommandActions;
/** @var Service The service object */
protected $service;
public function init()
2019-10-09 11:26:52 -04:00
{
$this->setTitle($this->translate('Service'));
2019-10-09 11:26:52 -04:00
$name = $this->params->shiftRequired('name');
$hostName = $this->params->shiftRequired('host.name');
2019-10-09 11:26:52 -04:00
$query = Service::on($this->getDb())->with([
'state',
2019-10-14 09:13:39 -04:00
'host',
'host.state'
2019-10-09 11:26:52 -04:00
]);
$query->getSelectBase()
->where(['service.name = ?' => $name])
->where(['service_host.name = ?' => $hostName]);
2019-10-09 11:26:52 -04:00
/** @var Service $service */
$service = $query->first();
if ($service === null) {
throw new NotFoundError($this->translate('Service not found'));
}
$this->service = $service;
}
public function getCommandTargetsUrl()
{
return Links::service($this->service, $this->service->host);
}
public function fetchCommandTargets()
{
return [$this->service];
}
public function indexAction()
{
2019-11-03 09:34:09 -05:00
$this->addControl((new ServiceList([$this->service]))->setViewMode('compact'));
$this->addControl(new QuickActions($this->service));
$this->addContent(new ObjectDetail($this->service));
2019-10-09 11:26:52 -04:00
}
}