Generate filter in host and service lists

refs #8565
This commit is contained in:
Matthias Jentsch 2015-04-07 16:29:10 +02:00
parent 6c0f9cf6f5
commit 1c5a091584
5 changed files with 88 additions and 44 deletions

View File

@ -125,17 +125,6 @@ class Monitoring_HostsController extends Controller
'host_active_checks_enabled',
'host_obsessing'*/
));
$unhandledObjects = $this->hostList->getUnhandledObjects();
$unhandledFilterExpressions = array();
foreach ($unhandledObjects as $object) {
$unhandledFilterExpressions[] = Filter::where('host', $object->getName());
}
$objectsInDowntime = $this->hostList->getObjectsInDowntime();
$downtimeFilterExpressions = array();
foreach ($objectsInDowntime as $object) {
$downtimeFilterExpressions[] = Filter::where('downtime_host', $object->getName());
}
$acknowledgedObjects = $this->hostList->getAcknowledgedObjects();
if (! empty($acknowledgedObjects)) {
@ -161,16 +150,20 @@ class Monitoring_HostsController extends Controller
$this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/hosts/delete-comment');
$this->view->stats = $hostStates;
$this->view->objects = $this->hostList;
$this->view->unhandledObjects = $unhandledObjects;
$unhandledFilterQueryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
$this->view->unhandledObjects = $this->hostList->getUnhandledObjects();
$this->view->problemObjects = $this->hostList->getProblemObjects();
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem')
->setQueryString($unhandledFilterQueryString);
->setQueryString($this->hostList->getUnhandledObjects()->filterFromResult());
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime')
->setQueryString($unhandledFilterQueryString);
$this->view->acknowledgedObjects = $acknowledgedObjects;
$this->view->objectsInDowntime = $objectsInDowntime;
->setQueryString($this->hostList->getUnhandledObjects()->filterFromResult());
$this->view->downtimeLink = Url::fromPath('monitoring/hosts/schedule-downtime')
->setQueryString($this->hostList->getProblemObjects()->filterFromResult());
$this->view->acknowledgedObjects = $this->hostList->getAcknowledgedObjects();
$this->view->objectsInDowntime = $this->hostList->getObjectsInDowntime();
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString(Filter::matchAny($downtimeFilterExpressions)->toQueryString());
->setQueryString($this->hostList->getObjectsInDowntime()->filterFromResult());
$this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
}

View File

@ -17,6 +17,7 @@ use Icinga\Module\Monitoring\Object\Service;
use Icinga\Module\Monitoring\Object\ServiceList;
use Icinga\Util\String;
use Icinga\Web\Url;
use Icinga\Web\UrlParams;
use Icinga\Web\Widget\Chart\InlinePie;
class Monitoring_ServicesController extends Controller
@ -144,23 +145,6 @@ class Monitoring_ServicesController extends Controller
'service_active_checks_enabled',
'service_obsessing'*/
));
$unhandledObjects = $this->serviceList->getUnhandledObjects();
$unhandledFilterExpressions = array();
foreach ($unhandledObjects as $service) {
$unhandledFilterExpressions[] = Filter::matchAll(
Filter::where('host', $service->getHost()->getName()),
Filter::where('service', $service->getName())
);
}
$objectsInDowntime = $this->serviceList->getObjectsInDowntime();
$downtimeFilterExpressions = array();
foreach ($objectsInDowntime as $service) {
$downtimeFilterExpressions[] = Filter::matchAll(
Filter::where('downtime_host', $service->getHost()->getName()),
Filter::where('downtime_service', $service->getName())
);
}
$acknowledgedObjects = $this->serviceList->getAcknowledgedObjects();
if (! empty($acknowledgedObjects)) {
@ -204,16 +188,18 @@ class Monitoring_ServicesController extends Controller
$this->view->stats = $serviceStates;
$this->view->hostStats = $hostStates;
$this->view->objects = $this->serviceList;
$this->view->unhandledObjects = $unhandledObjects;
$unhandledFilterQueryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
$this->view->unhandledObjects = $this->serviceList->getUnhandledObjects();
$this->view->problemObjects = $this->serviceList->getProblemObjects();
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem')
->setQueryString($unhandledFilterQueryString);
->setQueryString($this->serviceList->getUnhandledObjects()->filterFromResult()->toQueryString());
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')
->setQueryString($unhandledFilterQueryString);
->setQueryString($this->serviceList->getUnhandledObjects()->filterFromResult()->toQueryString());
$this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')
->setQueryString($this->serviceList->getProblemObjects()->filterFromResult()->toQueryString());
$this->view->acknowledgedObjects = $acknowledgedObjects;
$this->view->objectsInDowntime = $objectsInDowntime;
$this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime();
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString(Filter::matchAny($downtimeFilterExpressions)->toQueryString());
->setQueryString($this->serviceList->getObjectsInDowntime()->filterFromResult()->toQueryString());
$this->view->commentsLink = Url::fromRequest()
->setPath('monitoring/list/comments');
}

View File

@ -70,4 +70,18 @@ class HostList extends ObjectList
'_'
);
}
/**
* Returns a Filter that matches all hosts in this list
*
* @return array An
*/
public function filterFromResult()
{
$filterExpression = array();
foreach ($this as $host) {
$filterExpression[] = Filter::where('host', $host->getName());
}
return FilterOr::matchAny($filterExpression);
}
}

View File

@ -94,7 +94,7 @@ abstract class ObjectList implements Countable, IteratorAggregate
$acknowledgedObjects[] = $object;
}
}
return $acknowledgedObjects;
return $this->newFromArray($acknowledgedObjects);
}
public function getObjectsInDowntime()
@ -105,7 +105,7 @@ abstract class ObjectList implements Countable, IteratorAggregate
$objectsInDowntime[] = $object;
}
}
return $objectsInDowntime;
return $this->newFromArray($objectsInDowntime);
}
public function getUnhandledObjects()
@ -116,6 +116,37 @@ abstract class ObjectList implements Countable, IteratorAggregate
$unhandledObjects[] = $object;
}
}
return $unhandledObjects;
return $this->newFromArray($unhandledObjects);
}
/**
* @return ObjectList
*/
public function getProblemObjects()
{
$handledObjects = array();
foreach ($this as $object) {
if ((bool) $object->problem === true) {
$handledObjects[] = $object;
}
}
return $this->newFromArray($handledObjects);
}
/**
* Create a ObjectList from an array of hosts without querying a backend
*
* @return ObjectList
*/
protected function newFromArray(array $objects)
{
$class = get_called_class();
$list = new $class($this->backend);
$list->objects = $objects;
$list->count = count($objects);
$list->filter = $list->filterFromResult();
return $list;
}
abstract function filterFromResult();
}

View File

@ -3,6 +3,8 @@
namespace Icinga\Module\Monitoring\Object;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterOr;
use Icinga\Util\String;
/**
@ -113,4 +115,22 @@ class ServiceList extends ObjectList
'_'
);
}
/**
* Returns a Filter that matches all hosts in this HostList
*
* @return Filter
*/
public function filterFromResult()
{
$filterExpression = array();
foreach ($this as $service) {
$filterExpression[] = Filter::matchAll(
Filter::where('host', $service->getHost()->getName()),
Filter::where('service', $service->getName())
);
}
return FilterOr::matchAny($filterExpression);
}
}