Do not use array_map for generating the unhandled objects filter in HostsController.php

This commit is contained in:
Eric Lippmann 2014-12-29 12:17:17 +01:00
parent 2db2865433
commit f1f808b7a3

View File

@ -72,6 +72,7 @@ class Monitoring_HostsController extends Controller
'host_obsessing'*/ 'host_obsessing'*/
)); ));
$unhandledObjects = array(); $unhandledObjects = array();
$unhandledFilterExpressions = array();
$acknowledgedObjects = array(); $acknowledgedObjects = array();
$objectsInDowntime = array(); $objectsInDowntime = array();
$hostStates = array( $hostStates = array(
@ -81,9 +82,10 @@ class Monitoring_HostsController extends Controller
Host::getStateText(Host::STATE_PENDING) => 0, Host::getStateText(Host::STATE_PENDING) => 0,
); );
foreach ($this->hostList as $host) { foreach ($this->hostList as $host) {
/** @var Service $host */ /** @var Host $host */
if ((bool) $host->problem === true && (bool) $host->handled === false) { if ((bool) $host->problem === true && (bool) $host->handled === false) {
$unhandledObjects[] = $host; $unhandledObjects[] = $host;
$unhandledFilterExpressions[] = Filter::where('host', $host->getName());
} }
if ((bool) $host->acknowledged === true) { if ((bool) $host->acknowledged === true) {
$acknowledgedObjects[] = $host; $acknowledgedObjects[] = $host;
@ -108,12 +110,11 @@ class Monitoring_HostsController extends Controller
$this->view->hostStates = $hostStates; $this->view->hostStates = $hostStates;
$this->view->objects = $this->hostList; $this->view->objects = $this->hostList;
$this->view->unhandledObjects = $unhandledObjects; $this->view->unhandledObjects = $unhandledObjects;
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem')->setQueryString( $unhandledFilterQueryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
Filter::where('host', array_map(function ($h) { return $h->host; }, $unhandledObjects))->toQueryString() $this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem')
); ->setQueryString($unhandledFilterQueryString);
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime')->setQueryString( $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime')
Filter::where('host', array_map(function ($h) { return $h->host; }, $unhandledObjects))->toQueryString() ->setQueryString($unhandledFilterQueryString);
);
$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()