monitoring: Don't loop downtimes in the DowntimesController

This commit is contained in:
Eric Lippmann 2015-08-27 23:14:48 +02:00
parent d68edc5149
commit 0f2a4ceac3

View File

@ -6,24 +6,22 @@ namespace Icinga\Module\Monitoring\Controllers;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Web\Url; use Icinga\Web\Url;
/** /**
* Display detailed information about a downtime * Display detailed information about downtimes
*/ */
class DowntimesController extends Controller class DowntimesController extends Controller
{ {
/** /**
* The fetched downtimes * The downtimes view
* *
* @var array * @var \Icinga\Module\Monitoring\DataView\Downtime
*/ */
protected $downtimes; protected $downtimes;
/** /**
* A filter matching all current downtimes * Filter from request
* *
* @var Filter * @var Filter
*/ */
@ -31,8 +29,6 @@ class DowntimesController extends Controller
/** /**
* Fetch all downtimes matching the current filter and add tabs * Fetch all downtimes matching the current filter and add tabs
*
* @throws Zend_Controller_Action_Exception
*/ */
public function init() public function init()
{ {
@ -64,38 +60,17 @@ class DowntimesController extends Controller
))->addFilter($this->filter); ))->addFilter($this->filter);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->downtimes = $query->getQuery()->fetchAll(); $this->downtimes = $query;
if (false === $this->downtimes) {
throw new Zend_Controller_Action_Exception(
$this->translate('Downtime not found')
);
}
$this->getTabs()->add( $this->getTabs()->add(
'downtimes', 'downtimes',
array( array(
'title' => $this->translate(
'Display detailed information about multiple downtimes.'
),
'icon' => 'plug', 'icon' => 'plug',
'label' => $this->translate('Downtimes') . sprintf(' (%d)', count($this->downtimes)), 'label' => $this->translate('Downtimes') . sprintf(' (%d)', $query->count()),
'title' => $this->translate('Display detailed information about multiple downtimes.'),
'url' =>'monitoring/downtimes/show' 'url' =>'monitoring/downtimes/show'
) )
)->activate('downtimes'); )->activate('downtimes');
foreach ($this->downtimes as $downtime) {
if (isset($downtime->service_description)) {
$downtime->isService = true;
} else {
$downtime->isService = false;
}
if ($downtime->isService) {
$downtime->stateText = Service::getStateText($downtime->service_state);
} else {
$downtime->stateText = Host::getStateText($downtime->host_state);
}
}
} }
/** /**
@ -106,8 +81,7 @@ class DowntimesController extends Controller
$this->view->downtimes = $this->downtimes; $this->view->downtimes = $this->downtimes;
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes') $this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString($this->filter->toQueryString()); ->setQueryString($this->filter->toQueryString());
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/delete-all') $this->view->removeAllLink = Url::fromPath('monitoring/downtimes/delete-all')->setParams($this->params);
->setParams($this->params);
} }
/** /**
@ -123,10 +97,10 @@ class DowntimesController extends Controller
$delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes')); $delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
$delDowntimeForm->addDescription(sprintf( $delDowntimeForm->addDescription(sprintf(
$this->translate('Confirm removal of %d downtimes.'), $this->translate('Confirm removal of %d downtimes.'),
count($this->downtimes) $this->downtimes->count()
)); ));
$delDowntimeForm->setRedirectUrl(Url::fromPath('monitoring/list/downtimes')); $delDowntimeForm->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'));
$delDowntimeForm->setDowntimes($this->downtimes)->handleRequest(); $delDowntimeForm->setDowntimes($this->downtimes->fetchAll())->handleRequest();
$this->view->delDowntimeForm = $delDowntimeForm; $this->view->delDowntimeForm = $delDowntimeForm;
} }
} }