icingadb-web/application/controllers/HostController.php
2019-11-03 21:52:41 +01:00

58 lines
1.4 KiB
PHP

<?php
namespace Icinga\Module\Eagle\Controllers;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Eagle\Common\CommandActions;
use Icinga\Module\Eagle\Common\Links;
use Icinga\Module\Eagle\Model\Host;
use Icinga\Module\Eagle\Web\Controller;
use Icinga\Module\Eagle\Widget\Detail\ObjectDetail;
use Icinga\Module\Eagle\Widget\Detail\QuickActions;
use Icinga\Module\Eagle\Widget\HostList;
use ipl\Web\Url;
class HostController extends Controller
{
use CommandActions;
/** @var Host The host object */
protected $host;
public function init()
{
$this->setTitle($this->translate('Host'));
$name = $this->params->shiftRequired('name');
$query = Host::on($this->getDb())->with('state');
$query->getSelectBase()
->where(['name = ?' => $name]);
/** @var Host $host */
$host = $query->first();
if ($host === null) {
throw new NotFoundError($this->translate('Host not found'));
}
$this->host = $host;
}
protected function getCommandTargetsUrl()
{
return Links::host($this->host);
}
protected function fetchCommandTargets()
{
return [$this->host];
}
public function indexAction()
{
$this->addControl((new HostList([$this->host]))->setViewMode('compact'));
$this->addControl(new QuickActions($this->host));
$this->addContent(new ObjectDetail($this->host));
}
}