mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 07:14:35 +02:00
monitoring: Reduce DowntimeController complexity
This commit is contained in:
parent
a50d2110be
commit
b82306e2bb
@ -18,17 +18,10 @@ class DowntimeController extends Controller
|
|||||||
/**
|
/**
|
||||||
* The fetched downtime
|
* The fetched downtime
|
||||||
*
|
*
|
||||||
* @var stdClass
|
* @var object
|
||||||
*/
|
*/
|
||||||
protected $downtime;
|
protected $downtime;
|
||||||
|
|
||||||
/**
|
|
||||||
* If the downtime is a service or not
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
protected $isService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the downtime matching the given id and add tabs
|
* Fetch the downtime matching the given id and add tabs
|
||||||
*/
|
*/
|
||||||
@ -59,29 +52,20 @@ class DowntimeController extends Controller
|
|||||||
))->where('downtime_internal_id', $downtimeId);
|
))->where('downtime_internal_id', $downtimeId);
|
||||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||||
|
|
||||||
$this->downtime = $query->getQuery()->fetchRow();
|
if (false === $this->downtime = $query->fetchRow()) {
|
||||||
if ($this->downtime === false) {
|
|
||||||
$this->httpNotFound($this->translate('Downtime not found'));
|
$this->httpNotFound($this->translate('Downtime not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->downtime->service_description)) {
|
$this->getTabs()->add(
|
||||||
$this->isService = true;
|
'downtime',
|
||||||
} else {
|
array(
|
||||||
$this->isService = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->getTabs()
|
'icon' => 'plug',
|
||||||
->add(
|
'label' => $this->translate('Downtime'),
|
||||||
'downtime',
|
'title' => $this->translate('Display detailed information about a downtime.'),
|
||||||
array(
|
'url' =>'monitoring/downtimes/show'
|
||||||
'title' => $this->translate(
|
)
|
||||||
'Display detailed information about a downtime.'
|
)->activate('downtime')->extend(new DashboardAction());
|
||||||
),
|
|
||||||
'icon' => 'plug',
|
|
||||||
'label' => $this->translate('Downtime'),
|
|
||||||
'url' =>'monitoring/downtimes/show'
|
|
||||||
)
|
|
||||||
)->activate('downtime')->extend(new DashboardAction());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,52 +73,27 @@ class DowntimeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function showAction()
|
public function showAction()
|
||||||
{
|
{
|
||||||
|
$isService = isset($this->downtime->service_description);
|
||||||
$this->view->downtime = $this->downtime;
|
$this->view->downtime = $this->downtime;
|
||||||
$this->view->isService = $this->isService;
|
$this->view->isService = $isService;
|
||||||
$this->view->stateName = isset($this->downtime->service_description) ?
|
|
||||||
Service::getStateText($this->downtime->service_state) :
|
|
||||||
Host::getStateText($this->downtime->host_state);
|
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
||||||
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
|
$this->view->showHostLink = Url::fromPath('monitoring/host/show')->setParam('host', $this->downtime->host_name);
|
||||||
->setParam('host', $this->downtime->host_name);
|
|
||||||
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
||||||
->setParam('host', $this->downtime->host_name)
|
->setParam('host', $this->downtime->host_name)
|
||||||
->setParam('service', $this->downtime->service_description);
|
->setParam('service', $this->downtime->service_description);
|
||||||
|
$this->view->stateName = $isService ? Service::getStateText($this->downtime->service_state)
|
||||||
|
: Host::getStateText($this->downtime->host_state);
|
||||||
|
|
||||||
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
$form = new DeleteDowntimeCommandForm();
|
||||||
$this->view->delDowntimeForm->populate(
|
$form
|
||||||
array(
|
->populate(array(
|
||||||
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
'downtime_id' => $this->downtime->id,
|
||||||
'downtime_id' => $this->downtime->id,
|
'downtime_is_service' => $isService,
|
||||||
'downtime_is_service' => $this->isService
|
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
||||||
)
|
))
|
||||||
);
|
->handleRequest();
|
||||||
|
$this->view->delDowntimeForm = $form;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Receive DeleteDowntimeCommandForm post from other controller
|
|
||||||
*/
|
|
||||||
public function removeAction()
|
|
||||||
{
|
|
||||||
$this->assertHttpMethod('POST');
|
|
||||||
$this->createDelDowntimeForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a command form to delete a single comment
|
|
||||||
*
|
|
||||||
* @return DeleteDowntimeCommandForm
|
|
||||||
*/
|
|
||||||
private function createDelDowntimeForm()
|
|
||||||
{
|
|
||||||
$this->assertPermission('monitoring/command/downtime/delete');
|
|
||||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
|
||||||
$delDowntimeForm->setAction(
|
|
||||||
Url::fromPath('monitoring/downtime/show')
|
|
||||||
->setParam('downtime_id', $this->downtime->id)
|
|
||||||
);
|
|
||||||
$delDowntimeForm->handleRequest();
|
|
||||||
return $delDowntimeForm;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user