From 7bf6bd39e9d2a21e25dfd04efc095ebe6f95eeb3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 27 Jan 2015 14:54:21 +0100 Subject: [PATCH] monitoring: Implement Filterable in MonitoredObject --- .../Monitoring/Object/MonitoredObject.php | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 8d3246aab..213cf47b8 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -7,13 +7,15 @@ namespace Icinga\Module\Monitoring\Object; use InvalidArgumentException; use Icinga\Application\Config; use Icinga\Exception\InvalidPropertyException; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filterable; use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Web\UrlParams; /** * A monitored Icinga object, i.e. host or service */ -abstract class MonitoredObject +abstract class MonitoredObject implements Filterable { /** * Type host @@ -116,6 +118,13 @@ abstract class MonitoredObject */ protected $stats; + /** + * Filter + * + * @type Filter + */ + protected $filter; + /** * Create a monitored object, i.e. host or service * @@ -133,6 +142,35 @@ abstract class MonitoredObject */ abstract protected function getDataView(); + public function applyFilter(Filter $filter) + { + $this->getFilter()->addFilter($filter); + return $this; + } + + public function setFilter(Filter $filter) + { + // Left out on purpose. Interface is deprecated. + } + + public function getFilter() + { + if ($this->filter === null) { + $this->filter = Filter::matchAny(); + } + return $this->filter; + } + + public function addFilter(Filter $filter) + { + // Left out on purpose. Interface is deprecated. + } + + public function where($condition, $value = null) + { + // Left out on purpose. Interface is deprecated. + } + /** * Fetch the object's properties * @@ -140,7 +178,7 @@ abstract class MonitoredObject */ public function fetch() { - $this->properties = $this->getDataView()->getQuery()->fetchRow(); + $this->properties = $this->getDataView()->applyFilter($this->getFilter())->getQuery()->fetchRow(); if ($this->properties === false) { return false; }