Do not use an extra loop for generating the unhandled objects filter in ServicesController.php

This commit is contained in:
Eric Lippmann 2014-12-29 12:11:49 +01:00
parent 4441c1d4de
commit 2db2865433

View File

@ -74,6 +74,7 @@ class Monitoring_ServicesController extends Controller
'service_obsessing'*/ 'service_obsessing'*/
)); ));
$unhandledObjects = array(); $unhandledObjects = array();
$unhandledFilterExpressions = array();
$acknowledgedObjects = array(); $acknowledgedObjects = array();
$objectsInDowntime = array(); $objectsInDowntime = array();
$serviceStates = array( $serviceStates = array(
@ -94,6 +95,10 @@ class Monitoring_ServicesController extends Controller
/** @var Service $service */ /** @var Service $service */
if ((bool) $service->problem === true && (bool) $service->handled === false) { if ((bool) $service->problem === true && (bool) $service->handled === false) {
$unhandledObjects[] = $service; $unhandledObjects[] = $service;
$unhandledFilterExpressions[] = Filter::matchAll(
Filter::where('host', $service->getHost()->getName()),
Filter::where('service', $service->getName())
);
} }
if ((bool) $service->acknowledged === true) { if ((bool) $service->acknowledged === true) {
$acknowledgedObjects[] = $service; $acknowledgedObjects[] = $service;
@ -125,18 +130,11 @@ class Monitoring_ServicesController extends Controller
$this->view->serviceStates = $serviceStates; $this->view->serviceStates = $serviceStates;
$this->view->objects = $this->serviceList; $this->view->objects = $this->serviceList;
$this->view->unhandledObjects = $unhandledObjects; $this->view->unhandledObjects = $unhandledObjects;
$unhandledFilterExpressions = array(); $unhandledFilterQueryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
foreach ($unhandledObjects as $service) { $this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem')
$unhandledFilterExpressions[] = Filter::matchAll( ->setQueryString($unhandledFilterQueryString);
Filter::expression('host', '=', $service->getHost()->getName()), $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')
Filter::expression('service', '=', $service->getName()) ->setQueryString($unhandledFilterQueryString);
);
}
$queryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem');
$this->view->acknowledgeUnhandledLink->setQueryString($queryString);
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime');
$this->view->downtimeUnhandledLink->setQueryString($queryString);
$this->view->acknowledgedObjects = $acknowledgedObjects; $this->view->acknowledgedObjects = $acknowledgedObjects;
$this->view->objectsInDowntime = $objectsInDowntime; $this->view->objectsInDowntime = $objectsInDowntime;
$this->view->inDowntimeLink = Url::fromRequest() $this->view->inDowntimeLink = Url::fromRequest()