params->shiftRequired('name'); $hostName = $this->params->shiftRequired('host.name'); $query = Service::on($this->getDb())->with([ 'state', 'host', 'host.state' ]); $query->getSelectBase() ->where(['service.name = ?' => $name]) ->where(['service_host.name = ?' => $hostName]); $this->applyMonitoringRestriction($query); /** @var Service $service */ $service = $query->first(); if ($service === null) { throw new NotFoundError($this->translate('Service not found')); } $this->service = $service; $this->setTitleTab($this->getRequest()->getActionName()); } public function getCommandTargetsUrl() { return Links::service($this->service, $this->service->host); } public function fetchCommandTargets() { return [$this->service]; } public function indexAction() { if ($this->service->state->is_overdue) { $this->controls->addAttributes(['class' => 'overdue']); } $this->addControl((new ServiceList([$this->service]))->setViewMode('minimal')); $this->addControl(new QuickActions($this->service)); $this->addContent(new ObjectDetail($this->service)); $this->setAutorefreshInterval(10); } public function commentsAction() { $this->setTitle($this->translate('Comments')); $this->addControl((new ServiceList([$this->service]))->setViewMode('minimal')); $comments = $this->service->comment; $limitControl = $this->createLimitControl(); $paginationControl = $this->createPaginationControl($comments); yield $this->export($comments); $this->addControl($paginationControl); $this->addControl($limitControl); $this->addContent(new CommentList($comments)); $this->setAutorefreshInterval(10); } public function downtimesAction() { $this->setTitle($this->translate('Downtimes')); $this->addControl((new ServiceList([$this->service]))->setViewMode('minimal')); $downtimes = $this->service->downtime; $limitControl = $this->createLimitControl(); $paginationControl = $this->createPaginationControl($downtimes); yield $this->export($downtimes); $this->addControl($paginationControl); $this->addControl($limitControl); $this->addContent(new DowntimeList($downtimes)); $this->setAutorefreshInterval(10); } public function historyAction() { if ($this->service->state->is_overdue) { $this->controls->addAttributes(['class' => 'overdue']); } $this->addControl((new ServiceList([$this->service]))->setViewMode('minimal')); $db = $this->getDb(); $history = History::on($db)->with([ 'host', 'host.service', 'host.state', 'service', 'service.state', 'service.host', 'service.host.state', 'comment', 'downtime', 'notification', 'state' ]); $history ->getSelectBase() ->where([ 'history_host_service.id = ?' => $this->service->id, 'history_service.id = ?' => $this->service->id ], Sql::ANY); $limitControl = $this->createLimitControl(); $paginationControl = $this->createPaginationControl($history); yield $this->export($history); $this->addControl($paginationControl); $this->addControl($limitControl); $this->addContent(new HistoryList($history)); } protected function createTabs() { return $this ->getTabs() ->add('index', [ 'label' => $this->translate('Service'), 'url' => Links::service($this->service, $this->service->host) ]) ->add('history', [ 'label' => $this->translate('History'), 'url' => ServiceLinks::history($this->service, $this->service->host) ]); } protected function setTitleTab($name) { $tab = $this->createTabs()->get($name); if ($tab !== null) { $tab->setActive(); $this->view->title = $tab->getLabel(); } } }