monitoring: Implement Filterable in MonitoredObject

This commit is contained in:
Eric Lippmann 2015-01-27 14:54:21 +01:00
parent e086905384
commit 7bf6bd39e9
1 changed files with 40 additions and 2 deletions

View File

@ -7,13 +7,15 @@ namespace Icinga\Module\Monitoring\Object;
use InvalidArgumentException; use InvalidArgumentException;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Exception\InvalidPropertyException; use Icinga\Exception\InvalidPropertyException;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filterable;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\UrlParams; use Icinga\Web\UrlParams;
/** /**
* A monitored Icinga object, i.e. host or service * A monitored Icinga object, i.e. host or service
*/ */
abstract class MonitoredObject abstract class MonitoredObject implements Filterable
{ {
/** /**
* Type host * Type host
@ -116,6 +118,13 @@ abstract class MonitoredObject
*/ */
protected $stats; protected $stats;
/**
* Filter
*
* @type Filter
*/
protected $filter;
/** /**
* Create a monitored object, i.e. host or service * Create a monitored object, i.e. host or service
* *
@ -133,6 +142,35 @@ abstract class MonitoredObject
*/ */
abstract protected function getDataView(); 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 * Fetch the object's properties
* *
@ -140,7 +178,7 @@ abstract class MonitoredObject
*/ */
public function fetch() public function fetch()
{ {
$this->properties = $this->getDataView()->getQuery()->fetchRow(); $this->properties = $this->getDataView()->applyFilter($this->getFilter())->getQuery()->fetchRow();
if ($this->properties === false) { if ($this->properties === false) {
return false; return false;
} }